2 Replies Latest reply on Dec 30, 2009 9:20 PM by Rocky S

    Calling js function from .xhtml?

    Rocky S Master

      I have a requirement to open a confirmation box in order to perform the delete operation.

       

      Currently my delete button is defined here. So if the user clicks delete button, he gets a confirmation box to perform delete operation.

                  <h:commandButton id="delete"
                                value="Delete"
                               action="#{collatRptCatgryHome.remove}"
                            immediate="true"
                             rendered="#{collatRptCatgryHome.managed}">
                     </h:commandButton>

       

      I know i can do it easily in javascript.

      <script type="text/javascript">
      function show_confirm()
      {
      var r=confirm("Press a button");
      if (r==true)
         {
         document.write("You pressed OK!");
         }
      else
         {
         document.write("You pressed Cancel!");
         }
      }
      </script>

       

      Can you please show me how do i call this function show_confirm(). Please note on pressing Yes, above defined action should be invoked.

        • 1. Re: Calling js function from .xhtml?
          Rocky S Master

          Finally i achieved something.

           

          <a:commandButton id="delete1"
                                    value="Delete1"
                                   action="#{collatRptCatgryHome.remove}"
                                immediate="true"
                                 rendered="#{collatRptCatgryHome.managed}"
                         onclick="confirm('Please')">              
          </a:commandButton>

           

          But this code has 1 problem, in the confirmation box, either i click on OK or cancel, it will still proceed to perform the delete operation.

          I need, when cancel is clicked, it should not proceed with the delete operation.

          • 2. Re: Calling js function from .xhtml?
            Rocky S Master
            finally i got the solution. i will post soon, it will be helpful for others.