[ 
https://issues.apache.org/jira/browse/MYFACES-2881?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12898833#action_12898833
 ] 

Werner Punz commented on MYFACES-2881:
--------------------------------------

Ok I coded an external solution as well which you can apply: 

function fixViewStates(data) {
    if (data.status == "success") {
        //do the viewstate post processing here
        var responseXML = data.responseXML;
        if (!responseXML) return;

        //first fetch the update element holding the viewstate
        var viewStateVal = null;
        var foundUpdates = responseXML.getElementsByTagName("update");
        if (!foundUpdates) return;
        for (var cnt = foundUpdates.length - 1; viewStateVal == null && cnt >= 
0; cnt -= 1) {
            if (foundUpdates[cnt].getAttribute("id") == 
"javax.faces.ViewState") {
                viewStateVal = foundUpdates[cnt].firstChild.nodeValue;
            }
        }

        if (!viewStateVal) return;

        for (var cnt = document.forms.length - 1; cnt >= 0; cnt -= 1) {
            //viewstate is in a cdata block
            _setVSTForm(document.forms[cnt], viewStateVal);
        }

    }
}

function _setVSTForm(theForm, viewstateVal) {
    var viewStateField = (theForm.elements) ? 
theForm.elements["javax.faces.ViewState"] : 
null;//this._Dom.findFormElement(elem, this.P_VIEWSTATE);

    if (viewStateField) {
        viewStateField.value = viewstateVal;
    } else if (!viewStateField) {
        var element = document.createElement("div");
        element.innerHTML = ["<input type='hidden' name='", 
"javax.faces.ViewState" ,"' value='" , viewstateVal , "' />"].join("");
        try {
            theForm.appendChild(element.childNodes[0]);
        } finally {
            element.innerHTML = "";
            //ie gc screwup fixup
            if ("undefined" != typeof element.outerHTML) {
                element.outerHTML = "";
            }
        }
    }
}

you can use this function as a listener:

jsf.ajax.request(document.getElementById('queued3'), event, {execute:'@this', 
render:'refresh', onevent: fixViewStates});

if you send the function down as onevent handler or register it as global 
handler it also will fix the viewstate for mojarra properly in a non portlet 
environment.
This solution definitely works over both implementations and fixes the issue 
properly.



> Server state saving with two forms, ajax and normal request is broken
> ---------------------------------------------------------------------
>
>                 Key: MYFACES-2881
>                 URL: https://issues.apache.org/jira/browse/MYFACES-2881
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General
>    Affects Versions: 2.0.1, 2.0.2-SNAPSHOT
>         Environment: myfaces 2.0.1 or trunk; 
>            Reporter: Martin Kočí
>            Priority: Blocker
>             Fix For: 2.1.0
>
>
> Use simple xhtml with: 
> <h:form id="form1">
>             <h:commandButton value="Partial">
>                <f:ajax execute="@this" render="@this" />
>             </h:commandButton>
> </h:fom>
> </h:form>
>   <h:form id="form2">
>   <h:commandButton value="Full" />
> </h:form>
> then:
> 1) click "Partial" button 20x or more
> 2) click "Full" button
> -> ViewExpiredException appears. If you click "Partial" 19 times or less 
> ViewExpiredException does not appear. 
> 20 is default for NUMBER_OF_VIEW_IN_SESSION - it you set this param to 1 you 
> reproduce this problem with two clicks. Maybe there is more simple test case 
> for reproducing this issue but I didn't find it yet. 
> This bug is present in 2.0.1 already and is related to server state saving:
> myfaces 2.0.1:
> PSS + server: failed
> PSS + client: ok
> FSS + server:  failed
> FSS + client: ok
> myfaces 2.0.2-SNAPSHOT:
> PSS + server: failed
> PSS + client: ok
> FSS + server:  failed
> FSS + client: ok
> Very likely this causes MYFACES-2877 too. 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to