jquery - Pull bean value as String for Javascript use -


i'm trying set component's text based on bean's value. i'm using jquery because text changes depending on conditions.

so, jquery code looks this:

window.onload =function(){     $('.pnx-inline-input').on("change keyup paste", function(){         var savetext = #{extra.active_save};                         $('.save-button .pnx-btn-text').html(savetext); }); 

the bean handles localization. so, let's locale france, , text enregister. thing when rendered page, code segment looks this

window.onload =function(){     $('.pnx-inline-input').on("change keyup paste", function(){         var savetext = enregister;                       $('.save-button .pnx-btn-text').html(savetext); }); 

of course, enregister not defined anywhere, , causes error. need have code like

var savetext = "enregister"; 

for make sense.

how can make happen? thanks!

jsf in context of question merely html code generator. write down quotes in html template. part of generated html output, not of java variable. know, javascript doesn't run java/jsf (i.e. it's not server side). instead, runs html (i.e. it's client side).

var savetext = "#{extra.active_save}"; 

note still need take account value js-escaped, otherwise whole thing still break in javascript side if string contains doublequotes or other special characters in js such newlines. jsf utility library omnifaces has el function purpose, #{of:escapejs()}:

var savetext = "#{of:escapejs(extra.active_save)}"; 

you can of course homegrow own based on e.g. apache commons lang stringescapeutils.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -