I had a problem when my managed @ViewScoped bean behaves like @RequestScoped managedBean simply because I use the compound tag: insertChildren. I read other posts on this subject and know the limitations of @ViewScoped managedBeans, but I don't have explicit bindings and I don't use JSTL in my composite component.
I assume the insertChildren tag is tied to managedBean, but I hope someone out there can get me out of my misery and show me a workaround - I really don't want to start using @SessionScoped beans. :)
Here is my simplified example. 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, click "Submit" and an error is displayed along with the entered text. 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 translate the Grid panel and its components from a composite component and replace it with a composite tag: insertChildren, as shown below, when I type some text and click submit, the corresponding error message is displayed, 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.