为什么我的Facelets循环变量不会超出范围? [英] Why won't my Facelets loop variable go out of scope?

查看:78
本文介绍了为什么我的Facelets循环变量不会超出范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这看起来像很多文字,但是我认为这是一个我很想念的简单概念。

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

我正在使用Facelets编写Web应用程序。我有一个自定义标签rq:request-list,该标签以一个请求列表作为参数,并输出一个漂亮的表格来显示它们。到目前为止,一切都很好。

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就像您期望的那样开始:

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>

在将支持bean中的请求设置为表示的请求后,将我们带到编辑页面我们所在的表格行。这就是问题所在。

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在一页中使用了多次;

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>

现在出现表 确定;也就是说,所有文字都是正确的。但是,commandLinks指向错误的请求...它们指向页面上 last rq:request-list的相应行的Request。与请求有关的数据将按原样在表中输出,但是在单击commandLink时,{req}指向错误的请求。

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重申一下,如果我在页面上有几个rq:request-list,则每个 rq:request-list的第一行的Edit链接指向最后一个rq中的第一个请求(行):页面上的请求列表。 每个 rq:request-list的第二行的Edit链接指向页面上最后一个rq:request-list的第二个请求(行)。等等。

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.

如何让{req}指向原来的内容,而不仅仅是成为过时列表中的索引?

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

谢谢!

推荐答案

看看此博客条目,您可能使用了一次重复,当组件树出现时是构建版本,而不是在渲染时进行评估的foreach。 (但这只是黑暗中的一枪,我没有尝试您的示例)

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)

这篇关于为什么我的Facelets循环变量不会超出范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆