I’m doing a site which has a “register” link on every page, to allow the user to register at any time.
When the user clicks this link they are taken to a registration form and allowed to register.
I would like the “success” result of the commandButton on the registration form to return the user to their previous page.
I can’t figure out a nice way to do it in JSF. My current plan is to pass the current viewId into the registration page, like this:
<h:link outcome="signup?from=#{facesContext.viewRoot.viewId}">
But I really don’t think that’s the best way. Any suggestions?
It is maybe not the “best” way, but it is definitely the “easiest” way.
I’m not sure why it is not the “best”. Is it because of the
frombeing visible in the URL as request parameter? Well, you could always make it a POST request with a<h:commandLink>and pass the parameter as<f:param>(which is also possible (and recommended!) on<h:link>by the way) and then store it in a view or maybe session scoped bean. A POST link to a signup page is only less user and SEO friendly, but it’s more robust as to tracking because one could then not bookmark or share the page URL with thefromparameter inside which would give unexpected results after someone else signs in based on a bookmarked or shared link.Anyway, the “best” depends on the functional requirement and the (dis)advantages of all possible solutions. You’ve just to outweigh the one or the other to satisfy the functional requirement the best.