Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Reference to a component inside a composite component in JSF 2  RSS feed

 
Wellington Zomer
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I'm having the following problem.

I'm creating a component in JSF 2, it contains a <h:panelGroup id="panelFinder"> in your implementation.
Also created a button on the component, enable the ajax and rendering for the same <f:ajax render="panelFinder">.

The problem is that the id of the component panelFinder is set by default. Creating something like the final name of "idForm:idComponent:panelFinder".

Can I make a concatenation of these elements and then it could make it work, I can get the id of the component by #{cc.id}, but do not know how to have the id of the form as it is dynamic, because my component does not have a form, it is inserted into other pages that already contains the form created, and each with a different id.
I know I could use the property <h:form> to my pages to disable the inclusion of the form id of the components, but this would impact elsewhere.

Then have the following questions:

Is there any way more easy for to reference the element "panelFinder"?
If not, how know the id of the form where my component was placed?

Sorry for my english. Thank you.
 
Tim Holloway
Bartender
Posts: 18705
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Wellington!

JSF involves 2 types of id's. Simple IDs, and fully-qualified ID's. JSF tags can normally cross-reference themselves using only the simple IDs, but JavaScript cannot - it requires the fully-qualified IDs.

One reason for the difference is that by XML standard, each and every ID in a document must be unique. However, JSF allows plug-in components with internal IDs, multiplicative IDs (same ID for item in each row in a table, for example), and included files with IDs. So it constructs the fully-qualified IDs, which are unique at the HTML level, while still being able to work with simple (relative) IDs on a local basis.

This ID construction process is based on the concept of naming containers. The JSF form, dataTable (and each row in a datatable) and panelGrid objects, for example, are all naming containers, and it's good practice to always give them explicit IDs, since otherwise IDs will be generated and they'll change according to rather arbitrary rules. So giving the containers static IDs will keep the JavaScript happy. And make it a lot easier to figure out what went wrong when you get a JSF error message.

As I said, JSF can usually get by using a simple ID, but since IDs are only required to be unique within a container, I'm not really sure about cross-container references. I do make cross-container references myself, but I'm using RichFaces, which has a couple of utility functions for that purpose. For plain JSF, I'd have to read the manual.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!