Jsf 在cc:implementation外部声明标记,并让cc:implementation包含它

Jsf 在cc:implementation外部声明标记,并让cc:implementation包含它,jsf,jsf-2,facelets,markup,composite-component,Jsf,Jsf 2,Facelets,Markup,Composite Component,嗯。 我为CRUD创建了一个自定义组件,表单页面是一个参数。 在本例中,我需要两个页面,一个用于定义组件,另一个用于表单 有办法吗 详情如下: 实施: 组件 <cc:interface> <cc:attribute name="formPage" type="java.lang.String" required="true"/> ..... </cc:interface> <cc:implementation> ... &

嗯。 我为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>
<cc:implementation>
...
    <h:form id="form-crud">
        <XX:SOMETING name="#{cc.attrs.formContent}" />      
    </h:form>
...
</cc:implementation>

.....
...
...
第1页:crud.xhtml

<ui:define name="content-template" >
    <comp:crud 
        paginaForm="crud-form.xhtml" />
</ui:define>
<html ...
    <p:panelGrid id="grid-crud" columns="2" >
        <h:outputLabel for="dsName" value="Name: " />
        <p:inputText id="dsName"  value="#{crudBean.dsName}"/>
    </p:panelGrid>  
</html>
...
<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>
...

第2页:crud表单.xhtml

<ui:define name="content-template" >
    <comp:crud 
        paginaForm="crud-form.xhtml" />
</ui:define>
<html ...
    <p:panelGrid id="grid-crud" columns="2" >
        <h:outputLabel for="dsName" value="Name: " />
        <p:inputText id="dsName"  value="#{crudBean.dsName}"/>
    </p:panelGrid>  
</html>
...
<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>
...
您可以使用与使用类似的工具,例如
/
页眉/页脚

首先用所需的名称声明一个:

<cc:interface>
    <cc:facet name="form" />
</cc:interface>

然后,在所需的位置声明a,并在该位置结束:

<cc:implementation>
    ...
    <h:form>
        <cc:renderFacet name="form" />
    </h:form>
    ...
</cc:implementation>

...
...
现在您可以按如下方式使用它:


...

请注意,“普通”Facelets标记文件也可以通过
/
机制实现此构造。

这是我第二次修复您问题中的术语错误。这些不是自定义组件。这些是复合组件。要了解差异,请参阅ok@BalusC,收到提示!我会注意的!