Using jquery ajax to call a jsf managed bean method (an AjaxBehaviorEvent listener handler)

*爱你&永不变心* 提交于 2019-12-03 07:37:07

Here you go:

<script type="text/javascript">

    doAwesomeness();

</script>

In your page:

<a4j:jsFunction name="doAwesomeness" action="#{awesomeBean.awesomeMethod}"/>

Good luck!

Daniel

jQuery ajax request and JSF ajax request uses different js library's , I don't think there is a point in trying to mix those to too much...

If you whish to fire a JSF managed bean action from jQuery you better use a hidden h:commandButton for that purpose...

JSF:

<h:commandButton id="someId" action="#{someBean.someMethod}" style="display:none">
    <f:ajax render="someId" execute="someId"/>
</h:commandButton>

if you want to pass some more hidden args you can add some more hidden JSF components ids in the hidden h:commandButton execute attribute, that way their corresponding properties will be updated on server side...

js

$("#someId").click();

On the other side , if you want to use managed bean data in servlets that corresponds to your jQuery calls you can always access that JSF managed data, like this : JSF - get managed bean by name

In the same vein as pointed out by islandguy, if you use Primefaces, you woud use the <p:remoteCommand/> command, as follows :

<script type="text/javascript">
      doAwesomeness();
</script>

with :

 <p:remoteCommand name="doAwesomeness" 
          actionListener="#{awesomeBean.awesomeMethod}"
          oncomplete="jsToExecuteOnAjaxSuccess()" />

Hope this helps..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!