IntelliJ Java IDE
The moose likes JSF and the fly likes Reference to a component inside a composite component in JSF 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Reference to a component inside a composite component in JSF 2" Watch "Reference to a component inside a composite component in JSF 2" New topic
Author

Reference to a component inside a composite component in JSF 2

Wellington Zomer
Greenhorn

Joined: Jan 26, 2012
Posts: 1
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
Saloon Keeper

Joined: Jun 25, 2001
Posts: 12513

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.


One of the most odious afflictions that Business has inflicted on the modern English language is "pro-active". Most of the time it's simply redundantly used in place of the simple old word "active". And a good deal of the rest of the time it means "You're not overworked enough yet, so go out and find more!"
 
 
subject: Reference to a component inside a composite component in JSF 2
 
Threads others viewed
Maven Tomcat plugin precompile JSPs problem
fetch each component on a JSF page and check if id attribute is there.
Runtime parameter?
JSF, Facelets & Recursion
Duplicate Id error is thrown?
developer file tools