[英]How to call bean method from javascript function using a4j:ajax or a4j:actionListener?
I am using JSF, richfaces 4 stuff and i want to call a bean method when javascript function trigger.我正在使用 JSF,richfaces 4 东西,我想在 javascript function 触发时调用 bean 方法。
You can use <a4j:jsFunction>
, which allows you to perform Ajax requests to invoke the bean method directly from JavaScript code, and the response can be returned in a JSON format to use in a client JavaScript calls. You can use <a4j:jsFunction>
, which allows you to perform Ajax requests to invoke the bean method directly from JavaScript code, and the response can be returned in a JSON format to use in a client JavaScript calls.
Please note that <a4j:jsFunction>
is required to be inside a <h:form>
.请注意<a4j:jsFunction>
必须在<h:form>
内。 For example, you define the a4j:jsFunction likes this:例如,您像这样定义 a4j:jsFunction:
<h:form>
<a4j:jsFunction name="myJsFunction" action="#{bean.someAction}" reRender="xxxxx"/>
</h:form>
A javascript function which name called myJsFunction()
is created and it will invoke someAction() on the bean when being called.一个名为myJsFunction()
的 javascript function 被创建,它会在被调用时在 bean 上调用 someAction()。
For example, in your javascript function:例如,在您的 javascript function 中:
<script type="text/javascript">
function yourJavaScriptFuntion() {
..............;
myJsFunction(); //bean.someAction() will invoke here
..............;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.