[
https://issues.apache.org/jira/browse/MYFACES-3558?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14014548#comment-14014548
]
Leonardo Uribe commented on MYFACES-3558:
-----------------------------------------
It is expected behavior. You can't rely on the fact that the same view scope
bean will be across multiple requests. Think about a cluster configuration. But
note @PostConstruct is executed just once, so you can put the initialization
code there and everything else will work. If the bean is the same or it was
recreated is not a problem. Also, hold view scope bean instances in session can
be considered a memory leak.
> ViewScoped bean re-created on every ajax request
> ------------------------------------------------
>
> Key: MYFACES-3558
> URL: https://issues.apache.org/jira/browse/MYFACES-3558
> Project: MyFaces Core
> Issue Type: Bug
> Affects Versions: 2.1.7
> Environment: Ubuntu 12.04
> Reporter: Denis Kniazhev
> Assignee: Leonardo Uribe
>
> Given a view scoped bean:
> @ManagedBean
> @ViewScoped
> public class Bean implements Serializable {
> @PostConstruct
> public void pc() {
> System.out.println("in postConstruct");
> }
> }
> and a simple form:
> <h:form>
> <h:commandLink value="update">
> <f:ajax render="label"/>
> </h:commandLink>
> <h:outputText id="label" value="#{bean}"/>
> </h:form>
> Repeatable hitting on "update" button makes the value of label change:
> com.denisk.test.Bean@5b62a166
> com.denisk.test.Bean@27afca98
> com.denisk.test.Bean@3a93ea5f
> PostConstruct is fired only once though.
> I know that there is plenty of ViewScoped-related havoc in JSF2, which is
> described in
> http://java.net/jira/browse/JAVASERVERFACES-1492
> and related JSF spec issue (which will be fixed in spec v. 2.2):
> http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-787
> But current defect seems to be MyFaces-specific since on Mojarra 2.1.8 this
> works just fine
--
This message was sent by Atlassian JIRA
(v6.2#6252)