jsf - 在 cc 外部声明标记 :implementation and let the cc:implementation include it

标签 jsf jsf-2 facelets markup composite-component

嗯。 我创建了一个 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/

相关文章:

jsf - 如何从 HttpSessionListener 访问 JSF 应用程序范围的托管 bean?

mysql - JSF 输入汉字编码

javax.faces.FacesException : Expression Error: Named Object: player not found

jsf - 将操作方法​​名称作为参数传递给 facelets 组件

java - 如何实现自定义JSF组件来绘制图表?

spring - GWT 前端的最佳 java webframe 后端?

jsf - PrimeFaces 7.0 Ajax 更新警告

jsf - 如何根据存储的值生成多个文本框?

css - 如何在 CSS 中使用#resource?

jsf-2 - 从操作方法结果调用页面时未调用 JSF 2 Prerenderview 监听器