如何在EL中获取当前组件的id

Cri*_* A. 3 jsf el primefaces jsf-2

我正在使用JSF和PrimeFaces,但我需要获取组件id的值.因为我正在构建具有不同id的dinamycally面板,以显示我需要比较的面板,如果是当前面板,则显示它.

例如,如果我有下一个面板

<p:outputPanel id="#{bean.getID}" autoUpdate="true"
   renderer=#{@this.id == bean.currentPanel}
>
</p:outputPanel>
Run Code Online (Sandbox Code Playgroud)

和豆

public class Bean(){
  private int numberPanels =0;
  private int currentPanel = 0;

  public int getID(){
     //...a process that return different ID
  }
  // getter's and setters
Run Code Online (Sandbox Code Playgroud)

}

显然,@this.id不起作用.那么,如何使用PrimeFaces获取componente ne JSF的ID值?

sku*_*sel 8

#{component}EL范围中有一个隐式对象,它评估当前的UI组件.根据此信息,您将获得以下属性:

rendered="#{component.id eq bean.currentPanel}"
Run Code Online (Sandbox Code Playgroud)

  • @Luiggi:它列在JSF 2规范(第5-25页)第5.6.2.1章的"getValue"表条目中,并且在已知的[JSF 2中的通信](http://balusc.blogspot.com)中列出/2011/09/communication-in-jsf-20.html#ImplicitELObjects)文章. (3认同)