Finding/Selecting RichFaces Components using jQuery

by Michael Scepaniak on November 4, 2010 in software development

If you try to use jQuery to interact with JSF Richfaces components, you might run into difficulty selecting those components using their ID. The match is never made for some reason. That “reason” might very well be that RichFaces tends to put colons in the ID’s of their generated DOM elements. For example:

editForm:requiredOptions:1:listAllOptions:0:colorBox

There’s nothing wrong with this. It’s very well structured and successfully handles nested components and collections. But, if you try to get jQuery to select the component matching this ID, you’ll fail because of the colons. The solution is to properly escape the colons in the ID before passing it to the selector:

var componentId = component.id;
componentId = componentId.replace(/:/g, "\:");
var $component = jQuery("#" + componentId);

Hope this helps.

Mike
Want to be notified when new articles are posted?
Enter your email address:

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post:

Member of The Internet Defense League