-
1. Re: keeping track on previous page viewed
kipod Sep 4, 2009 2:22 AM (in response to kevcpu411)I would also like to know the answer to your question.
I have a products search page with page parameters. After the user searches, and clicks on a product, he is taken to that product's details page.
I would like to offer the user a
back
button that will redirect him back to the search page WITH the previously entered search parameters showing.Actually - the user can reach the product details page from many locations in the app, so where ever he came from I want to go back there and show whatever state was present before (the
state
was the previous page's URL parameters)From Dan Allen's Seam-in-Action book, I see anonymous page parameters may help, such as
<page id="/productDetails.xhtml"> <param name="productId" value="#{productHome.id}" converterId="javax.faces.Long" /> <param name="returnTo"/> </page>
One thing I don't get from the book, and I guess it is implied there is:
When we have a link to the productDetails page, such as:
<s:link id="productName" value="#{_prd.name}" view="/productDetails.xhtml"> <f:param name="productId" value="#{_prd.id}"/> </s:link>
We also have to manually specify an f:param for the
returnTo
???
Meaning, if I really wanna go back to the search page the user was on, I need to specify ALL the search page parameters in a link that actually leads to the product details page ?? -
2. Re: keeping track on previous page viewed
swd847 Sep 4, 2009 4:27 AM (in response to kevcpu411)I have a solution that works within conversations that keeps track of the order that pages were viewed in the conversation:
pages.xml
<page action="#{pageViewStack.push}" login-required="true" view-id="/app/*"> <page view-id="/parent.xhtml"> <action execute="#{pageViewStack.pop}" /> </page>
PageViewStack:
@Name("pageViewStack") @Scope(ScopeType.CONVERSATION) @AutoCreate public class PageViewStack implements Serializable { public PageViewStack() { views = new Stack<String>(); } public void push() { String a = FacesContext.getCurrentInstance().getViewRoot().getViewId(); if (a == null) { return; } if (views.empty() || !views.peek().equals(a)) { views.push(a); } } /* * This pops the top item and then returns the next item This is because the * top item is always the active page, and we will be trying to move the the * active pages parent */ public String pop() { if (views.size() > 1) { views.pop(); } if (views.size() > 0) return views.peek(); return ""; } Stack<String> views; public int getCount() { return views.size(); } @Override public String toString() { StringBuilder db = new StringBuilder(); for (String s : views) { db.append(s + ":"); } return db.toString(); } }
To go back in the conversation I just redirect to /parent.xhtml.
This may not be what you are after if you are not using conversations.