使用EL表达式将组件ID传递给JSF中的复合组件

Kev*_*vin 2 ajax jsf el composite-component jsf-2

问题:我将EL表达式传递给复合组件,但EL表达式是从复合组件内部而不是之前进行评估的.将EL表达式求值为字符串的意图发送到复合组件.

我有一个复合组件,MenuTable:

<cc:interface>
    <cc:attribute name="model" type="nz.co.tradeintel.web.MenuTable"/>
    <cc.attribute name="updateId" /> 
</cc:interface>

<cc:implementation>
    <h:panelGroup id="menuTable">
    <table>
        <ui:repeat id="repeat1" value="#{cc.attrs.model.rows}" var="row">
            <tr>
            <ui:repeat id="repeat2" value="#{row.contents}" var="entry">
                <td>
                    <p:commandLink action="#{cc.attrs.model.setSelected(entry)}" update="#{cc.attrs.updateId}" value="#{entry.toString()}"/>
                </td>
            </ui:repeat>
            </tr>
        </ui:repeat>
    </table>
    </h:panelGroup>
</cc:implementation>
Run Code Online (Sandbox Code Playgroud)

目的是我传递一个绝对组件ID作为这样的属性updateId:

<p:PanelGroup id="updatingPanel">
    <!-- Lots of components.-->
</p:PanelGroup>
<custom:MenuTable updateId="#{component.clientId}:updatingPanel" model="#{menuBackBean.menuTable}" />  
Run Code Online (Sandbox Code Playgroud)

问题是,updateId<p:commandLink />复合组件内的范围评估的EL表达式,我得到以下错误:

javax.faces.FacesException: Cannot find component with identifier ":j_idt37:j_idt39:updatingPanel:j_idt61:repeat1:0:repeat2:0:j_idt65:updatingPanel" referenced from "j_idt37:j_idt39:updatingPanel:j_idt61:repeat1:0:repeat2:0:j_idt65".
Run Code Online (Sandbox Code Playgroud)

注:JSF认为我试图更新组件与和ID的updatingPanel内部的复合材料部件.

为什么不从外部范围评估EL表达式:<custom:MenuTable/>

有一些相关的答案,但我不理解它们,比如这个.

使用Mojarra 2.1.15

Bal*_*usC 6

在构建组件时,不会评估EL表达式,但是在访问该属性时.换句话说,它们是运行时而不是构建时.该#{component}当前 UI组件此刻的EL表达式进行求值,这是在特定的情况下<p:commandLink>.这解释了不同的结果.

您需要以不同方式处理此问题,而不使用#{component}.其中一种方法是

<p:panelGroup binding="#{updatingPanel}">
    ...
</p:panelGroup>
<custom:MenuTable ... updateId=":#{updatingPanel.clientId}" />
Run Code Online (Sandbox Code Playgroud)

如果仍然无效,请确保不使用<h:form prependId="false">.

也可以看看: