Hello,
I'm putting ui:include
inside h:panelGroup
and rendering it dynamically when required.
The usual assumption and theory is, ManagedBean associated with the included page should not get initialized when ui:include
is not rendered.
This is not happening when I use ui:repeat
inside included page.
Here is a Example to repeat the Issue:
page.1.xhtml
<h:body>
<h:form>
<p:outputLabel value="#{mBeanOne.beanOnetxt}"/><br/>
</h:form>
<h:panelGroup rendered="false" layout="block">
<ui:include src="page2.xhtml"/>
</h:panelGroup>
</h:body>
MBeanOne.java
@ManagedBean
@ViewScoped
public class MBeanOne implements Serializable{
private String beanOnetxt;
public MBeanOne() {
System.out.println("MBeanOne - Constructor");
}
@PostConstruct
public void init(){
beanOnetxt = "This is Managed Bean 1";
System.out.println("MBeanOne - Postconstruct");
}
//SETTERS and GETTERS
}
page2.xhtml
<h:body>
<h:outputText value="#{mBeanTwo.beanTwotxt}"/><br/>
<ui:repeat var="var" value="#{mBeanTwo.versionList}">
<h:outputText value="#{var}"/><br/>
</ui:repeat>
</h:body>
MBeanTwo.java
@ManagedBean
@ViewScoped
public class MBeanTwo implements Serializable{
private String beanTwotxt;
private List<String> versionList;
public MBeanTwo() {
System.out.println("MBeanTwo - Constructor");
}
@PostConstruct
public void init(){
beanTwotxt = "This is Managed Bean 2";
versionList = new ArrayList<String>();
versionList.add("Playground");
versionList.add("Kestrel");
versionList.add("Merlin");
versionList.add("Tiger");
System.out.println("MBeanTwo - Postconstruct");
}
//SETTER and GETTER
}
As you can see in page1.xhtml
I have use rendered="false"
for h:paneGroup
which encapsulates ui:include
, but still MBeanTwo
is getting initialized when I load page1.xhtml
.
If I remove ui:repeat
from page2.xhtml
then MBeanTwo
is not getting initialized.
Is this a bug in JSF, if so any workaround available?
Versions used and tested:
Primefaces 3.5
JSF 2.1.13 and 2.2.0-m05