使用的EL EX pression传递一个组件ID在JSF复合组件 [英] Use an EL expression to pass a component ID to a composite component in JSF
问题描述
问题:我正在传递的EL前pression到复合部件,但在EL前pression正在从复合部件内评估,而不是之前。其用意是使EL前pression计算为一个字符串被发送到复合部件
Problem: I am passing an EL expression to a composite component, but the EL expression is being evaluated from inside the composite component, rather than before. The intention being that the EL expression evaluates to a string with is sent to the composite component.
我有一个复合成分, 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>
的意图是,我通过一个绝对的组件ID为属性 updateId
是这样的:
<p:PanelGroup id="updatingPanel">
<!-- Lots of components.-->
</p:PanelGroup>
<custom:MenuTable updateId="#{component.clientId}:updatingPanel" model="#{menuBackBean.menuTable}" />
现在的问题是,在EL EX pression为 updateId
从&LT的范围进行评估;号码:commandLink /&GT ;
复合组件中,我也得到了以下错误:
The problem is, the EL expression for the updateId
is evaluated from the scope of the <p:commandLink />
within the composite component, and I get the following error:
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".
注:JSF认为我想更新与组件和ID updatingPanel
是的在的复合成分
为什么EL EX pression不是从外部范围评估:&LT;自定义:MenuTable /&GT;
Why is the EL expression not evaluated from the outer scope: <custom:MenuTable/>
?
有一些相关的答案,但我不理解他们,如的这个。
There are a few related answers, but I don't understand them, such as this one.
使用Mojarra 2.1.15
Using Mojarra 2.1.15
推荐答案
EL EX pressions没有评估目前的组件的内置,但此刻的属性进行访问。换句话说,他们的运行的而不是构建时的。该#{组件}
指的是<一href="http://docs.oracle.com/javaee/6/api/javax/faces/component/UIComponent.html#getCurrentComponent%28javax.faces.context.FacesContext%29"相对=nofollow> 电流的此刻的EL EX pression评估UI组件,这是在特定情况下,&LT;电话号码: commandLink&GT;
。这也解释了不同的结果。
EL expressions are not evaluated at the moment the component is built, but at the moment the attribute is accessed. In other words, they're runtime and not buildtime. The #{component}
refers to the current UI component at the moment the EL expression is evaluated, which is in your particular case the <p:commandLink>
. That explains the different outcome.
您需要处理这个不同,而无需使用#{组件}
。方法之一是
You need to approach this differently, without using #{component}
. One of the ways is
<p:panelGroup binding="#{updatingPanel}">
...
</p:panelGroup>
<custom:MenuTable ... updateId=":#{updatingPanel.clientId}" />
如果仍然无法正常工作,那么请确保您不使用&LT; H:形式prependId =假&GT;
If that still doesn't work, then make sure that you don't use <h:form prependId="false">
.
- <一个href="http://stackoverflow.com/questions/8634156/how-to-reference-components-in-jsf-ajax-cannot-find-component-with-identifier/8644762#8644762">How引用组件的JSF AJAX?无法找到标识符QUOT组成部分;富&QUOT;鉴于
- JSF NamingContainer和UIForm用prependId
- How to reference components in JSF ajax? Cannot find component with identifier "foo" in view
- JSF NamingContainer and UIForm with prependId
这篇关于使用的EL EX pression传递一个组件ID在JSF复合组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!