property object is not changing value

67 views Asked by At

I have following Page.tml code:

<span class="dropdown">
    <t:pagelink page="tracker" data-toggle="dropdown" class="dropdown-toggle disabled" style="padding-top: 5px; padding-bottom: 5px;">
        <span>
            <b class="caret"></b>
            <t:if test="!project"> All Tickets</t:if>
            <t:if test="project"> Project</t:if>
        </span>
    </t:pagelink>
    <ul class="dropdown-menu">
        <li>                    
            <t:pagelink page="tracker" data-toggle="dropdown" class="dropdown-toggle disabled">
            <span>All Tickets</span>
            </t:pagelink>
        </li>
        <t:loop source="projectList" value="project">
            <li><t:pagelink page="tracker" context="${project.id}">${project.title}</t:pagelink></li>
        </t:loop>
    </ul>
</span>
<t:if test="project">
    <span class="path-divider"> > </span>
    <strong>
        <t:pagelink page="tracker" context="project.id">
            <span>${project.title}</span>
        </t:pagelink>
    </strong>
</t:if>

And for my page java class:

@Property
@Inject
private ProjectDao projectDao;
@Property
private Project project;
@Property
private List<Project> projectList;

@Property
@Inject
private TicketDao ticketDao;
@Property
private List<Ticket> ticketList;

@PageLoaded
void onPageLoad() {
    projectList = projectDao.loadAll();
    ticketList = ticketDao.loadAll();
}

void onActivate(Integer contextValue) {
    if (contextValue != null) {  
        project = projectDao.getByID(contextValue);
    }
    if (project != null) {
        List ticketListByProjectID = ticketDao.getTicketsByProjectID(project.getId());
        if (!ticketListByProjectID.isEmpty()) {
            ticketList = ticketListByProjectID;
        }           
    } else {
        ticketList = ticketDao.loadAll();
    }
}

I have a problem to change object project to some other, when I select from a contextValue. It's always the same object in TML (it is value of last element in the loop), but in java code it is changing when I print to console. What I'm doing wrong ?

1

There are 1 answers

0
Bob Harner On BEST ANSWER

You're using your project property for 2 different an conflicting purposes -- a loop variable and the selected item. Try using different variables for those 2 purposes.