Maire Kehoe commented on Jul 13, 2010

how to get the components ID in the Client Side in XPages

Thanks for posting, I appreciate you sharing the knowledge.

You can use the syntax you've described to insert Server Side JavaScript (SSJS) inline within your client scripts:

var tempID = '#{javascript:getComponent("country1").getClientId(facesContext)}'

which is useful because it allows you to do any SSJS computation, which may be quite complicated.

For the specific example you're talking about, where you're only looking up the cliendId,

because clientIds are used so often XPages has a special computed value engine just to handle it,

so instead of using a javascript: computation you can use an id: computation, like so:

var country1 = '#{id:country1}';

To look up the node corresponding to the ID, the XPages tutorials generally use

var country1 = XSP.getElementById("#{id:country1}");


var country1 = dojo.byId("#{id:country1}");

where the first option is described here:

and dojo.byId is described here: