5 Replies Latest reply on Aug 15, 2011 6:50 AM by Adi Katz

    All form elements are being submitted when ajaxSingle="true"

    Adi Katz Novice

      Hello,

       

      This is not a new issue as I seen it before on this forum but I never found an answer that I could live with

      I am using RichFaces 3.3 and while debugging browser side ( with firebug ) it is clear that all form elements are being

      sent to the server on ajax requests. Setting the ajaxSingle property affects only the server side apparently.

      To my eyes this is negating the all idea behind ajax... Why should I create more network traffic and load on my server when I am intersted only in few bytes of information from the client side ?? ( the http request is still being parsed fully on the server even if the majority of it is not processed by rich faces)

      So my first question, Is there any design decision behind this behaviour ?

      More practically, My application generates forms dynamically which can get very big ( hundreds of inputs ) while the user changes only few of them and one each time. Submitting all this data back to the server each time the user changes a value is an overkill. Seems I will be better of just with simple form submission...

       

      Any of you wise people can advise me ?

       

      Thanks!

        • 1. Re: All form elements are being submitted when ajaxSingle="true"
          Mark Paluch Master

          Hi Adi,

          some thougts on this:

          A form submission needs to be complete, because of validation and possible data requirements in the execution of the request. If you would send only half of the data and your process behind needs some data which was entered but not submitted you would get a problem. On the other side, hundreds of inputs indicate a bad application design. And if you just want to transmit the data you need, minimize network traffic and overhead you probably should not use JSF anyway, stay with JSP and servlets.

           

          Best regards,

          Mark

          • 2. Re: All form elements are being submitted when ajaxSingle="true"
            Adi Katz Novice

            Hi Mark,

             

            Thanks for your answer, but I do not agree with you for the following reasons:

            1) The application developer knows exactly what is needed on the server side and can design an accurate ajax behaviour. Good framework should not enforce application behaviour of any kind! Application errors are for the developer to deal with. I expect of a good framework flexibility rather than "helpful" limitations.

            2) Example: A web based spreadsheet is a classic ajax application that potentially can have thousands of inputs on the screen while the user changes one at a time and wants to see other inputs updated. So again, your suggestion for sticking to "JSP" and servlets is not relevant.

             

            Best regards,

            Adi

            • 3. Re: All form elements are being submitted when ajaxSingle="true"
              Adi Katz Novice

              Digging in the source code a bit reveals:

               

              org.ajax4jsf.renderkit.AjaxRendererUtils line 286 is commentted out. Uncommenting it will cause the browser to submit only the ajaxed value.

               

              if (ajaxSingle ) {

                        parameters.put(AJAX_SINGLE_PARAMETER_NAME, targetComponent.getClientId(facesContext));

                        // options.put("single", JSReference.TRUE);

                        if (input) {

                                  options.put("control", JSReference.THIS);

                        }

              }

               

              Can someone from RichFaces team can explain rationale behind it ?

               

              Thanks

              Adi

              • 4. Re: All form elements are being submitted when ajaxSingle="true"
                Bernard Labno Master

                Some complex components have their client id on i.e. DIV surrounding input, so submitting value of element under componentId would trigger error in javascript. Other reason is that client side doesn't know of how many inputs given component consists. There can be component consisted of several inputs, their id's must be different, so there is no way to tell client side which controls are to be submit for given component.

                Thus everything in form gets submitted and the components on the server side decide what parameters are for them.

                1 of 1 people found this helpful
                • 5. Re: All form elements are being submitted when ajaxSingle="true"
                  Adi Katz Novice

                  Hello Bernard,

                   

                  Thanks for your reply. This make sense, but the simple case ( which covers 90% of use cases I believe ) is just an a4j:support component attached to h:InputText. In this case really there is no need for full form sumbmission. It just diminish the full strength of an Ajaxed web app.

                   

                  Can I suggest this becomes an optional parameter on the a4j:support component ?

                  I think this is something the framework should leave for the developer to control ( with the disclaimer from your reply )

                   

                  Thanks

                  Adi