Execute two methods in action in JSF

百般思念 提交于 2019-12-20 08:59:40

问题


Is it possible to execute two methods in action of <h:commandButton>?

For example,

<h:commandButton action="#{bean.methodOne();bean.methodTwo();}" />

回答1:


You can use f:actionListener like this.

  <h:commandButton action="#{bean.methodOne();}">
    <f:actionListener binding="#{bean.methodTwo();}" />
  </h:commandButton>

You can add as many f:actionListener elements as you need.




回答2:


Add a methodThree in your bean :

public Object methodThree() {
    methodOne();
    methodTwo();
    return someThing;
}

And call this method from the JSF page.




回答3:


The accepted answer was close to working for me but the semi-colon was throwing a parse exception. The below code worked:

<h:commandButton>
    <f:actionListener binding="#{bean.methodTwo()}" />
</h:commandButton>


来源:https://stackoverflow.com/questions/7912663/execute-two-methods-in-action-in-jsf

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