简体   繁体   中英

Jsf always remove last element from ArrayList

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 ?

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.

I was having the similar issue. I was using 'tr:iterator' to iterate over ArrayList'<'Customer'>'(); 'ui:repeat' solved my problem. 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.

But I doubt what you are trying to achieve can be done in better way, have a look at this link @ SO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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