Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSF h:commandButton fires other command buttons within form?

Tags:

ajax

jsf

I have a form containing several h:commandButtons - all have f:ajax tags attached. When I trigger one of these command buttons, then I see in the log that all are actualy getting fired - so all actions are called?

Is this normal behaviour of the h:commandButton + f:ajax combination?

I'm using action attribute of commandButton and not the listener on f:fajax.

Hope someone can explain this to me.

Thanks in advance.

/Søren

EDIT:

Simplified code:

<h:form>
  <ui:repeat ...>
     <h:inputText value="#{order.quantity}"/>
  </ui:repeat>
  <h:commandButton type="button" action="#{facade.updateOrderItems()}" value="Update">
     <f:ajax execute="@form" render=":orderList" onevent="onAjaxEvent"></f:ajax>
  </h:commandButton>
  <h:commandButton type="button" action="#{facade.deleteSelectedOrderItems(order)}" value="Delete">
    <f:ajax execute="@form" render=":orderList" onevent="onAjaxEvent"></f:ajax>
  </h:commandButton>
  <h:commandButton type="button" action="#{facade.addOrdersItemsToWishList(order)}" value="Add to wish list"> <f:ajax execute="@form" render=":orderList" onevent="onAjaxEvent"></f:ajax>
                                </h:commandButton>
</h:form>

When I click the Update button it seems the Delete and Add to wish list buttons gets called as well...?

like image 227
sorenchristensen Avatar asked Mar 01 '26 12:03

sorenchristensen


1 Answers

I hope it's not to late. I had the same problem since two days ago and now solved it finaly. It turns out, that the problem is the type="button". So throwing this away is the workaround. In your f:ajax you have to use execute="@form" so that the valueChange-event is fired of the input-fields to have the data in the bean otherwise only the command-button is executed and the valueChange is not registered. So a button of yours should look like this:

<h:commandButton action="#{facade.deleteSelectedOrderItems(order)}" value="Delete">
   <f:ajax execute="@form" render=":orderList" onevent="onAjaxEvent"></f:ajax>
</h:commandButton>
like image 87
Daniel Müssig Avatar answered Mar 03 '26 10:03

Daniel Müssig



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!