views:

202

answers:

1

Hi! I know this looks like a lot of text, but I think it's a pretty simple concept I'm missing.

I'm writing a web application with Facelets. I've got a custom tag rq:request-list that takes a list of requests as a parameter and outputs a lovely table to display them. So far, so good.

rq:request-list starts out like you'd expect:

<!-- ... -->
<ice:dataTable value="#{list}" var="req">
    <ice:column>
        <f:facet name="header">Date last edited</f:facet>
        <ice:outputText value="#{req.dateModified}" />
    </ice:column>
<!-- ... -->

And that turns out just fine. It even has a link in the table to edit the request. Yippee!

<ice:column rendered="#{spokespersonView}">
    <f:facet name="header">Edit</f:facet>
    <h:commandLink value="Edit" action="edit_r" rendered="#{RequestSessionBean.mutable}">
        <f:setPropertyActionListener target="#{RequestSessionBean.request}" value="#{req}"/>
    </h:commandLink>
</ice:column>

That takes us to the editing page, after setting the request in the backing bean to the one represented by the table row we're at. This is where the problem's at. And it's subtle.

rq:request-list is used several times in one page; as such:

<ui:repeat value="#{ExperimentListBean.usersExperiments}" var="exp">
    <rq:request-list list="#{RequestListBean.requestsByExperiment[exp]}" showExperiment="false" spokespersonView="true" />
</ui:repeat>

Now the tables appear OK; that is, all the text is right. However, the commandLinks point to the wrong Requests ... they point to the Request of the corresponding row of the last rq:request-list on the page. The data pertaining to the Requests is outputted as it should be in the table, but {req} points to the wrong request when it comes to clicking on a commandLink.

To reiterate, if I have a few rq:request-lists on a page, the Edit link for the first row of every rq:request-list points to the first request (row) in the last rq:request-list on the page. The Edit link for the second row of every rq:request-list points to the second request (row) of the last rq:request-list on the page. Etc.

How can I get {req} to point to what I it was, and not just be an index in a list that is outdated?

Thanks!

A: 

Take a look at this blog entry, you probably use repeat which is executed once, when the component tree is build, instead of foreach which get evaluated at rendering time. (But this is just a shot in the dark, I don't tried your example)

Tim Büthe
It worked! Thank you!I'm still new to Java web programming; I thought that c:forEach was executed just once and ui:repeat was executed every time. But then again, this page doesn't post back to itself, so I don't see why it would matter either way. Anyway, it works, so thanks!
Nick