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.
A few remarks about your questions :
ui:repeat
is the good practiceYou have two solutions (by order of preference) :
@ViewScoped
. You can easily do this by using JBoss Wildlfy 8 or Oracle Glassfish 4 servers.@ViewScoped
But in both case, try to get rid of JSTL in your JSF pages, it is a source of a lot of strange issues.