本文介绍了复合组件是否真的需要namingcontainer接口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个可以与其他对象迭代的复合组件.问题在于复合组件是一个命名容器,无法进行简单的selectOnMenu更改和刷新其他selectOnMenu,因为给selectOnMenu赋予的"id"为combo1:combo并且看不到combo2:combo.

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.

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

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

另一种尝试,但不起作用. p:commandbutton在CC内看不到div的ID.获取JSF2组合的父级的clientId组件

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)

推荐答案

是的.否则,您最终将获得重复组件ID".在同一个父命名容器中使用多个复合组件时,复合组件实现会产生错误.

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.

如果您绝对希望不要使用基于NamingContainer的组件,则可以创建一个标记文件.它只需要一些.taglib.xml样板.

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.

您的复合实现无效.为了正确地用ajax引用组合,您需要一个纯HTML <div>或一个完全是ID为#{cc.clientId}<span>.

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

例如

<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"或使重复/重复最小化的东西)

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

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

这篇关于复合组件是否真的需要namingcontainer接口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 06:48