Jsf 总是从 ArrayList 中删除最后一个元素
我在支持 bean 中有一个 ArrayList
,并使用 c:forEach
在 JSF 页面中进行渲染。当我通过索引删除ArrayList
元素时,jsf无论索引是什么,总是删除最后一个元素。为什么会出现这样的情况呢?
JSF 中的删除按钮是:
<a4j:commandButton immediate="true" action="#{bean.removeEntry}" ...
所以我使用立即属性。我认为问题是因为立即跳过 JSF 生命周期中的应用请求阶段。有可能吗?
如果是,那么在这种情况下如何运行应用请求阶段?
I have an ArrayList
in a backing bean and his rendering in JSF page with c:forEach
. When iI remove the ArrayList
element by index, jsf, no matter what index is, always removes the last element. Why happening this?
Remove button in JSF is :
<a4j:commandButton immediate="true" action="#{bean.removeEntry}" ...
So i use immediate attribute. I think problem is because immediate skips Apply request phase in JSF Life Cycle. Is possible?
If yes, than how run Apply request phase in this case ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否使用 Facelets(.xhtml 页面)?如果是这样,您可能会遇到一些关于 JSTL 标记的常见误解,例如
。这是一篇关于它的好文章:https://rogerkeays.com/jsf-c -foreach-vs-ui-repeat
基本上,
仅在最初构建视图时进行处理;它不会成为组件树的一部分,并且在更改后备集合时可能会出现一些您意想不到的行为。您最好使用
代替。Are you using Facelets (.xhtml pages)? If so, you may be running into some common misconceptions about JSTL tags like
<c:foreach>
. Here's a good article on it:https://rogerkeays.com/jsf-c-foreach-vs-ui-repeat
Basically,
<c:foreach>
is processed only when the view is initially built; it does not become part of the component tree, and can have some behavior you don't expect when the backing collection is changed. You may be better off using<ui:repeat>
instead.多一点代码会有帮助,但立即命令按钮基本上用于导航离开当前页面,因为动作侦听器或操作将在应用请求阶段执行,典型情况是取消按钮。这意味着您不会在那里获得更新的值。
如果您的逻辑依赖于其他一些 uiinput,请立即执行此操作,并且您可以在 valuechangelistener 中挂钩。
但我怀疑你想要实现的目标能否以更好的方式完成,看看这个 链接@SO
little more code would have helped, but immediate on command button is basically used for navigating away from current page as actionlistener or action will execute in apply request phase, typical case cancel button. This means you will not get updated value there.
If your logic depends on some other uiinput make that immediate and you can hook things in valuechangelistener.
But I doubt what you are trying to achieve can be done in better way, have a look at this link @ SO
我也有类似的问题。我使用 'tr:iterator' 来迭代 ArrayList'<'Customer'>'(); “ui:repeat”解决了我的问题。
谢谢。
I was having the similar issue. I was using 'tr:iterator' to iterate over ArrayList'<'Customer'>'(); 'ui:repeat' solved my problem.
Thanks.