how to rerender a4j:commandLink after the action has been completed

Ikthiander picture Ikthiander · Jun 6, 2013 · Viewed 7.2k times · Source

i have a very simple code here:

<a4j:commandLink action="#{ticketAboxEventHelper.removeAboxTicket(ticketAbox)}"
                             onclick="if(!confirm('Are you sure ... ?')) return false;"
                             reRender="aboxlistpanel">
                        <h:graphicImage alt="Delete" url="../../img/dialog-error-5.png" title="Delete" />
                        <a4j:support event="oncomplete" 
                                     action="#{editTicketNewAction.testRerender()}" 
                                     reRender="aboxlistpanel"
                                     />
</a4j:commandLink>

When the link clicked the system must

  1. ask if the user is confirmed
  2. do the action
  3. rerender the aboxlistpanel

Now my problem is the rerendering is hapenning before the action is getting finished. any idea how it can be done in the right way?

Answer

Alexandre Lavoie picture Alexandre Lavoie · Jun 6, 2013

Your action methods is not valid for JSF 1.2 and you don't need the <a4j:support>. Since you want to pass a parameter, you should use <f:attribute /> and actionListener :

<a4j:commandLink actionListener="#{ticketAboxEventHelper.removeAboxTicket}" onclick="if(!confirm('Are you sure ... ?')) return false;" reRender="aboxlistpanel">
    <h:graphicImage alt="Delete" url="../../img/dialog-error-5.png" title="Delete" />
    <f:attribute name="ticket" value="#{ticketAbox}" />
</a4j:commandLink>

Your bean method will look like this :

public void removeAboxTicket(ActionEvent event)
{
    TicketAbox ticket = (TicketAbox)event.getComponent().getAttributes().get("ticket");

    // Your business logic
}

More info :