【问题标题】:How to create a composite of existing components in JSF?如何在 JSF 中创建现有组件的组合?
【发布时间】:2011-07-10 07:41:24
【问题描述】:

我想知道是否可以编写自己的组件(或称其为 Widget、Object)。

我的意思是,不要(例如)在其中使用h:panelGrouph:outputLabel,而是自己创建h:panelMarkzzz,作为panelGroup 和outputLabel 的组合。

在 JSF 上可以吗?

【问题讨论】:

    标签: jsf components facelets


    【解决方案1】:

    是的,可以像这样创建现有组件的组合。

    启动示例:

    /resources/foo/group.xhtml

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:cc="http://xmlns.jcp.org/jsf/composite">
        <cc:interface>
            <cc:attribute name="label" type="java.lang.String" required="true" />
        </cc:interface>
        <cc:implementation>
             <h:panelGroup>
                 <h:outputLabel value="#{cc.attrs.label}" />
                 <cc:insertChildren />
             </h:panelGroup>
        </cc:implementation>
    </html>
    

    /test.xhtml

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" 
        xmlns:h="http://xmlns.jcp.org/jsf/html" 
        xmlns:foo="http://xmlns.jcp.org/jsf/composite/foo">
        <h:head>
            <title>Test</title>
        </h:head>
        <h:body>
            <foo:group label="Label value">
                <h:outputText value="This will appear after label inside the panelgroup" />
            </foo:group>
        </h:body>
    </html>
    

    /foo 文件夹名称随您的喜好而定,您可以在 XML 命名空间中将其引用为 http://xmlns.jcp.org/jsf/composite/XXX。 XHTML 文件名是标签名。

    也就是说,复合组件具有性能影响,只有在使用简单的包含或标记文件无法实现功能要求时才应使用它们。在您的特定情况下,您最好使用标记文件。只有当您真正需要 &lt;cc:interface componentType="..."&gt; 时,复合组件才有价值。

    另见:

    【讨论】:

      【解决方案2】:

      也许你的意思是Composite Components

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-08-25
        • 1970-01-01
        • 2023-04-03
        • 1970-01-01
        • 1970-01-01
        • 2012-05-29
        • 2011-07-19
        • 1970-01-01
        相关资源
        最近更新 更多