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

    Seam, Richfaces and the Back-Button

    Israel Fonseca Apprentice

      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