3

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

something like

function fonction1() {
  var variable = "#{myBean.property}";
} 
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Bob Samadi
  • 137
  • 2
  • 5
  • 13
  • What exactly is the problem with the code posted so far? It should work just fine, provided that it's enclosed in a Facelets file and the property returns a valid (escaped) JS string. – BalusC Feb 11 '13 at 13:36

2 Answers2

8

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());
Daniel
  • 36,833
  • 10
  • 119
  • 200
  • can i make a hidden button and create and launch a click on the button from JavaScript ? – Bob Samadi Feb 11 '13 at 13:00
  • yep , `` , then click it like this `$("#my_button").click()`; – Daniel Feb 11 '13 at 13:04
  • function fnc(){ length=document.getElementById('form:aa').value.length; if(length == 10){ $("#hh").click(); }} When I execute this function click launches when the page loads but not when I call the function :( – Bob Samadi Feb 11 '13 at 13:27
  • not sure what you are trying to do exactly, but is looks like a different question, so accept the answer and ask a new question... – Daniel Feb 11 '13 at 13:30
0

I guess you want it to be updated to the current value inside the bean. You can't! You can only add it to javascript during load time. If you want it to be updated you will have to do ajax calls to fetch the current value.

fmsf
  • 36,317
  • 49
  • 147
  • 195