1 Reply Latest reply on Jul 12, 2008 5:46 AM by sergeysmirnov

    a:commandButton does not support onclick=

    coolstone

      I use RichFaces3.2.1, JBoss Seam 2.0.0.GA.
      To delete something, we ask the user to onfirm it.
      this code does not take any effect:

      <a:commandButton action="#{userList.deleteUser(item.id)}"
       reRender="searchResults"
       onclick="return confirm('are you sure?');"
       image="/img/Toolbar/tb_del.gif" style="border:0px;" />


      but this code works well:
      <h:commandButton action="#{userList.deleteUser(item.id)}"
       reRender="searchResults"
       onclick="return confirm('are you sure?');"
       image="/img/Toolbar/tb_del.gif" style="border:0px;" />


      a:commandButton does not support onclick="return confirm('are you sure?');" ? or here come a bug?

      Thank you!


        • 1. Re: a:commandButton does not support onclick=

          onclick for the a:commandLink has a code that triggers ajax call. If you define some statements for onlick, it is located in front of the ajax code. Putting 'return'there, you just make the rest code useless.
          If you look at the generated source, you can see something like:

          onclick="return confirm('are you sure?'); the_rest_ajax_code_here"

          As you can see, the_rest_ajax_code_here will be never executed regardless what confirm dialog returns.

          The solution is returning false only if the confirm return false.

          Try onclick="if (! confirm('are you sure?')) {return false};"