returnToCapturedView returns to different conversation
v.lukoyanov Jul 28, 2009 9:24 AMHi.
I'm trying to implement return-to-previous-page-after-login feature. The problem I stuck with is when I'm returned to previous page previous conversation isn't restored.
More specifically:
On a /home.seam I have a search box.
home.xhtml
<rich:panel> <f:facet name="header">Quick find product:</f:facet> <h:form id="searchForm" > <h:inputText size="50" value="#{productSearchAction.queryString}" /> <h:commandButton value="Find" action="#{productSearchAction.search}"> </h:commandButton> </h:form> </rich:panel>
Bean:
@Name("productSearchAction") @Scope(ScopeType.CONVERSATION) public class ProductSearchAction { ... @SuppressWarnings("unchecked") @Begin(join = true) public String search() throws ParseException { org.apache.lucene.search.Query luceneQuery = new MultiFieldQueryParser(new String[] {"name", "model", "description"}, new StandardAnalyzer()).parse(_queryString); javax.persistence.Query query = _entityManager.createFullTextQuery(luceneQuery, Product.class); setResultList(query.getResultList()); return "search"; }
search.page.xml
<raise-event type="com.meshop.event.captureView" />
compoments.xml
<event type="org.jboss.seam.security.notLoggedIn"> <action execute="#{loginRedirector.captureCurrentView}" /> </event> <event type="com.meshop.event.captureView"> <action execute="#{loginRedirector.captureCurrentView}" /> </event> <event type="org.jboss.seam.security.postAuthenticate"> <action execute="#{loginRedirector.returnToCapturedView}" /> </event>
LoginRedirector.java
@Name("loginRedirector") @Scope(ScopeType.SESSION) @AutoCreate public class LoginRedirector { @In("redirect") private Redirect _redirect; @In("identity") private Identity _identity; private Redirect _savedRedirect; public void captureCurrentView() { if (_identity != null && !_identity.isLoggedIn()) { _savedRedirect = _redirect; _redirect.captureCurrentView(); } } public void returnToCapturedView() { if (_savedRedirect != null && _savedRedirect.getViewId() == null || !_savedRedirect.getViewId().contains("error.xhtml")) { _savedRedirect.returnToCapturedView(); } } }
When I enter query and hit 'Find' i'm redirected to search.seam. Then I press sign in button and enter login info. After that i'm redirected back to search, but cid is different (therefore no previous search results). On debug.seam i can see that the valid conversation is present.