3
votes

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

1
That's weird. Post a code example showing this bug.Luiggi Mendoza
try using immediate=true in your <h:commandButton> like this <h:commandButton immediate=true action=..../>Anas
immediate=true solves part of the problem. The other buttons are not executed - however my values from inputText is not set in bean :-( If I replace @ form with @ this then it also seems that everything is working, but again I'm not getting the data into my bean...sorenchristensen

1 Answers

3
votes

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>