[prev in list] [next in list] [prev in thread] [next in thread] 

List:       myfaces-user
Subject:    Re: ViewExpiredException with multiple forms on a page and ajax calls
From:       Francois Grandjean <fgrandjean () darts-ip ! com>
Date:       2011-10-11 7:50:32
Message-ID: 4E93F548.1010508 () darts-ip ! com
[Download RAW message or body]

Thank you for the update, Werner.
I will keep with the fix proposed by Leonardo as it provides a global 
solution (I don't want to create too much coupling between my forms, and 
having to specify each time the multiple rendering targets) and I don't 
need to have a mojarra compatible solution.

Francois

On 6/10/2011 09:27, Werner Punz wrote:
> Hi, sorry to jump in so late.
> First of all the problem is not a MyFaces problem but a deficit in the 
> JSF spec which hopefully will be resolved one way or the other in 2.2.
> Secondly Leo already posted the (better) myfaces workaround which 
> fixes the issue. But this works only for myfaces if you need to have 
> it working for mojarra as well as for myfaces since jsf 2.1 there is 
> another official wworkaround. You can put rendertargets which you 
> refresh for every request in every form. Having such a render target 
> allows you
> to have the viewstate properly updated in every form.
> 
> Here is a short example to the issue:
> http://code.google.com/a/apache-extras.org/p/myfaces-js-integrationtests/source/browse/src/main/webapp/integrationtests/test14-multiform.xhtml \
>  
> 
> this uses two forms and a render target in each form.
> 
> You can see the idea behind it. This behavior is part of the jsf 2.1 
> spec but in my opinion just a hotfix, the final resolution for this 
> issue really must come from the spec side itself by updating the ajax 
> protocol, everything else just is a hack.
> 
> Werner
> 
> 
> Am 10/4/11 11:37 PM, schrieb Leonardo Uribe:
> > Hi
> > 
> > The problem is not all hidden fields containing the state are updated
> > after the submit. It is a known problem, see:
> > 
> > https://issues.apache.org/jira/browse/MYFACES-2881
> > 
> > For more details.
> > 
> > Try add this after your jsf.js include:
> > 
> > <script type="text/javascript">
> > //fixup for an issue of the jsf2.0 and 2.1 ajax spec to deal
> > with multiple forms per page
> > window.myfaces = window.myfaces || {};
> > myfaces.config = myfaces.config || {};
> > myfaces.config.no_portlet_env = true;
> > </script>
> > 
> > That should work. Note
> > org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION is used when
> > you have a multi-window app, to prevent one window swallow all slots
> > in session and prevent the other window to throw ViewExpiredException.
> > So if you set this to 2, there will be only 2 slots per window. Since
> > not all javax.faces.ViewState hidden fields are updated, the state
> > manager cannot restore the state because that view was already purged
> > from session map.
> > 
> > regards,
> > 
> > Leonardo Uribe
> > 
> > 2011/10/4 Scott O'Bryan<darkarena@gmail.com>:
> > > Nope..  The higher the number the longer it will take tp expire.
> > > Picture this.  Each form has a view state.  Durring a PPR, the view
> > > state is altered for the form your submitting, but not for the other
> > > one.  When that form is submitted, the page thinks you're using a form
> > > from a long time back.  Picture someone hitting the back button 20
> > > times and the. Resubmitting a form..
> > > 
> > > Generally it's considered bad form JSF, especially one involving
> > > AJAX, to have multiple forms.
> > > 
> > > Scott
> > > 
> > > Sent from my iPhone
> > > 
> > > On Oct 4, 2011, at 4:40 AM, Francois 
> > > Grandjean<fgrandjean@darts-ip.com>  wrote:
> > > 
> > > > Hi,
> > > > 
> > > > I'm using MyFaces 2.1.3. and I face a problem when using two forms 
> > > > on the same page, one of them being refreshed several times through 
> > > > ajax calls before a commandLink is called on the other form.
> > > > This results in a ViewExpiredException being thrown.
> > > > Here's a simple page to reproduce the problem:
> > > > 
> > > > <h:form id="form1">
> > > > <h:commandLink id="link1" value="Submit form 1">
> > > > <f:ajax/>
> > > > </h:commandLink>
> > > > </h:form>
> > > > <h:form id="form2">
> > > > <h:commandLink id="link2" value="Submit form 2"/>
> > > > </h:form>
> > > > 
> > > > If I click on link1 more than 20 (or the value of 
> > > > 'org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION') times and then 
> > > > click on link2 I get a ViewExpiredException.
> > > > This looks similar to the problem depicted in MYFACES-3117, so I 
> > > > tried to use parameter 
> > > > 'org.apache.myfaces.NUMBER_OF_SEQUENTIAL_VIEWS_IN_SESSION' and set 
> > > > it to a lower value, say 2.
> > > > But then I get the ViewExpiredException even quicker, after just 
> > > > two clicks on link1.
> > > > 
> > > > Is there something I'm doing wrong here or is this a bug or a 
> > > > limitation of the specs?
> > > > And is there any other workaround than increasing the value of 
> > > > org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION or trying to replace 
> > > > my h:commandLink's by h:outputLink or h:link's ?
> > > > 
> > > > Thanks for your help!
> > > > 
> > > > Francois
> > > 
> > 
> 
> 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic