1

我做了一个复合组件,里面是一个<f:ajax>标签,它的“render”属性是cc的一个参数。

像这样的东西:

    ...
    <cc:attribute name="additionalAjaxRenderIds" type="java.lang.String"></cc:attribute>
    ...
    <h:commandLink value="test" action="#{myBean.someAction}" id="testLink" >
        <f:ajax execute="@this" render="#{cc.attrs.additionalAjaxRenderIds} "/>
    </h:commandLink>
    ...

我在一个表单中使用这个 cc,那已经在一个外部命名容器中:

    <h:form id="myForm">
        ...
        <mycomp:myComponent id="myCC" additionalAjaxRenderIds=":#{component.namingContainer.parent.clientId}:myPanel" />
        <h:panelGroup id="myPanel">
            ...
        </h:panelGroup>
        ...
    </h:form>

问题是,如果我写

additionalAjaxRenderIds=":#{component.namingContainer.clientId}:myPanel"

我收到此错误:

<f:ajax> contains an unknown id ':j_idt44:myForm:myCC:myPanel' - cannot locate it in the context of the component testLink

而如果我使用这个(+ .parent):

additionalAjaxRenderIds=":#{component.namingContainer.parent.clientId}:myPanel"

错误是:

<f:ajax> contains an unknown id ':j_idt44:myPanel' - cannot locate it in the context of the component testLink

而不是预期的ID:

':j_idt44:myForm:myPanel'

所以看起来我的cc命名容器的父级不是表单,而是外部命名容器

有什么办法:1,获得正确的父(表单)2,在我将EL作为参数传递之前评估EL(所以我可以将计算出的clientId传递给我的cc而不是EL表达式,所以组件不会引用到 commandLink 标签,但到 h:form 我把我的抄送)

我知道我可以使用

additionalAjaxRenderIds=":#{component.namingContainer.parent.clientId}:myForm:myPanel" 

但我不喜欢那个解决方案

此外,将表单的 prependId 属性设置为 false 会破坏整个组件的查找(结果也会导致 ajax 标记)

4

1 回答 1

0

EL 表达式不会在构建组件时评估,而是在访问属性时评估。换句话说,它们是runtime而不是buildtime。是#{component}指评估 EL 表达式时的当前UI 组件,在您的特定情况下是<h:commandLink>. 这解释了不同的结果。

您需要以不同的方式处理此问题,而不使用#{component}.

例如

<h:form id="myForm" binding="#{myForm}">
    ...
    <mycomp:myComponent id="myCC" additionalAjaxRenderIds=":#{myForm.clientId}:myPanel" />
    <h:panelGroup id="myPanel">
        ...
    </h:panelGroup>
    ...
</h:form>

或者

<h:form id="myForm">
    ...
    <mycomp:myComponent id="myCC" additionalAjaxRenderIds=":#{myPanel.clientId}" />
    <h:panelGroup id="myPanel" binding="#{myPanel}">
        ...
    </h:panelGroup>
    ...
</h:form>
于 2012-12-30T19:01:54.760 回答