0

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 ?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Daggeto
  • 943
  • 1
  • 8
  • 17

3 Answers3

1

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.

Roger Keays
  • 3,117
  • 1
  • 31
  • 23
Jeremiah Orr
  • 2,620
  • 1
  • 18
  • 24
0

I was having the similar issue. I was using 'tr:iterator' to iterate over ArrayList'<'Customer'>'(); 'ui:repeat' solved my problem. Thanks.

satu
  • 19
  • 2
0

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

Community
  • 1
  • 1
baba.kabira
  • 3,111
  • 2
  • 26
  • 37