I'm using Mojarra 2.2.12. I have a case where a @ViewScoped
@ManagedBean
is immediately destroyed on page load, although the view is not ended. The problem is reproducible with solely the below in <h:body>
:
<h:outputText value="#{testBean.value}" />
<h:link outcome="other" includeViewParams="true">link</h:link>
The other
must refer to a different view and not the same view. There's no <f:viewParam>
necessary to reproduce the problem.
And the below bean:
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
public class TestBean implements Serializable {
@PostConstruct
public void init() {
System.out.println("@PostConstruct on " + this);
}
@PreDestroy
public void clear() {
System.out.println("@PreDestroy on " + this);
}
public String getValue() {
return "test";
}
}
If we remove includeViewParams="true"
attribute, then the bean is not immediately destroyed.Why does includeViewParams="true"
cause this behavior?