jQuery in Action, 2nd edition
The moose likes JSF and the fly likes Difference between UIComponent getId and getClientId(FacesContext) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Difference between UIComponent getId and getClientId(FacesContext)" Watch "Difference between UIComponent getId and getClientId(FacesContext)" New topic
Author

Difference between UIComponent getId and getClientId(FacesContext)

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

I'm just wondering what the difference is between the getId() and getClientId(FacesContext) method of the UIComponent?

I guess the getClientId() 'generates an id if one does not exist.' Is that the big diff? Can't we expect every component to already have an id? I'm thinking especially during the validation or conversion phase. If a UIComponent is being validated, it's already been rendered at least once, so it would have to have an id, right?

JSF 1.2 UIComponent JavaDoc


Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4967

Well, when used in the validation method, if you want the <h:message for="xyz"/> tag to work, you need to use getClientId(xxx)

It seems getId() just generated the name that might be used in the tag, where the getClientId gets the fully qualified name.



text.getClientId --> rpsgameform:gesture
text.getId --> gesture
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14568
    
    7

Kito Mann mentioned that fact in his JSF in Action book.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Difference between UIComponent getId and getClientId(FacesContext)
 
Similar Threads
Is this a typo in the javadoc? (invokeOnComponent)
selectOneMenu
Programatically adding Trinidad components
UIViewRoot findComponent
create component with ajax and listener behavior in java