我对通过<composite:insertChildren/>
进行嵌套合成有疑问。当我进入页面时,它呈现如下子窗体:
<form id="parentComposite:childComposite:childForm" ...>
当我点击执行内容更新的“打开”按钮时,除了“ onPageLoad”以外,呈现子表单,这会导致子按钮损坏:
<form id="parentComposite:panelComposite:childComposite:childForm" ...>
这一次,HTML正确呈现,这意味着第一种情况下的ViewState
必须以某种方式破坏。
页面
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:cc="http://java.sun.com/jsf/composite/components">
<h:head/>
<h:body>
<h:form id="pageForm">
<p:commandButton
id="dialogOpener"
value="Open"
<!-- UPDATE RENDERS DIALOG OTHER THAN "onPageLoad" -->
update="parentComposite:dialog"
oncomplete="PF('dialog').show();"/>
</h:form>
<cc:parentComposite
id="parentComposite"
dialogId="dialog"
widgetVar="dialog"
handler="#{testBean}">
<cc:childComposite
id="childComposite"
handler="#{testBean}"/>
</cc:parentComposite>
</h:body>
</html>
省略 panelComposite 将解决此问题,但是为什么在包含panelComposite的情况下呈现方式不一致?
父母复合
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:cc="http://java.sun.com/jsf/composite/components">
<composite:interface>
<composite:attribute name="dialogId" required="true"/>
<composite:attribute name="widgetVar" required="true"/>
<composite:attribute name="handler" type="main.ParentHandler"/>
</composite:interface>
<composite:implementation>
<p:dialog
id="#{cc.attrs.dialogId}"
widgetVar="#{cc.attrs.widgetVar}"
header="parentDialog"
appendTo="@(body)">
<h:form id="parentForm">
<p:commandButton
id="parent"
value="Parent"
action="#{cc.attrs.handler.onParentAction()}"/>
</h:form>
<!-- ISERT CHILDREN HERE -->
<cc:panelComposite id="panelComposite">
<composite:insertChildren/>
</cc:panelComposite>
</p:dialog>
</composite:implementation>
</ui:composition>
面板组合
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:composite="http://xmlns.jcp.org/jsf/composite">
<composite:interface>
</composite:interface>
<composite:implementation>
<div class="panel-container">
<composite:insertChildren/>
</div>
</composite:implementation>
</ui:composition>
孩子组合
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
<composite:attribute name="handler" type="main.ChildHandler"/>
</composite:interface>
<composite:implementation>
<h:form id="childForm">
<p:commandButton
id="child"
value="Child"
action="#{cc.attrs.handler.onChildAction()}"/>
</h:form>
</composite:implementation>
</ui:composition>