简体   繁体   English

复合组件是否真的需要namingcontainer接口?

[英]Should a composite component really require namingcontainer interface?

I want to create a composite componet that can iterate with others. 我想创建一个可以与其他对象迭代的复合组件。 The problem is that composite componet is a namingcontainer and a simple selectOnMenu change and refresh other selectOnMenu do not is possible because "id" given to selectOnMenu is combo1:combo and can't see combo2:combo . 问题在于复合组件是一个命名容器,无法进行简单的selectOnMenu更改和刷新其他selectOnMenu,因为为selectOnMenu提供的“ id”是combo1:combo ,看不到combo2:combo

The best situation would be form1:combo1 and form1:combo2 , then, combo1 and combo2 uses uinamingcontainer of h:form . 最好的情况是form1:combo1form1:combo2 ,然后,combo1和combo2使用h:form uinamingcontainer。 This link talks about this but no solution. 此链接讨论此问题,但没有解决方案。 https://cwiki.apache.org/MYFACES/create-a-non-namingcontainer-composite-component.html https://cwiki.apache.org/MYFACES/create-a-non-namingcontainer-composite-component.html

Another try but don't works. 再次尝试,但不起作用。 p:commandbutton can't see id of div inside of CC. p:commandbutton在CC中看不到div的ID。 Obtaining the clientId of the parent of a JSF2 composite component 获取JSF2复合组件的父组件的clientId

<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)

Should a composite component really require namingcontainer interface? 复合组件是否真的需要namingcontainer接口?

Yes. 是。 Otherwise you would end up with "Duplicate component ID" errors coming from the composite component implementation when using multiple of them in the same parent naming container. 否则,当您在同一个父命名容器中使用多个复合组件实现时,您将最终遇到“复合组件ID”错误。

If you're absolutely positive that you don't want a NamingContainer based component, then rather create a tag file instead. 如果您绝对不希望使用基于NamingContainer的组件,则可以创建一个标记文件。 It only requires some .taglib.xml boilerplate. 它只需要一些.taglib.xml样板文件。

See also: 也可以看看:


Another try but don't works. 再次尝试,但不起作用。 p:commandbutton can't see id of div inside of CC p:commandbutton在CC中看不到div的ID

Your composite implementation is invalid. 您的复合实现无效。 In order to reference a composite properly by ajax, you need a plain HTML <div> or a <span> with exactly the ID of #{cc.clientId} . 为了正确地通过ajax引用组合,您需要一个纯ID为#{cc.clientId}的纯HTML <div><span>

Eg 例如

<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>

(I have by the way the impression that the <h:panelGroup> is superfluous, you can safely omit it; further the id="#{cc.clientId}_lb" can better be id="label" or something to minimize repetition/duplication) (顺便说一句,我觉得<h:panelGroup>是多余的,可以放心地忽略它;进一步, id="#{cc.clientId}_lb"最好是id="label"或可以最大程度减少重复的内容/复制)

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM