嗯。 我创建了一个 CRUD 自定义组件,表单页面是一个参数。 在本例中,我需要两页,一个用于定义组件,另一个用于表单。
有什么办法可以做到这一点吗?
如下:
实现:
组件
<cc:interface>
<cc:attribute name="formPage" type="java.lang.String" required="true"/>
.....
</cc:interface>
<cc:implementation>
...
<h:form id="form-crud">
<ui:include src="#{cc.attrs.formPage}" />
</h:form>
...
</cc:implementation>
第 1 页:crud.xhtml
<ui:define name="content-template" >
<comp:crud
paginaForm="crud-form.xhtml" />
</ui:define>
第 2 页:crud-form.xhtml
<html ...
<p:panelGrid id="grid-crud" columns="2" >
<h:outputLabel for="dsName" value="Name: " />
<p:inputText id="dsName" value="#{crudBean.dsName}"/>
</p:panelGrid>
</html>
新实现(示例)
为了简化,我希望在同一页面中具有组件定义和表单,类似的东西。是否可以? 我知道我可以使用模板,但自定义组件具有更多属性。
新组件
<cc:implementation>
...
<h:form id="form-crud">
<XX:SOMETING name="#{cc.attrs.formContent}" />
</h:form>
...
</cc:implementation>
新页面 1:new-crud.xhtml
...
<ui:define name="content-template" >
<comp:crud
form="new-form" />
<XX:SOMETING id="new-form">
<p:panelGrid id="grid-crud" columns="2" >
<h:outputLabel for="dsName" value="Name: " />
<p:inputText id="dsName" value="#{crudBean.dsName}"/>
</p:panelGrid>
</XX:SOMETING>
</ui:define>
...
最佳答案
您可以使用 <f:facet>
与那些使用例如的完全一样<h:dataTable>
/<h:column>
页眉页脚。
首先声明一个 <cc:facet>
与所需的名称:
<cc:interface>
<cc:facet name="form" />
</cc:interface>
然后声明 <cc:renderFacet>
在它应该结束的所需位置:
<cc:implementation>
...
<h:form>
<cc:renderFacet name="form" />
</h:form>
...
</cc:implementation>
现在您可以按如下方式使用它:
<comp:crud>
<f:facet name="form">
...
</f:facet>
</comp:crud>
请注意,此构造也可以通过 <ui:define>
使用“plain vanilla”Facelets 标记文件。/<ui:insert>
机制。
关于jsf - 在 cc 外部声明标记 :implementation and let the cc:implementation include it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25648036/