4 Replies Latest reply on Sep 24, 2009 12:41 PM by juangon

    Seam, Richfaces and the Back-Button

    israel.bgf

      Hi, i'm having an strange issue with the back button. If i do a lot of post-backs using ajax components from richfaces, and go to another page (from a navigation rule/outcome), on that new page if i press the browser back-button the old page is "apparently" in a fresh state, but after the first post-back it retrieves its "true" state.

      The same thing doesn't happen using plain JSF components. I did a test case to show it:

      Ajax Page A

      <?xml version="1.0" encoding="ISO-8859-1" ?>
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:rich="http://richfaces.org/rich"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:s="http://jboss.com/products/seam/taglib"
       template="/resources/facelets/templates/base.xhtml">
      
       <a4j:outputPanel id="panel" ajaxRendered="true">
       #{pageA.bigString == '' ? 'Empty string!' : 'Its a BIG! string!'}
       </a4j:outputPanel>
      
       <br/>
      
       <a4j:form id="formulario">
       <h:outputText value="#{pageA.bigString}"/>
       <br/>
       <h:inputText value="#{pageA.value}"/>
       <a4j:commandButton value="Append" action="#{pageA.appendString}" reRender="formulario"/>
       </a4j:form>
      
       <br/>
      
       <a4j:form>
       <h:commandLink value="Go to page B" action="/pages/pageB.xhtml"/>
       </a4j:form>
      
      </ui:composition>
      


      Normal Page A
      <?xml version="1.0" encoding="ISO-8859-1" ?>
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:rich="http://richfaces.org/rich"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:s="http://jboss.com/products/seam/taglib"
       template="/resources/facelets/templates/base.xhtml">
      
       #{pageA.bigString == '' ? 'Empty string!' : 'Its a BIG! string!'}
      
       <br/>
      
       <h:form id="formulario">
       <h:outputText value="#{pageA.bigString}"/>
       <br/>
       <h:inputText value="#{pageA.value}"/>
       <h:commandButton value="Append" action="#{pageA.appendString}"/>
       </h:form>
      
       <br/>
      
       <h:form>
       <h:commandLink value="Go to page B" action="/pages/pageB.xhtml"/>
       </h:form>
      
      </ui:composition>
      


      Page B (Just to transit)
      <?xml version="1.0" encoding="ISO-8859-1" ?>
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:rich="http://richfaces.org/rich"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:s="http://jboss.com/products/seam/taglib"
       template="/resources/facelets/templates/base.xhtml">
      
       Page B
      
      </ui:composition>
      


      And the test backing bean:
      package br.com.techpeople.template.view;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      
      @Name("pageA")
      @Scope(ScopeType.PAGE)
      public class PageA {
      
       private String bigString = "";
      
       private String value;
      
       public void appendString(){
       bigString += value;
       }
      
       public void setValue(String value) {
       this.value = value;
       }
      
       public String getValue() {
       return value;
       }
      
       public void setBigString(String bigString) {
       this.bigString = bigString;
       }
      
       public String getBigString() {
       return bigString;
       }
      
      }
      


      The test is pretty simple, the backing bean just append the initial string. There is a different message if the bigString != null. After adding some strings, go to the next page, and after come back with the broser back-button. If you are using the "normal" page everthing works as expected, if you are using the ajax one the old page looks like a "new" one, but if you add a new string the page get the old state again.

      It's a pretty simple test to do, just remember to replace the template attribute.

      Is it a Seam bug, Richfaces bug, or is it an expected behavior? And how could i make my ajax application get the "normal" application behavior?

      Thks,

      Israel

        • 1. Re: Seam, Richfaces and the Back-Button
          nbelaevski

          Hi Israel,

          Can you please check this with "client" state saving method? Also does this reproduce in all browsers or some particular one?

          • 2. Re: Seam, Richfaces and the Back-Button
            israel.bgf

            My first posting was based in the Server side save stating. Using Firefox 3.0.7, it was as i told. With IE6, the ajax page after using the back-button is truly new, it don't even get back the old state after the first submit (even with the normal page too).

            With the client side enabled, firefox back-button don't get the state restored after the first submit (like the IE did with the ajax page using the server-side mode). The normal page worked as expected.

            The IE with client side did something really weird. The ajax page worked the same as the firefox did, but the normal page throw the following exception when trying to submit the form.

            java.io.IOException: Not in GZIP format

            Well, maybe my testing was not very accurate but I did my best. :)

            And for now I think that something strange is going on. First i thought that it could be the page-scope, but the symptom happens with the Session scope too.

            Any idea nbelaevski? Should it be posted in the JIRA?

            Thks in advance,

            Israel

            • 3. Re: Seam, Richfaces and the Back-Button
              israel.bgf

              I Forgot to say, i'm using Seam 2.1.1 too with Jboss 4.2.3

              • 4. Re: Seam, Richfaces and the Back-Button
                juangon

                I didn't have any problem with the browser back button with client state saving.