0

I'm using JSF2 and primefaces.

I'm doing a dynamic data table with primefaces (p:dataTable). In the managed bean , there is a list linked to this data table. Also, there is an action button that will add a new element to the table automatically.

However , when I press the button , even if I add the element to the list, no changes are . displayed into the data table. Debugging I found out that the List<String> field is being reinitialized again, so it will always have 1 element.

Does anyone now what I'm missing?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
Camilo
  • 199
  • 2
  • 13
  • Looks like your bean is `@RequestScoped`. Change it at least to `@ViewScoped` and try again. – Luiggi Mendoza Oct 27 '13 at 21:58
  • I put @SessionScope to the managed bean and It worked. NO idea why :D but It took me a while – Camilo Oct 27 '13 at 22:17
  • Using unnecessary `@SessionScoped` will impact your application performance. Looks like you can't use `@ViewScoped` for working with CDI and in a Java EE 6 environment. If that's your case, I would recommend adding OmniFaces to your application and use their `@ViewScoped` custom annotation that solves this gap, or migrate to JSF 2.2 and a Java EE 7 environment when this is already solved. – Luiggi Mendoza Oct 27 '13 at 22:21
  • Hi @Luiggi I changed to '@ViewScoped' as you recommended and it worked as well. I'm upgrading to jsf 2.2 as you mentioned it. Thank you – Camilo Oct 27 '13 at 22:33
  • I also forgot that `@ViewScoped` exists since JSF 2. If this is a legacy application, then keep working with JSF 1.2. If not, then start using JSF 2 instead. – Luiggi Mendoza Oct 27 '13 at 22:34
  • @LuiggiMendoza You should write it as an answer. – noone Oct 28 '13 at 05:04
  • @noone why? It is a duplicate question. – Luiggi Mendoza Oct 28 '13 at 05:11
  • @LuiggiMendoza Because the question still appears as unsolved with not a single answer. I feel like I wasted time when I click on a question like this, read the question, then check out the comments just to realize that the problem has already been solved. – noone Oct 28 '13 at 05:20
  • @noone you're free to post an answer then. – Luiggi Mendoza Oct 28 '13 at 05:21

0 Answers0