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

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -