JSF ViewState does not update when submitting 2 forms

I have a problem with JSF 2. I am using Mojarra 2.1.14 with Primefaces 3.1.4

I have a page with two forms: formA and formB . Two forms contain each ViewState view in a hidden input field.

<h:form id="formA" binding="#{sessionBean.formA}">
    <h:commandButton value="formA" action="#{sessionBean.actionA}">
        <f:ajax/>
    </h:commandButton>
</h:form>

<h:form id="formB" binding="#{sessionBean.formB}">
    <h:commandButton value="formB" action="#{sessionBean.actionB}">
        <f:ajax/>
    </h:commandButton>
</h:form>

The user submits formA using an Ajax action. Inside the Java action, I explicitly update formA and formB (which are bound).

public void actionA(){
    FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add(formA.getClientId());
    FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add(formB.getClientId());
    System.out.println("action A!!");
}

public void actionB(){
    System.out.println("action B!!");
}

Ajax answers have HTML code for formA and formB (element) and ViewState.

JSF HTML formA formB ViewState : formA. formB ViewState.

formB Ajax. ViewState , postBack , renderResponse true RESTORE, INVOKE APPLICATION: . VIEW_STATE, sumbit formB, .

JSF 2? - ?

maven GitHub: https://github.com/nithril/jsf-multiple-form

!

+5
2

, , JavaScript JSF. rendered f:ajax:

<h:form id="formA" binding="#{sessionBean.formA}">
  <h:commandButton value="formA" action="#{sessionBean.actionA}">
    <f:ajax render=":formB @form"/>
  </h:commandButton>
</h:form>

<h:form id="formB" binding="#{sessionBean.formB}">
  <h:commandButton value="formB" action="#{sessionBean.actionB}">
    <f:ajax render=":formA @form"/>
  </h:commandButton>
</h:form>

:

+4

, MyFaces 2.0.x/2.1.x, , script:

window.myfaces = window.myfaces || {};
myfaces.config = myfaces.config || {};
//set the config part
myfaces.config.no_portlet_env = true; 

JSF Ajax .

, , webapp, , .

+2

All Articles