You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Michael Heinen <mh...@googlemail.com> on 2011/12/28 12:34:14 UTC
Re: ViewExpiredException with multiple forms on a page and ajax calls
Hi,
I run recently also in this problem and solved it by adding the proposed
script which sets myfaces.config.no_portlet_env to true.
Werner said in Issue MYFACES-2881
(https://issues.apache.org/jira/browse/MYFACES-2881)
that he provided also a patch to myFaces and that the final fix will be
in 2.1 (a protocol change regarding the viewstates or a viewroot
detection method)
Question:
What's this final fix?
I run into this issue with myfaces 2.1.5 and richfaces 4.1.
Should the config parameter myfaces.config.no_portlet_env still be
necessary or should this work now out of the box?
Michael
Am 11.10.2011 09:50, schrieb Francois Grandjean:
> 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<da...@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<fg...@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
>>>>
>>>
>>
>>
>