This content has been marked as final.
Show 6 replies
-
1. Re: Last Page Visited
israel.bgf Aug 13, 2009 9:40 PM (in response to israel.bgf)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 Aug 14, 2009 12:13 AM (in response to israel.bgf)Hi,
you could try registering a listener to org.jboss.seam.afterPhase or org.jboss.seam.beforePhase events I guess.
Cheer,
Ben
-
3. Re: Last Page Visited
israel.bgf Aug 14, 2009 4:02 PM (in response to israel.bgf)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;
@Name("viewHistory")
@AutoCreate
@BypassInterceptors
@Scope(ScopeType.SESSION)
public class ViewHistory {
private LinkedList<String> history;
@Create
public void init(){
history = new LinkedList<String>();
}
public void addCurrentViewId(){
String currentViewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
if(history.size() != 0 && history.getLast().equals(currentViewId)){
return;
}
if(history.size() == 2){
history.removeFirst();
}
history.add(currentViewId);
}
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"/>
</page>
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,
Israel
(Seam 2.1.1) -
4. Re: Last Page Visited
ben_utzer Aug 17, 2009 1:32 PM (in response to israel.bgf)Hi Israel,
your code works for me if I correct the spelling error in
#{viewHistory.addCurentViewId}
.My suggestion was to use something like:
@Observer("org.jboss.seam.beforePhase") public void before(PhaseEvent event) { if (event.getPhaseId().equals(PhaseId.RENDER_RESPONSE)) { //do your history thing } }
-
5. Re: Last Page Visited
ralf Aug 17, 2009 2:53 PM (in response to israel.bgf)Hi,
there is a component, which name is
redirect
. There is a functionality which is namedcaptureCurrentView
andreturnToCapturedView
.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.bgf Aug 17, 2009 7:47 PM (in response to israel.bgf)Thanks for the replies, i will give a look in both tips. :)