title: JSF 2.0 navigation not working properly
body: <p>I am trying to get started with JSF 2.0. I am trying a basic navigation example and it's not working properly. </p>
  
  <p>The file structure is the following:</p>
  
  <p><img src="https://i.stack.imgur.com/aI7Pw.png" alt="enter image description here"></p>
  
  <p>I have configured the mapping in web.xml:</p>
  
  <pre><code>&lt;!-- Change to "Production" when you are ready to deploy --&gt;
  &lt;context-param&gt;
      &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
      &lt;param-value&gt;Development&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;!-- Welcome page --&gt;
  &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.xhtml&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  
  &lt;!-- JSF mapping --&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>And the index page has 2 buttons which take you to different pages when clicked</p>
  
  <p>The faces-config.xml file defines some navigation cases:</p>
  
  <pre><code>&lt;!-- Configuration of navigation rules --&gt;  
  &lt;navigation-rule&gt;
      &lt;from-view-id&gt;/index.xhtml&lt;/from-view-id&gt; 
      &lt;navigation-case&gt;
          &lt;from-outcome&gt;success&lt;/from-outcome&gt;
          &lt;to-view-id&gt;/pages/success.xhtml&lt;/to-view-id&gt;
      &lt;/navigation-case&gt;
       &lt;navigation-case&gt;
          &lt;from-outcome&gt;error&lt;/from-outcome&gt;
          &lt;to-view-id&gt;/pages/error.xhtml&lt;/to-view-id&gt;
      &lt;/navigation-case&gt;
  &lt;/navigation-rule&gt;
  </code></pre>
  
  <p>E.g. the following button should take you to the success page (/pages/success.xhtml):</p>
  
  <pre><code>&lt;p:commandButton id="addUser" value="Add" action="#{userMB.addUser}" ajax="false"/&gt;
  </code></pre>
  
  <p>I have debugged this an the return value of addUser is definitely "success".</p>
  
  <p>The page switches to success.xhtml because I see the content is changed, but the browser URL points to index.xhtml....</p>
  
  <p>At startup: URL is <strong>localhost:8080/PROJECT/</strong> with no index.xhtml probably because we configured it as the welcome file. When we hit the button above, the URL becomes <strong>localhost:8080/PROJECT/index.xhtml</strong></p>
  
  <p>I believe I have messed up something with the mappings or the relative paths. I have found some advice that the only mapping should be the one with *.xhtml but I did not really understand why and how to address multiple subfolders of pages.</p>
  
  <p>Any help is appreciated, thanks</p>