2 Replies Latest reply on Jul 30, 2007 5:45 PM by rajakolli

    Concurrent Ajax calls throws View State could'nt be restored

    rajakolli

      I have a web Application and I am trying to submit 2 ajax calls simultaneously. The first one goes fine but the second one does'nt.

      Instead it throws me a "View State could'nt be restored. Reload page?"

      Please let me know whether using AJAX4JSF we could do multiple ajax calls at the same time.

      Any help would be grealty appreciated.
      Thank you in advance.

      Here's the code snippet.
      
      <h:selectOneMenu id='state' styleClass="selectOneMenu"
       value="#{RenewalOffer.state}"
       immediate="true">
       <a4j:support event="onchange" action="#{RenewalOffer.changeStateAction}" ajaxSingle="true"
       reRender="school" immediate="true"></a4j:support>
       <f:selectItems value='#{RenewalOffer.stateList}' />
       </h:selectOneMenu>
      
      
      <h:selectOneRadio id="schoolTerm" styleClass="selectOneRadio"
       value='#{RenewalOffer.schoolTerm}' rendered="#{RenewalOffer.kal}"
       binding="#{RenewalOffer.schoolTermC}">
       <a4j:support event="onclick" action="#{RenewalOffer.changeSchoolTermAction}"
       ajaxSingle="true" reRender="academicBeginPeriod,academicEndPeriod" immediate="true"></a4j:support>
       <f:selectItems value='#{RenewalOffer.schoolTermList}' />
       </h:selectOneRadio>
      


        • 1. Re: Concurrent Ajax calls throws View State could'nt be rest

           

          "rajakolli" wrote:

          Please let me know whether using AJAX4JSF we could do multiple ajax calls at the same time.


          This is a question for JSF implementation you use and the your application itself, but not to Ajax4jsf. JSF was developed in pre-ajax era. So, nobody expected the intensive simultaneous requests processed by the JSF lifecycle.

          From the Ajax4jsf side, it allows to organize the queue and processes the next request only the previous response returns back.

          For doing this you need to define the same queue name for bothe ajax requests sources.

          PS. Quote from the future richfaces demo:

          Queue and Traffic Flood Protection


          eventsQueue attribute defines the name of the queue that will be used to order upcomming Ajax
          requests. By default, RichFaces does not queue Ajax requests. If events are produced
          simultaneously, they will come to the server simultaniously. JSF implementations
          (especially, the very first ones) doe not guaranty that the request comes first will be
          served or pass the JSF lifecycle first. The order how the server side data
          will be modified in case of simultanious request might be unpredictable.
          Using eventsQueue attribute allows to avoid possible mess. Define the queue name explicitly,
          if you expect an intensive Ajax traffic in your application.


          The next request posted in the same queue will wait until the previos one is not
          processed and Ajax response returns back if the eventsQueue attribute is defined. In
          addition, Richfaces starts to remove from the queue the 'similar' requests. 'Similar' are
          the requests that produced by the same event. For example, you have the following code,
          only the newest request will be sent to the server if user types very fast and typed
          the several characters already before the previous Ajax response is back.

          <h:inputText value="#{userBean.name}">
          <a4j:support event="onkeyup" eventsQueue="foo"reRender="bar" />
          </h:inputText>

          requestDelay attribute defines the time (in ms.) that request will be wait in
          the queue before it is ready to be sent. When the delay time is over, the request will be
          sent to the server or removed if the newest 'similar' request is in queue already .

          ignoreDupResponses attributes orders to ignore the Ajax response produced by the
          request if the newest 'similar' request is in the queue already. ignoreDupResponses="true"
          does not cancel the request while it is processed on the server, but just allows to
          avoid unnssesary updates on the client side if the response loses the actuality.

          Defining the eventsQueue along with requestDelay allows to protect against unnssesary
          traffic flood and syncronizes the order of Ajax requests. If you have several source of
          Ajax requests, you can define the same queue name there. This might be very helpful if
          you have Ajax components that invoke request asynchronously from the ones produced by
          events from users. For example a4j:poll or a4j:push. In case the requests from such
          components modify the same data, the syncronization might be very helpful.

          • 2. Re: Concurrent Ajax calls throws View State could'nt be rest
            rajakolli

            Thank you for the prompt reply

            1) This is a question for JSF implementation you use and the your application itself, but not to Ajax4jsf.
            2) From the Ajax4jsf side, it allows to organize the queue and processes the next request only the previous response returns back.

            For some reason I got a little confused by the (1) and (2).

            But this is what I understood
            The JSF implementation (IBM) that I am using is creating the problem but not the AJAX4JSF lib.

            I think I agree with what you are saying because we had a similar problem with multiple JSF request problem.
            which we solved by synchronising the requests on session in the filter.



            
             if (session == null || uri.indexOf(".jsf") < 0) {
             chain.doFilter(request, response);
             } else {
             synchronized (session) {
             chain.doFilter(request, response);
             }
             }
            


            On your suggestions on using the eventsQueue.
            Pros: Good thing it works.
            Cons: The AJAX requests got sequential requests which is one thing that I would like to be changed to concurrent requests.


            So would you recommend me shifting to MyFaces to get rid of this problem.
            which then allows me to submit concurrent/simultaneous AJAX requests.