0

Here is file structure of my JSF application.

enter image description here

User directory is secured & one needs to authenticate to see user/success.xhtml. user/success.xhtml has a button which is used to logout. That button submits form to following method.

public String logout(){
        HttpSession session = (HttpSession)FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        session.invalidate();
        return "index";
    }

Last line of above method is there to redirect user to index.xhtml, as index.xhtml is not in the same directory as user/success.xhtml so I am getting following error.

Unable to find matching navigation case with from-view-id '/user/success.xhtml' for action '#{AccContrl.logout()}' with outcome 'index'

How can I redirect to a file present up in the hierarchy? I tried return "/../index"; but it didn't work.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
user4913383
  • 181
  • 1
  • 1
  • 10
  • You could `response.sendRedirect(request.getContextPath() + "/index.xhtml");` – Kenneth Clark May 29 '15 at 04:32
  • This is the 2nd time that I had to remove unrelated version tags from your question. You threw in all the JSF version tags 1.2, 2.x and 2.2 in one and same question. This is abusing tags for the sake of getting attention. Don't do that anymore. Just always use [jsf]. If the question in turn concerns a specific JSF version, use **either** 1.2, **or** 2.x, **or** 2.2, not all three. – BalusC May 29 '15 at 05:34
  • Sorry @BalusC and thanks for answer. – user4913383 May 29 '15 at 16:20

1 Answers1

0

The navigation outcome represents a view ID. If it does not start with /, then it is interpreted relative to the current path. If it starts with /, then it is interpreted relative to the web root.

So, just use /index.

return "/index";

Unrelated to the concrete problem, you should be redirecting here, not navigating. Not only because you should always perform a redirect when you intend to naviage away after POST, but also because the invalidated session is still present in the current request/response, but only not anymore in the next one.

return "/index?faces-redirect=true";

See also:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452