【发布时间】:2014-09-04 11:03:31
【问题描述】:
你好,
我将ui:include 放入h:panelGroup 并在需要时动态呈现它。
通常的假设和理论是,当 ui:include 未呈现时,与包含页面关联的 ManagedBean 不应被初始化。
当我在包含页面中使用ui:repeat 时,不会发生这种情况。
这是一个重复问题的示例:
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
}
正如您在page1.xhtml 中看到的那样,我使用rendered="false" 来表示封装ui:include 的h:paneGroup,但当我加载page1.xhtml 时,MBeanTwo 仍在初始化。
如果我从page2.xhtml 中删除ui:repeat,则MBeanTwo 不会被初始化。
这是 JSF 中的一个错误,如果有的话,有什么可用的解决方法吗?
使用和测试的版本:
Primefaces 3.5
JSF 2.1.13 和 2.2.0-m05
【问题讨论】:
标签: jsf jsf-2 primefaces