How to get id of current component in EL

空扰寡人 提交于 2020-01-02 08:16:10

问题


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>

And 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

}

Obviously, @this.id doesn't work. So, how to get the value of ID of componente ne JSF with PrimeFaces?


回答1:


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}"


来源:https://stackoverflow.com/questions/18988331/how-to-get-id-of-current-component-in-el

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!