简体   繁体   English

Jsf 总是从 ArrayList 中删除最后一个元素

[英]Jsf always remove last element from ArrayList

I have an ArrayList in a backing bean and his rendering in JSF page with c:forEach .我在支持 bean 中有一个ArrayList ,他在 JSF 页面中使用c:forEach渲染。 When iI remove the ArrayList element by index, jsf, no matter what index is, always removes the last element.当我通过索引移除ArrayList元素时,jsf无论索引是什么,总是移除最后一个元素。 Why happening this?为什么会发生这种情况?

Remove button in JSF is : JSF 中的删除按钮是:

<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.我认为问题是因为立即跳过了 JSF 生命周期中的应用请求阶段。 Is possible?有可能吗?

If yes, than how run Apply request phase in this case ?如果是,那么在这种情况下如何运行 Apply 请求阶段?

Are you using Facelets (.xhtml pages)?您是否在使用 Facelets(.xhtml 页面)? If so, you may be running into some common misconceptions about JSTL tags like <c:foreach> .如果是这样,您可能会对诸如<c:foreach>类的 JSTL 标记产生一些常见的误解。 Here's a good article on it:这是一篇关于它的好文章:

https://rogerkeays.com/jsf-c-foreach-vs-ui-repeat https://rogerkeays.com/jsf-c-foreach-vs-ui-repeat

Basically, <c:foreach> is processed only when the view is initially built;基本上, <c:foreach>仅在最初构建视图时处理; 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.您最好使用<ui:repeat>代替。

I was having the similar issue.我遇到了类似的问题。 I was using 'tr:iterator' to iterate over ArrayList'<'Customer'>'();我正在使用 'tr:iterator' 迭代 ArrayList'<'Customer'>'(); 'ui:repeat' solved my problem. 'ui:repeat' 解决了我的问题。 Thanks.谢谢。

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.如果您的逻辑依赖于其他一些 uiinput,请立即执行,您可以在 valuechangelistener 中挂钩。

But I doubt what you are trying to achieve can be done in better way, have a look at this link @ SO但我怀疑您想要实现的目标是否可以以更好的方式完成,请查看此链接@SO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM