0

I would like to have this navigation case work on any page, but I can't find how to generically reference the origin page on a navigation rule in the tag to-view-id:

    <navigation-rule>
        <from-view-id>/public/login/login.xhtml</from-view-id>
        <navigation-case>
            <from-action>#{LoginBean.login}</from-action>
            <from-outcome>success</from-outcome>
            <to-view-id>/public/login/login.xhtml</to-view-id>
            <redirect />
        </navigation-case>
    </navigation-rule>

The case translates to: after proper login on page login.xhtml, redirect to self, that is, login.xhtml

I would like to have something like:

   <navigation-rule>
        <navigation-case>
            <from-view-id>*</from-view-id>
            <from-action>#{LoginBean.login}</from-action>
            <from-outcome>success</from-outcome>
            <to-view-id>self</to-view-id>
            <redirect />
        </navigation-case>
    </navigation-rule>

So if, for example, the login action was triggered from a page with view-id mypage.xhtml, I get <to-view-id>mypage.xhtml</to-view-id> without defining a particular navigation rule for <from-view-id>mypage.xhtml</from-view-id>

In other words, I'd like to know if there is an equivalent of <from-view-id>*</from-view-id> for the tag <to-view-id>

My current solution is returning an outcome of null instead of "success" on LoginBean.login action success when a parameter redirectToSelfAfterLogin is defined, which keeps me in the view I called the action from.

(I also thought of having a redirectToAfterLogin parameter and redirect to self by default returning null on success instead, but this is more practical for my current scenario)

Anyway, I would like to know if there could also be a faces-config navigation rule based solution.

NotGaeL
  • 8,344
  • 5
  • 40
  • 70

1 Answers1

2

You really needn't set a navigation case, if your intention is to just redirect to the originally requested page. The originally requested page is available as a variable in the request object, with the key javax.servlet.forward.request_uri which is easily retrievable in your login bean using

   FacesContext ctxt = FacesContext.getCurrentInstance();
   String originalURI = ctxt.getExternalContext().getRequestMap("javax.servlet.forward.request_uri"); //the original uri

If you really prefer a navigation-config-based setting, you can directly access the requestScope object in there with

   <to-view-id>#{requestScope['javax.servlet.forward.request_uri']}</to-view-id>

But I won't recommend that; it's just ugly. That's decidedly page-level stuff you're burying in a config file

kolossus
  • 20,559
  • 3
  • 52
  • 104
  • Thanks for the advice. The reason I want a faces-config redirection is the previous two navigation-cases defined by the dev-team for outcome success (and error) on login action were there, so just adding a third one and keep every case handled on the same place makes sense. Simply returning null as outcome worked too, but render condition on `` would not get reevaluated (since the view does not change). I ended up redirecting to `FacesContext.getCurrentInstance().getRootView().getViewId()+"?faces-redirect=true"` which gets me the same result... – NotGaeL Nov 22 '14 at 14:48
  • ..although you solution seems to be a better fit. – NotGaeL Nov 22 '14 at 15:00