Search code examples
jsfjsf-2

Execute two methods in action in JSF


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

For example,

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

Solution

  • 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.