复合组件是否真的需要命名容器接口?

时间:2012-12-28 15:30:58

标签: jsf-2 composite-component

我想创建一个可以与其他人迭代的复合组件。问题是复合组件是一个命名容器和一个简单的selectOnMenu更改并刷新其他selectOnMenu是不可能的,因为给予selectOnMenu的“id”是combo1:combo并且看不到combo2:combo

最好的情况是form1:combo1form1:combo2,然后,combo1和combo2使用h:form的uinamingcontainer。 这个链接谈论这个但没有解决方案。 https://cwiki.apache.org/MYFACES/create-a-non-namingcontainer-composite-component.html

另一种尝试但不起作用。 p:commandbutton无法在CC中看到div的id。 Obtaining the clientId of the parent of a JSF2 composite component

<p:commandButton value="asd" partialSubmit="true" process="@this" update="fooId"/>  
    <cf:label id="fooId" title="xxxxx" />[index.xhtml]




<composite:interface componentType="RootComponent" preferred="false">
    <composite:attribute name="title" />
</composite:interface>

<composite:implementation>
<div id="#{cc.immediateParent.clientId}:#{cc.id}">
#{currentDate}
<h:panelGroup id="#{cc.clientId}" layout="block">
    <p:outputLabel id="#{cc.clientId}_lb" value="#{cc.attrs.title}">
        <composite:insertChildren />
    </p:outputLabel>
</h:panelGroup>
</div>
</composite:implementation>[label.xhtml](compositecomponent)

1 个答案:

答案 0 :(得分:4)

  

复合组件是否真的需要命名容器接口?

是。否则,当在同一父命名容器中使用多个组件时,最终会出现“复制组件ID”错误。

如果您非常肯定您不想要基于NamingContainer的组件,那么请改为创建标记文件。它只需要一些.taglib.xml样板。

另见:


  

另一种尝试,但不起作用。 p:commandbutton无法在CC

中看到div的ID

您的复合实施无效。要通过ajax正确引用合成,您需要一个纯HTML <div><span>,其ID恰好为#{cc.clientId}

E.g。

<composite:implementation>
    <div id="#{cc.clientId}">
        #{currentDate}
        <h:panelGroup layout="block">
            <p:outputLabel id="#{cc.clientId}_lb" value="#{cc.attrs.title}">
                <composite:insertChildren />
            </p:outputLabel>
        </h:panelGroup>
    </div>
</composite:implementation>

(顺便说一下<h:panelGroup>多余的印象,你可以安全地省略它;进一步id="#{cc.clientId}_lb"可以更好地id="label"或者什么来减少重复/复制)

另见:

相关问题