2 Replies Latest reply on May 2, 2007 1:56 PM by sergeysmirnov

    a4j:commandLink onclick return value affects behaviour

    mkuehle

      Hi,

      it seems that the return value of any javascript function which is called in onclick attribute of a4j:commandLink does stop the ajax call.

      In my case i need a user confirmation if user clicks on an a4j:commandLink. If the user cancel the confirmation the ajax call shouldn't be performed. If the user pushes 'OK' the confirmation dialog returns true and the a4j:commandLink should perfom the ajax call but it doesn't.

      The following code

      <a4j:commandLink action="#{MyBB.doit}" reRender="myComp" onclick="return confirm('Confirm it');">Delete Entry</a4j:commandLink>


      It doesn't matter wich case the confirmation returns ('OK' -> true or 'Cancel' -> false) the a4j:commandLink doesn't perform the ajax call.

      But also if onclick="return true;" is set the ajax call wouldn't be perfomed.

      I would expect that 'return true' will perform the normal behaviour. My question is: how can i implement a user confirmation for this component?

      In this example the ajax call to delete an entry should only be performed if the user will confirm this action.
      Thanks for any suggestions.

        • 1. Re: a4j:commandLink onclick return value affects behaviour
          mkuehle

          I found the answer to solve this problem.

          The answer ist not to return a return value if the confirmation returned true. Because if the custom javascript in onclick attribute returns a value the following javascript which is added automatically by ajax4jsf framework to submit the form wouldn't be executed (as normal behaviour if there is a return statement... ;).

          So if i change the onclick javascript to the following it works like i expect it.

          <a4j:commandLink action="#{MyBB.doit}" reRender="myComp" onclick="if(!confirm('Confirm it')){return false;}">Delete Entry</a4j:commandLink>


          I found this solution through the "Custom Java Script together with Ajax4jsf" Example (http://livedemo.exadel.com/a4j-jsEvents/).

          Maybe someone needs this information...

          • 2. Re: a4j:commandLink onclick return value affects behaviour

            Yes, you are right here. Actually, I answered a similar question in another thread, but missed your question. Sorry. I was very simple to answer.