Reply To: Get view-id from arbitrary pretty-url

Splash Forums Rewrite Users Get view-id from arbitrary pretty-url Reply To: Get view-id from arbitrary pretty-url


Ah, I see. I thought you were using PrettyFaces – With Rewrite you have a few options, but the one I’d recommend is something like this:

First you’ll need to add the JSF integration module: rewrite-integration-faces

If you to return to previous page, you could record it (create a bean that records the current page (and last page)). Then navigate to the last page stored in that bean.

.perform(PhaseOperation.enqueue(new HttpOperation() {
   public void perform(HttpServletRewrite event, EvaluationContext context) {
      event.getRequest().getSession().setAttribute("LAST_PAGE", event.getRequest().getSession().getAttribute("CURRENT_PAGE"))
      event.getRequest().getSession().setAttribute("CURRENT_PAGE", FacesContext.getCurrentInstance().getViewRoot().getViewId());

If you want to do the above in a more JSF neutral way, then you could do the same thing in a JSF PhaseListener where you could save the value in a bean, instead of directly in the session map. If you are using JSF 2.2, you might even be able to inject the bean directly into the PhaseListener.

Once you’ve saved the last viewId, you can just reference that new variable in any page using EL:

<h:link value="Go back to previous page" outcome="#{sessionScope.LAST_PAGE}" />