6 Replies Latest reply on Aug 17, 2009 7:47 PM by Israel Fonseca

    Last Page Visited

    Israel Fonseca Apprentice

      How to know the last page that the user visited?


      I'm, in the view /view1.xhtml and go to the /view2.xhtml, now in the view 2 i want some method to return the /view1.xhtml, is there any built-in function to achieve this?

        • 1. Re: Last Page Visited
          Israel Fonseca Apprentice

          And btw, is there any Seam/JSF event that can detect if the user changed the current page? Maybe something with a phase listener to achieve this..

          • 2. Re: Last Page Visited
            Ben Utzer Newbie


            you could try registering a listener to org.jboss.seam.afterPhase or org.jboss.seam.beforePhase events I guess.



            • 3. Re: Last Page Visited
              Israel Fonseca Apprentice
              But how could i know if the view id is changing with these events? Anyway, id did a component to solve this needing:

              package br.com.techpeople.nexxcard.utility;

              import java.util.LinkedList;

              import javax.faces.context.FacesContext;

              import org.jboss.seam.Component;
              import org.jboss.seam.ScopeType;
              import org.jboss.seam.annotations.AutoCreate;
              import org.jboss.seam.annotations.Create;
              import org.jboss.seam.annotations.Name;
              import org.jboss.seam.annotations.Scope;
              import org.jboss.seam.annotations.intercept.BypassInterceptors;

              public class ViewHistory {

                      private LinkedList<String> history;
                      public void init(){
                              history = new LinkedList<String>();
                      public void addCurrentViewId(){
                              String currentViewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
                              if(history.size() != 0 && history.getLast().equals(currentViewId)){
                              if(history.size() == 2){
                      public String getLastViewId(){
                              if(history.size() == 0){
                                      return FacesContext.getCurrentInstance().getViewRoot().getViewId();
                              return history.getFirst();
                      public static ViewHistory instance(){
                              return (ViewHistory) Component.getInstance("viewHistory", ScopeType.SESSION);


              Just have to put it in action in the pages.xml to the view id matching /*. Example:

              <page view-id="/pages/*" login-required="true">
                   <action execute="#{viewHistory.addCurentViewId}" on-postback="false"/>

              the problem is... it is doing something strange, it's causing an endless redirect in my browser. Don't know why, maybe I did a mistake. Could someone just put this component, and test it for me?

              Thanks in advance,


              (Seam 2.1.1)
              • 4. Re: Last Page Visited
                Ben Utzer Newbie

                Hi Israel,

                your code works for me if I correct the spelling error in #{viewHistory.addCurentViewId}.

                My suggestion was to use something like:

                 public void before(PhaseEvent event) {
                    if (event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) {
                        //do your history thing

                • 5. Re: Last Page Visited
                  Ralf H. Newbie


                  there is a component, which name is redirect. There is a functionality which is named captureCurrentView and returnToCapturedView.


                  You can track method-calls and their behaviour in the pages.xml

                  I dont have an example, but i am sure, you will find something.

                  • 6. Re: Last Page Visited
                    Israel Fonseca Apprentice

                    Thanks for the replies, i will give a look in both tips. :)