5 Replies Latest reply on Jan 15, 2009 10:30 AM by ilya_shaikovsky

    How to submit several forms by one button click

    koloale1

      I have several forms and want to submit ajax request that contains parameters from all these forms using only one AjaxCommandButton. Any thoughts how to accomplish it?

      Thanks in advance,
      Alexey

        • 1. Re: How to submit several forms by one button click
          koloale1

          When ajaxCommandButton is nested within form it creates button with onclick="A4J.AJAX.Submit('_viewRoot','form1',event,{'parameters':{'form1:saveBtn':'form1:saveBtn'} ,'actionUrl':'/editor.jsf'} );return false;"
          How I can parametrize button to include there form2 also.

          • 2. Re: How to submit several forms by one button click
            ilya_shaikovsky

            a4j:command works fully the same as h:command but using Ajax. So it submits the form around as standard ones.. All other approaches will looks like a hack ;) Why you can't use common form ?

            • 3. Re: How to submit several forms by one button click
              koloale1

              Because a have two different form on one page and want one button to submit both forms.
              I have rather complex layuot with one top property sheet, then tree on the left and another property sheet on
              the right, that depends on currently selected node in the tree. If I create one big form it would contains many elements (e.g. tree) that I don't want to send on save action. Instead I have two form for different property sheets. By the way it cause very incomprehensible errors with dupicated id if I don't separate elements to different forms.

              • 4. Re: How to submit several forms by one button click
                koloale1

                I found one solution but I'm not confident if it is fully correct and there wouldn't any pitfalls.
                In the first form I added button with js function call:

                <h:form id="form1">
                <a4j:commandButton onclick="nodeContentSave()"
                 actionListener="#{documentBean.save}"
                 value="Super Save"/>
                </h:form>


                and to the second form I added jsfunction:
                <h:form id="form2">
                 <a4j:jsFunction name="nodeContentSave"/>
                </h:form>
                





                • 5. Re: How to submit several forms by one button click
                  ilya_shaikovsky

                  Anyway resolving the issues connected to one common form seems preferrable for me. About your solution - so it sends two parallel requests. And possible problems with this case isn't RF specific.