属性对象没有改变值

时间:2015-06-08 21:19:27

标签: java tapestry

我有以下Page.tml代码:

<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>

对于我的页面java类:

@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();
    }
}

当我从contextValue中选择时,我有一个问题是将对象project更改为其他对象。它始终是TML中的相同对象(它是循环中最后一个元素的值),但在java代码中,当我打印到控制台时它会发生变化。我做错了什么?

1 个答案:

答案 0 :(得分:1)

您正在将项目属性用于2个不同的冲突目的 - 循环变量和所选项目。尝试使用不同的变量来达到这两个目的。