4

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?

3
  • First, you should use #{bean.ID} instead of #{bean.getID}. Second, you should not have business logic in your getters methods, see here (if you still insist to place business logic in the getter, don't complain for performance problems later =\). To the question, I guess you can dynamically bind the <p:outputPanel id="#{bean.id}" binding="#{theOutputPanel}" rendered="#{theOutputPanel.id eq bean.currentPanel}">. I haven't tested this but may do what you want/need (but you should change bean.currentPanel to String). Commented Sep 24, 2013 at 17:42
  • Related: stackoverflow.com/q/8168302/1065197 Commented Sep 24, 2013 at 17:44
  • 1
    @LuiggiMendoza There are at least 3 typos in the text besides the getter! Commented Sep 24, 2013 at 17:46

1 Answer 1

9

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}" 
Sign up to request clarification or add additional context in comments.

5 Comments

Could you post any documentation to this #{component}as well?
@Luiggi: it's listed in "getValue" table entry of chapter 5.6.2.1 of JSF 2 spec (page 5-25) and -of course- in the known Communication in JSF 2 article.
@LuiggiMendoza It is listed in section 5.6.2.1 of the JSF 2.0 specification "Implicit Object ELResolver for Facelets and Programmatic Access".
@BalusC I most probably knew of that object from your famous post. But finding it in the Specification was also worth doing. Took some time, though, as I'm on my mobile. Sorry for the overlapping comment!
I found a trouble, when I call rendered={component.id eq bean.currentPanel} the component.id it is as if you have not assigned, because always I print the values and some cases are equals , so how to assigned the value after?.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.