如何获取EL中当前组件的ID [英] How to get id of current component in EL
问题描述
我正在使用JSF和PrimeFaces,但是我需要获取组件ID的值.因为我要用不同的ID来动态地构建面板,所以要显示一个面板,我需要比较当前面板是否为当前面板,然后再显示它.
I'm working with JSF and PrimeFaces, but I need to get the value of the id of a component. Because I'm building dinamycally panels with diferent id, to show a the panel I need to compare if is the current panel, then show it.
例如,如果我有下一个面板
For example if I've the next panel
<p:outputPanel id="#{bean.getID}" autoUpdate="true"
renderer=#{@this.id == bean.currentPanel}
>
</p:outputPanel>
还有
public class Bean(){
private int numberPanels =0;
private int currentPanel = 0;
public int getID(){
//...a process that return different ID
}
// getter's and setters
}
很显然,@this.id
不起作用.那么,如何通过PrimeFaces获取JSF组件ID的值呢?
Obviously, @this.id
doesn't work. So, how to get the value of ID of componente ne JSF with PrimeFaces?
推荐答案
EL范围中有一个隐式的#{component}
对象,其结果为当前UI组件.有了这些信息,您将获得以下属性:
There is an implicit #{component}
object in the EL scope that evaluates to the current UI component. Given this information, you'll get the following attribute:
rendered="#{component.id eq bean.currentPanel}"
这篇关于如何获取EL中当前组件的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!