Call multiple bean method in primefaces simultaneously

和自甴很熟 提交于 2019-12-19 10:22:19

问题


I am building a web application using primefaces-4.0. I wanted to call two bean methods simultaneously on click of command button. I tried it by using remoteCommand.

<p:commandButton value="Submit" ajax="false"
                        actionListener="#{userBean.execute}"
                        onclick="callCorrelation()">
                    </p:commandButton>
                    <p:remoteCommand name="correlation" update="correlationDialog"
                        actionListener="#{userBean.correlation}" />

Java Script function :

<head>
<script type="text/javascript">
    $(document).callCorrelation(function() {
        correlation ();
    });           
</script>
</head>

But it did not work.

Is there any other way to call two bean methods simultaneously?


回答1:


Your concrete problem is caused because you've turned off ajax by ajax="false". This will create a synchronous form submit which makes it impossible to fire an ajax request along. If you remove ajax="false", then it will likely work, but you've still a race condition if the one method depends on the result of the other. It's not defined which one would be executed first.

Better just use a single command component. You can use action and actionListener together. The action is intented for business actions. The actionListener is intented for preparing of business actions. If you need more action listeners, just nest a <f:actionListener> or perhaps a <f:setPropertyActionListener>.

<p:commandButton value="Submit"
    actionListener="#{userBean.correlation}"
    action="#{userBean.execute}"
    update="correlationDialog" />

See also:

  • Differences between action and actionListener


来源:https://stackoverflow.com/questions/18850322/call-multiple-bean-method-in-primefaces-simultaneously

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