Search code examples
jsfcommandbutton

Is there any way to call a method with h:commandButton without reloading page?


<h:commandButton value="A"   action="#{juegoService.ingresarPalabra('A')}">

</h:commandButton>

I'm using JSF 2.0, and I have a button like the above, for each letter of the alphabet that call a method that load an image on the page, depending the word you press will load the corresponding image, but I need to call the method without reloading the page because I can only have loaded one image on the page, because when I click other the page reloads the Bean and the other image returns to the first state thats its not charged.


Solution

  • You should use f:ajax and refresh container with image.

        <h:commandButton value="A with AJAX" id="button" action="#{juegoService.ingresarPalabra('A')}" >
          <f:ajax execute="@this" render="containerId" />
        </h:commandButton>