Unable to find matching navigation case with from-view-id '/pages/index.xhtml'

jsf, navigation, view

Solution

You should not include the context path `/ui` nor the `FacesServlet` mapping `/faces` in the navigation case outcome. It should just represent the sole view ID, which is basically just the path to the physical view file absolute to the webcontent root or relative to the current view ID.

So, absolute (starting with `/`) to the webcontent root:

/pages/home.xhtml

Or relative (not starting with `/`) to the current view ID (assuming that you're in `/pages/index.xhtml`):

home.xhtml

Do note that dot-slash `./` and double-dot-slash `../` notations are not supported.

Or even without file extension; JSF will imply the Facelets default suffix which defaults to `.xhtml` and is configureable by `javax.faces.DEFAULT_SUFFIX` context parameter:

/pages/home
home

It makes after all also sense if you realize that the context path `/ui` and the `FacesServlet` mapping `/faces/*` are not controllable from inside the webapp on! If they ever change externally, then you'd theoretically need to change all navigation case outcomes in the entire codebase and rebuild the webapp. This would not make any sense. JSF takes thus already care of them for you.

See also:

- How to navigate in JSF? How to make URL reflect current page (and not previous one)

- Difference between h:button and h:commandButton

- When should I use h:outputLink instead of h:commandLink?

- What URL to use to link / navigate to other JSF pages

Problem

I am having trouble navigating between my JSF pages. Most of my navigation happens when you click a command button. The action of the command button returns a string. My log in page is my welcome page. Here it is in my web.xml: ``` <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>faces/pages/index.xhtml</welcome-file> </welcome-file-list> ``` In my browser's address bar, the page appears as: ``` http://localhost:8080/ui/faces/pages/index.xhtml ``` Once authentication happens, the function returns this String: ``` "/ui/faces/pages/home.xhtml" ``` The file I want to navigate to is located at: ``` pages/home.xhtml ``` However when navigation is supposed to happen, I get this error: Unable to find matching navigation case with from-view-id '/pages/index.xhtml' for action '#{indexPageController.login()}' with outcome '/ui/faces/pages/home.xhtml' Can anyone help me understand the relative path I need to correctly navigate to the page?

Original source

Related problems