Question

I have a index.xhtml file in WebContent folder which is my main page. There I can send some data to a controller which will then redirect to an list.xhtml file located in WEB-INF/jsf/. list.xhtml is in WEB-INF/jsf/ so it couldn't be accessed without sending the data from the index page.

Anyway the redirect from index.xhtml to list.xhtml works perfectly ( <p:commandButton /> with an action to a controller ). The problem is navigating back from list.xhtml to index.xhtml. No matter what I do it doesn't seem to work.

So far I've tried:

<h:button value="Go Back" outcome="index.xhtml" /> - button is greyed out with the message This button is disabled because a navigation case could not be matched. Assuming that's because it's searching for index.xhtml in WEB-INF/jsf/

<h:button value="Go Back" outcome="../../index.xhtml" /> - same result as above

<p:commandButton value="Go Back" action="#{listController.goBack}" /> and action="#{goBackController.goBack}" - with goBack() method returning the same thing that was in outcome values in previous examples

If anyone could push me in the right direction that'd be much appreciated.

Also I am aware that webpages shouldn't really be in WEB-INF but I don't know how else to hide the list.xhtml page.

Was it helpful?

Solution

There are 2 things about outcome that you need to know:

  1. You cannot use a full page name with .xhtml as a value for outcome. For example, if the page name is Example.xhtml, the proper way is outcome="Example".
  2. Suppose at the moment you're at this page http://yourdomain.com/app/folder/Page1.xhtml, if you click on a button with outcome="Page2", you will arrive at http://yourdomain.com/app/folder/Page2.xhtml. You cannot use ../ in the outcome to navigate to the parent folder.

Try this:

<p:button value="Go back" href="../../index.xhtml" />

If it doesn't work, put an absolute path in the href should do the job.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top