javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-2199

Ajax rendering of content which contains another form causes its view state to disappear

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: 2.1.3
    • Fix Version/s: None
    • Component/s: ajax
    • Labels:
      None
    • Environment:

      Mojarra 2.1.3, Tomcat 7.0.19, Glassfish 3.1.1, Win7 x64.

      Description

      Background:

      Consider the following example:

      <h:panelGroup id="firstPanel">
          <h:form id="firstForm">
              <h:outputLabel for="input" value="First form input" />
              <h:inputText id="input" value="#{bean1.input}" required="true" />
              <h:commandButton value="Submit form" action="#{bean1.submit}">
                  <f:ajax execute="@form" render="@form :secondPanel :messages" />
              </h:commandButton>
              <h:message for="input" />
          </h:form>
      </h:panelGroup>
      <h:panelGroup id="secondPanel">
          <h:form id="secondForm">
              <h:outputLabel for="input" value="Second form input" />
              <h:inputText id="input" value="#{bean2.input}" required="true" />
              <h:commandButton value="Submit other form" action="#{bean2.submit}">
                  <f:ajax execute="@form" render="@form :firstPanel :messages" />
              </h:commandButton>
              <h:message for="input" />
          </h:form>
      </h:panelGroup>
      <h:messages id="messages" globalOnly="true" layout="table" />
      

      When you submit one of the two forms, the parent component of the other form will be re-rendered. However, the jsf.js does not append the view state as a hidden field of the other form. When you submit the other form, nothing will be processed/invoked. In the above example, a second click will get it to work, however there are cases wherein the button never works and I think this is related to the same root issue.

      The workaround is to explicitly add the ID of the other form to the render id.

      <h:panelGroup id="firstPanel">
          <h:form id="firstForm">
              <h:outputLabel for="input" value="First form input" />
              <h:inputText id="input" value="#{bean1.input}" required="true" />
              <h:commandButton value="Submit form" action="#{bean1.submit}">
                  <f:ajax execute="@form" render="@form :secondPanel :secondForm :messages" />
              </h:commandButton>
              <h:message for="input" />
          </h:form>
      </h:panelGroup>
      <h:panelGroup id="secondPanel">
          <h:form id="secondForm">
              <h:outputLabel for="input" value="Second form input" />
              <h:inputText id="input" value="#{bean2.input}" required="true" />
              <h:commandButton value="Submit other form" action="#{bean2.submit}">
                  <f:ajax execute="@form" render="@form :firstPanel :firstForm :messages" />
              </h:commandButton>
              <h:message for="input" />
          </h:form>
      </h:panelGroup>
      <h:messages id="messages" globalOnly="true" layout="table" />
      

      This way jsf.js will add the view state hidden field to the other form. The same problem exposes in both Mojarra 2.1.3 and MyFaces 2.1.1 by the way.

        Activity

        Hide
        frederickkaempfer added a comment -

        Is this a duplicate of the following spec issue:

        http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-790 ?

        Show
        frederickkaempfer added a comment - Is this a duplicate of the following spec issue: http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-790 ?
        Hide
        rogerk added a comment -
        Show
        rogerk added a comment - Duplicate of : http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-790

          People

          • Assignee:
            rogerk
            Reporter:
            balusc
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: