I had asked myself a similar question last week, we are basically looking for a way to do History and History* (UI statechart stuff we talked about in the early days of Seam).
Well I've done it, but only by storing the outcome in the session context and then firing it when the login or register process is complete.
Surely this sort of process is what nested conversations are made for ?
Have you looked at how the issue tracker demo handles the login challenge? I think that is pretty elegant.
(It uses Conversation.redirect().)
Thanks, Gavin, that approach is much more elegant than my fudge. I'll engineer that in.
However, I'm a stage down the login process and have hit another issue; If the user has bookmarked a page e.g.
They can jump directly to this page without any login challenge. Admittedly they can't do much when they get there but it is a bit confusing.
I would rather they were forwarded to the login screen, but the @LoggedIn interceptor isn't fired & even if the interceptor was fired (e.g. via a factory or method call on the page) I wouldn't be able to specify an outcome for redirection.
I'm currently looking at the NavigationHandler to see if this will do the job. I'm new to JSF so I'm open to any better / alternative solutions.
Yes, this is because of the JSF lifecycle for non-faces requests (there is no action). I don't think you can solve this with a NavigationHandler - the NavigationHandler is only called to translate an action outcome to a viewid. When you hit main.seam directly, you already know the viewid.
I believe you *can* solve it with a PhaseListener, but you will need to do something like this:
UIViewRoot viewRoot = context.getApplication().getViewHandler() .createView( context, "login.jsp" ); context.setViewRoot(viewRoot);
Or, perhaps, something like this:
String url = context.getApplication().getViewHandler().getActionURL( context, "login.jsp" ); url = encodeConversationId(url); ExternalContext externalContext = context.getExternalContext(); externalContext.redirect( externalContext.encodeActionURL(url) ); context.responseComplete();
Note that I have not tried either thing.