how to get the value of the managed bean property inside javascript

advertisements

This question already has an answer here:

  • How do I pass JSF managed bean properties to a JavaScript function? 3 answers

Can anyone tell me how to get the managed bean property value inside the javascript method

something like

function fonction1() {
  var variable = "#{myBean.property}";
}


You can like this:

<h:inputText id="propertyId" value="#{myBean.property}" style="display:none"/>

and access it like this (note that if its inside a form you might need to add the form prefix)

alert($('#propertyId').val()); // or alert($('#myFormId\\:propertyId').val());