JSTL c:forEach causes CDI (Seam 3) @ViewScoped bean to invoke @PostConstruct on every AJAX request using Mojarra 2.1.18+

StackOverflow https://stackoverflow.com/questions/21913105

Question

This is a followup question to some questions on stackoverflow.com:

JSTL c:forEach causes @ViewScoped bean to invoke @PostConstruct on every request

Why does @PostConstruct callback fire every time even though bean is @ViewScoped? JSF

However, we're using Mojarra 2.1.22 but our Seam 3 CDI @ViewScoped annotated beans always become reconstructed, that is the method annotated with @PostConstruct is executed and we get an new bean on every AJAX request.

All I keep hearing for a few months (it's February 2014 now) is that Mojarra 2.1.18+ has many of these bugs fixed and that the view-scoped bean should survive AJAX requests when the view is using this bean from a <c:forEach items="#{mySeam3CdiViewScopedBean.items}" ... >.

Here are a few bugs:

https://java.net/jira/browse/JAVASERVERFACES-1665

https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-928 (<- see the last comment by dwightd - I cannot confirm it!)

https://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-787

https://java.net/jira/browse/JAVASERVERFACES-2688

The only difference to the examples I mentioned at the top is that we're using Seam 3.1 Faces CDI @ViewScoped (+ @Named) and not "native" JSF @ViewScoped (+ @ManagedBean).

Question:

Is Seam 3 Faces (3.1 Final) the reason why it isn't working?

(How can we find out? It's not easy to translate what we have to a test case... maybe someone knows?)


PS: I know this is more of a forum question, but I have hopes that the people here dealing with JSF 2 but not necessarily Seam 3 (Faces) could give their feedback.

Was it helpful?

Solution

A few remarks about your questions :

  • Using JSTL loop in JSF is not recommended since it's not managed in JSF lifecycle. Using facelets ui:repeat is the good practice
  • Seam 3 is deprecated, you should avoid using it as you won't have any support if the problem comes from here.

You have two solutions (by order of preference) :

But in both case, try to get rid of JSTL in your JSF pages, it is a source of a lot of strange issues.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top