javascript 如何在javascript中获取托管bean属性值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14812163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 22:38:22  来源:igfitidea点击:

how to get managed bean property value inside javascript

javascriptjqueryjsfprimefaces

提问by Bob Samadi

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

谁能告诉我如何在 javascript 方法中获取托管 bean 属性值

something like

就像是

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

回答by Daniel

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());

回答by fmsf

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.

我猜您希望它更新为 bean 内的当前值。你不能!您只能在加载期间将其添加到 javascript。如果您希望它被更新,您将不得不执行 ajax 调用来获取当前值。