I am having an issue where my @ViewScoped managed bean is behaving like a @RequestScoped managedBean simply because I am using the composite:insertChildren tag. I have read the other posts on the subject and am aware of the limitations of @ViewScoped managedBeans, but I do not have any explicit bindings nor am I using JSTL in my composite component.
I'm assuming that the insertChildren tag is being bound to the managedBean, but I'm hoping that somebody out there can put me out of my misery and show me a workaround - I really don't want to start using @SessionScoped beans. :)
Here's my simplified example. The Simple Managed Bean:
@ManagedBean(name = "simpleMB")
@ViewScoped
public class SimpleManagedBean implements Serializable {
private static final long serialVersionUID = -1;
@NotNull
@Email
private String email;
public SimpleManagedBean() {
System.out.println("SimpleManagedBean");
}
@PostConstruct
public void postConstruct() {
System.out.println("Post construct");
}
public String submit() {
return null;
}
... setter and getter
}
Using the SimpleManagedBean above with the form and composite component (without insertChildren) below, everything works as expected. I enter some text, press Submit and the error is displayed along with the text entered. At this point, I am happy.
<h:form>
<foo:simpleNoChildren />
<h:commandButton id="submit"
value="Submit"
action="#{simpleMB.submit}" />
</h:form>
... and the composite component ....
<composite:interface />
<composite:implementation>
<h:panelGrid columns="3">
<h:outputText value="Email" />
<h:inputText id="email"
value="#{simpleMB.email}"
required="true" />
<h:message for="email" />
</h:panelGrid>
</composite:implementation>
Now, if I move the panelGrid and it's components out of the composite component and replace with an composite:insertChildren tag, as shown below, when I enter some text and press submit, the proper error message is shown, but since the @PostConstruct method is called again, the text I entered no longer displayed. :(
<h:form>
<foo:simple>
<h:panelGrid columns="3">
<h:outputText value="Email" />
<h:inputText id="email" value="#{simpleMB.email}" required="true" />
<h:message for="email" />
</h:panelGrid>
</foo:simple>
<h:commandButton id="submit" value="Submit" action="#{simpleMB.submit}" />
</h:form>
... and my complicated composite component :) ...
<composite:interface />
<composite:implementation>
<composite:insertChildren />
</composite:implementation>
Any thoughts or suggestions?
Thanks in advance.