我正在使用 JSF 和 PrimeFaces,但我需要获取组件的 id 值。因为我正在构建具有不同 id 的 dinamycally 面板,为了显示我需要比较的面板,如果是当前面板,然后显示它。
例如,如果我有下一个面板
<p:outputPanel id="#{bean.getID}" autoUpdate="true"
renderer=#{@this.id == bean.currentPanel}
>
</p:outputPanel>
和 bean
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 值呢?
最佳答案
有一个隐含的 #{component}
EL 作用域中计算当前 UI 组件的对象。鉴于此信息,您将获得以下属性:
rendered="#{component.id eq bean.currentPanel}"
关于jsf - 如何在 EL 中获取当前组件的 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18988331/