Why won't my Facelets loop variable go out of scope?

橙三吉。 提交于 2019-12-13 02:04:21

问题


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!


回答1:


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)



来源:https://stackoverflow.com/questions/1134604/why-wont-my-facelets-loop-variable-go-out-of-scope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!