根据https://code.google.com/p/primefaces/issues/detail?id=4720 https://code.google.com/p/primefaces/issues/detail?id=4720, The ComponentUtils.resolveWidgetVar(String expression, UIComponent component)
该函数自 2013 年起在 Primefaces 中可用。它可以在 EL 中使用"#{p:widgetVarFromContext(searchExpression, component)}"
功能。
当多个组件在不同的环境中具有相同的 id 时,这非常有用NamingContainer
,但仍然存在于同一视图中。在这种情况下,
这#{p:widgetVar(searchExpression)}
函数仅返回最后找到的一个。
但我不明白如何引用UIComponent
必须作为 EL 的第二个参数传递。上面提到的错误报告建议我们可以参考它#{component}
。谁能给我举个例子吗?
The #{component}
是一个隐式 EL 变量,引用current UIComponent http://docs.oracle.com/javaee/7/api/javax/faces/component/UIComponent.html#getCurrentComponent(javax.faces.context.FacesContext)在 EL 范围内(另见隐式 EL 对象 http://balusc.blogspot.nl/2011/09/communication-in-jsf-20.html#ImplicitELObjects)。您通常只能在组件的 HTML 属性或模板文本子项中引用它。
例如。的情况下<h:inputText>
它将引用一个实例UIInput https://docs.oracle.com/javaee/7/api/javax/faces/component/UIInput.html其中有一个类isValid()
method.
<h:inputText id="foo" required="true"
style="background: #{component.valid ? '' : 'pink'}"
onclick="alert('Client ID of this component is #{component.clientId}');" />
您还可以使用binding
属性让 JSF 在视图构建期间放置对 Facelet 作用域中的组件实例的引用。这样,在视图渲染期间,组件引用将在 Facelet 中的任何位置可用。
<script>alert('Client ID of foo component is #{foo.clientId}');</script>
<h:inputText binding="#{foo}" />
也可以看看:
- component.clientId 和 p:component() 生成的客户端 id 之间的区别 https://stackoverflow.com/questions/20539713/difference-between-client-id-generated-by-component-clientid-and-pcomponent/
- 没有 bean 属性的 JSF 组件绑定 https://stackoverflow.com/questions/8168302/jsf-component-binding-without-bean-property
- JSF 中的“绑定”属性如何工作?何时以及如何使用它? https://stackoverflow.com/questions/14911158/how-does-the-binding-attribute-work-in-jsf-when-and-how-should-it-be-used
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)