我正在尝试使用<f:ajax render=":component"/>
动态加载视图。
那部分没有问题。但是,在该视图中使用commandLinks不会。
动态加载目标视图的容器:
<h:form>
<h:commandLink>
<f:param name="tmp2" value="tmp/newxhtml.xhtml"/>
<f:ajax render=":newXhtml"/>
</h:commandLink>
</h:form>
<h:panelGroup layout="block" id="newXhtml">
<ui:include src="#{param['tmp2']}"/>
</h:panelGroup>
单击commandLink时,将设置tmp2值,并通过ajax重新呈现'newXhtml'。
此链接位于随附的.xhtml中,但无效:
<h:form>
<h:commandLink>
<f:ajax listener="#{backingBean.sampleMethod}"/>
</h:commandLink>
</h:form>
BackingBean.java:
public class BackingBean{
public void sampleMethod() {
//breakpoint here is never hit
}
}
答案 0 :(得分:2)
当我没有使用<f:ajax>
来包含页面而是使用带有action属性的普通<h:commandLink>
并将include页面保存到@SessionScope
bean时,我开始工作了
包括xhtml:
<h:form>
<f:ajax render=":newXhtml">
<h:commandLink action="#{includeBean.setIncludePage('tmp/newXhtml.xhtml')}">
</h:commandLink>
</f:ajax>
</h:form>
<h:panelGroup layout="block" id="newXhtml">
<ui:include src="#{includeBean.includePage}"/>
</h:panelGroup>
包含的.xhtml可以保持不变。
包含页面的支持bean:
@Named
@SessionScope
public class IncludeBean implements Serializable {
private static final long serialVersionUID = 1L;
private String includePage;
@PostConstruct
public void init() {
includePage = "tmp/newxhtml.xhtml";
}
public String getIncludePage() {
return includePage;
}
public void setIncludePage(String includePage) {
this.includePage = includePage;
}
}