3

我对 JSF 和 Primefaces 有点陌生,我想制作一个包含 Primefaces GridPanel 的复合组件:

<composite:interface>
    <composite:attribute name="bind" type="com.whatever.IBackingBean"/>
    <composite:facet name="headerCols"/>
    <composite:facet name="bodyCols"/>
</composite:interface>
<composite:implementation>
<h:form>
    <p:panelGrid>
        <p:row>
            <composite:renderFacet name="headerCols"/>
            <p:column>
                <h:outputText value="Col1" />
            </p:column>
            <p:column>
                <h:outputText value="Col2" />
            </p:column>
            <p:column>
                <h:outputText value="Col3" />
            </p:column>
        </p:row>

        <p:row>
            <composite:renderFacet name="bodyCols"/>
            <p:column>
                <h:outputText value="#{cc.attrs.bind.prop1}" />
            </p:column>
            <p:column>
                <h:outputText value="#{cc.attrs.bind.prop2}" />
            </p:column>
            <p:column>
                <h:outputText value="#{cc.attrs.bind.prop3}" />
            </p:column>
        </p:row>
    </p:panelGrid>
</h:form>
</composite:implementation>

并希望有类似的用法:

<x:mycomposite bind="#{myBackingBean}">
    <f:facet name="headerCols">
        <p:column>
             <h:outputText value="My Extra Prop"/>
        </p:column>
    </f:facet>
    <f:facet name="bodyCols">
        <p:column>
             <h:outputText value="#{myBackingBean.extraProp}"/>
        </p:column>
    </f:facet>
</x:mycomposite>

但是当我这样做时......方面不会被添加。我认为这可能与无法<composite:renderFacet>用作参数有关,<p:panelGrid>该参数也(可能)是复合的。

因为我需要添加列而不是行,所以我需要在多个位置添加所以<composite:insertChildren>不起作用。

我大概可以只使用一个属性,但是如何将元素值作为属性值传递呢?因为这样的东西似乎不可用:

<x:mycomposite bind="#{myBackingBean}">
    <f:attribute name="headerCols">
        <p:column>
             <h:outputText value="My Extra Prop"/>
        </p:column>
    </f:attribute>
    <f:attribute name="bodyCols">
        <p:column>
             <h:outputText value="#{myBackingBean.extraProp}"/>
        </p:column>
    </f:attribute>
</x:mycomposite>

这假设我将复合材料修改为:

<composite:interface>
    <composite:attribute name="bind" type="com.whatever.IBackingBean"/>
    <composite:attribute name="headerCols"/>
    <composite:attribute name="bodyCols"/>
</composite:interface>
<composite:implementation>
<h:form>
    <p:panelGrid>
        <p:row>
            #{cc.attrs.headerCols}
            <p:column>
                <h:outputText value="Col1" />
            </p:column>
            <p:column>
                <h:outputText value="Col2" />
            </p:column>
            <p:column>
                <h:outputText value="Col3" />
            </p:column>
        </p:row>

        <p:row>
            #{cc.attrs.bodyCols}
            <p:column>
                <h:outputText value="#{cc.attrs.bind.prop1}" />
            </p:column>
            <p:column>
                <h:outputText value="#{cc.attrs.bind.prop2}" />
            </p:column>
            <p:column>
                <h:outputText value="#{cc.attrs.bind.prop3}" />
            </p:column>
        </p:row>
    </p:panelGrid>
</h:form>
</composite:implementation>

任何人都可以就如何使使用模式起作用提供任何替代方案或建议吗?

谢谢!

4

1 回答 1

0

I'll post my workaround, which isn't technically a solution - so I don't think it's fair to quite mark it as such.

The reason why this isn't really a solution, is because it doesn't actually use the Primefaces <p:panelGrid> (whose layout options I'm slowly beginning to detest on whole - but that's another topic) and instead just uses an HTML5 <table>. It achieves the overall goal that I wanted, but will require me to ensure I add all the correct Primefaces styles to the table widget manually so the look and feel remain consistent.

If anyone has an alternate solution, I'd love to see it.

<composite:interface>
    <composite:attribute name="bind" type="com.whatever.IBackingBean"/>
    <composite:facet name="headerCols"/>
    <composite:facet name="bodyCols"/>
</composite:interface>
<composite:implementation>
<h:form>
<table>
    <tr>
        <composite:renderFacet name="headerCols"/>
        <th>
            <h:outputText value="Col1" />
        </th>
        <th>
            <h:outputText value="Col2" />
        </th>
        <th>
            <h:outputText value="Col3" />
        </th>
    </tr>

    <tr>
        <composite:renderFacet name="bodyCols"/>
        <td>
            <h:outputText value="#{cc.attrs.bind.prop1}" />
        </td>
        <td>
            <h:outputText value="#{cc.attrs.bind.prop2}" />
        </td>
        <td>
            <h:outputText value="#{cc.attrs.bind.prop3}" />
        </td>
    </tr>
</table>
</h:form>
</composite:implementation>
于 2014-10-03T21:44:49.470 回答