3 Replies Latest reply on Feb 11, 2009 8:58 PM by Nick Belaevski

    Performance and ajax request content

    Kerdudou Ronan Apprentice

      Hi all,

      Since we use RichFaces we don't stop to struggle with performance bottleneck.
      We know well what ajaxsingle, region and immediate can help us but it's not sufficient.
      One of our problem is large form or large editable datatable.
      In such a case, every ajax request sent from the form send all the data even if unnecessary.
      When the datatable is large with a lot of inputs. The request building on client side with IE can make more 3 secs (saw all the " Append text control ..." in a4j:log).

      - First question, if there any mean to send an ajax request from a given form but without sending the data of the form ?

      So, we tried another way: We tried to replace all inputs of the form by a simple outputs (in a JSF term) that can be editable only on click (via javascript/prototype replace method) (a la google spreadsheet). But here, we don't know how to synchronize the newly javascript enabled input with the view on the server side (that does not know any input on the page).

      Any hint or advice would be greatly appreciated.

        • 1. Re: Performance and ajax request content
          Kerdudou Ronan Apprentice

          Is there someone from the richfaces team that can explain us the following principle:

          quoted from http://livedemo.exadel.com/richfaces-demo/richfaces/ajaxAttributes.jsf?c=ajaxattributes&tab=usage:

          Data Processing Options
          "RichFaces uses form based approach for Ajax request sending.[...]

          ajaxSingle - boolean attribute which provides possibility to limit JSF tree processing(decoding, conversion/validation, value applying) to the component which send the request only. "


          To make things clear, it seems that all ajax requests always send the closest form with all its inputs whatever the "ajaxSingle" attribute or is set or not.

          If I'm right, why RC send all the inputs if they are ignored on server side ?

          Once again, I'm asking if there any mean to send an ajax request from a given form but without sending the data of the form ?

          thanks for any answer.



          • 2. Re: Performance and ajax request content
            Nick Belaevski Master

            For the first post:

            <h:form id="form">
             <a4j:loadScript src="resource:///org.ajax4jsf.javascript.PrototypeScript" />
            
             <script type="text/javascript">/*<![CDATA[*/
             function addInput(elt) {
             var inputId = elt.id.replace(/\:text$/, ":input");
             var input = $(inputId);
             if (!input) {
             Element.insert(elt, {after: "<input type='text' onblur='var elt = $(\"" + elt.id + "\"); elt.innerHTML = this.value; Element.hide(this); Element.show(elt);' name='" + inputId + "' id='" + inputId + "' />"});
             }
             input = $(inputId);
            
             input.value = elt.innerHTML;
             Element.hide(elt);
             Element.show(input);
             input.focus();
             }
             /*]]>*/</script>
            
             <a4j:repeat id="repeat" var="item" value="#{forum5Bean.data}">
             <h:inputText value="#{item.value}" id="input" rendered="#{empty renderPhase and param[rich:clientId('input')] != null}" />
            
             <a4j:outputPanel onclick="addInput(this)" id="text">
             <h:outputText value="#{item.value} " />
             </a4j:outputPanel>
            
             <br />
             </a4j:repeat>
            
             <h:commandLink value="Submit" />
            </h:form>


            Phase listener class:
            package demo;
            
            import javax.faces.event.PhaseEvent;
            import javax.faces.event.PhaseId;
            import javax.faces.event.PhaseListener;
            
            public class RenderPhaseListener implements PhaseListener {
            
             public void afterPhase(PhaseEvent event) {
             }
            
             public void beforePhase(PhaseEvent event) {
             event.getFacesContext().getExternalContext().getRequestMap().put("renderPhase", Boolean.TRUE);
             }
            
             public PhaseId getPhaseId() {
             return PhaseId.RENDER_RESPONSE;
             }
            
            }


            • 3. Re: Performance and ajax request content
              Nick Belaevski Master

              A bit enhanced page:

              <h:form id="form">
               <a4j:loadScript src="resource:///org.ajax4jsf.javascript.PrototypeScript" />
              
               <script type="text/javascript">/*<![CDATA[*/
               function addInput(elt) {
               var inputId = elt.id.replace(/\:text$/, ":input");
               var input = $(inputId);
               if (!input) {
               Element.insert(elt, {after: "<input type='text' onblur='var elt = $(\"" + elt.id + "\"); elt.innerHTML = this.value; Element.hide(this); Element.show(elt);' name='" + inputId + "' id='" + inputId + "' />"});
               }
               input = $(inputId);
              
               input.value = elt.innerHTML;
               Element.hide(elt);
               Element.show(input);
               input.focus();
               }
               /*]]>*/</script>
              
               <a4j:repeat id="repeat" var="item" value="#{forum5Bean.data}" rowKeyVar="rk">
               <c:set var="clientId" value="form:repeat:#{rk}:input"/>
              
               <h:inputText value="#{item.value}" id="input" rendered="#{empty renderPhase and param[clientId] != null}" />
              
               <a4j:outputPanel onclick="addInput(this)" id="text">
               <h:outputText value="#{item.value}" />
               </a4j:outputPanel>
              
               <br />
               </a4j:repeat>
              
               <h:commandLink value="Submit" />
              </h:form>