Should a composite component really require namingcontainer interface?

夙愿已清 提交于 2019-12-12 10:06:19

问题


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.

The best situation would be form1:combo1 and form1:combo2, then, combo1 and combo2 uses uinamingcontainer of h:form. This link talks about this but no solution. 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. 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:


Should a composite component really require namingcontainer interface?

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.

If you're absolutely positive that you don't want a NamingContainer based component, then rather create a tag file instead. It only requires some .taglib.xml boilerplate.

See also:

  • When to use <ui:include>, tag files, composite components and/or custom components?

Another try but don't works. p:commandbutton can't see id of div inside of CC

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

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>

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

See also:

  • JSF Updating Composite Component (Primefaces)
  • Is it possible to update non-JSF components (plain HTML) with JSF ajax?


来源:https://stackoverflow.com/questions/14071825/should-a-composite-component-really-require-namingcontainer-interface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!