How can I generate a unique JavaScript variable name from a JSF clientId? -
i want define javascript function every instance of jsf composite component.
for this, inside component, i'm trying like:
<h:outputscript> function myfunction_#{component.clientid}(day) { //do instance specific stuff } </h:outputscript>
specifically trying use function in richfaces calendar this:
<rich:calendar id="calendar" ... dayclassfunction="myfunction_#{component.clientid}">
but clientid doesn't contain characters valid in javascript variable names.
is there way calculate md5 hash or pseudo-unique clientid (or else!) inside jsf el expression?
i need instance-specific because return value relies on instance values , dayclassfunction attribute doesn't accept function takes clientid or likewise specific argument.
i've done before this:
window['#{cc.clientid}'] = { myfunction1 : function() { ... }, myfunction2 : function() { ... } };
then call need with
dayclassfunction="window['#{cc.clientid}'].myfunction1()"
this way scoped component. can add prefix client id never conflict other variable names on window scope.
can't think of character, allowed in client id, break javascript.
Comments
Post a Comment