2

I made a simple application named Sport. When I test it, the home page (index.xhtml) displays correctly, and the URL is:
http://localhost:8080/Sport

When I click an item in the navigation menu, for example Teams, the requested page (teams.xhtml) displays correctly, but the URL looks like this:
http://localhost:8080/Sport/index.html;jsessionid=C9B3379254D6E21A6A2EA90775710108

After that, I click another item, for example Stadiums. The page stadiums.xhtml displays, but the URL is:
http://localhost:8080/Sport/teams.xhtml

This behaviour goes on. It looks like the URL is always one step behind the actual page.

menu.xhtml:

...
<h:commandLink value="#{msgs.home}" action="home" />
<h:commandLink value="#{msgs.teams}" action="teams" />
<h:commandLink value="#{msgs.stadiums}" action="stadiums" />
...

faces-config.xml:

...
<navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
        <from-outcome>home</from-outcome>
        <to-view-id>/index.xhtml</to-view-id>
    </navigation-case>
    <redirect/>
</navigation-rule>
<navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
        <from-outcome>stadiums</from-outcome>
        <to-view-id>/stadium.xhtml</to-view-id>
    </navigation-case>
    <redirect/>
</navigation-rule>
<navigation-rule>
    <from-view-id>*</from-view-id>
    <navigation-case>
        <from-outcome>teams</from-outcome>
        <to-view-id>/team.xhtml</to-view-id>
    </navigation-case>
    <redirect/>
</navigation-rule>
...

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <!-- Use Documents Saved as *.xhtml -->
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>
    <context-param>
      <param-name>javax.faces.CONFIG_FILES</param-name>
      <param-value>/WEB-INF/faces-config.xml</param-value>
   </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
        <!--<url-pattern>/faces/*</url-pattern>-->
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>    
</web-app>

I'm using JSF2.2 library (in NetBeans 7.4).
Any ideas?

vtomic85
  • 590
  • 1
  • 11
  • 32
  • Duplicate of [What is the difference between redirect and navigation/forward and when to use what?](http://stackoverflow.com/questions/11277366/what-is-the-difference-between-redirect-and-navigation-forward-and-when-to-use-w) and [How to make URL reflect current page and not the previous one?](http://stackoverflow.com/questions/15521451/how-to-make-url-reflect-the-current-page-and-not-the-previous-one/15523045#15523045) and [When should I use h:outputLink instead of h:commandLink?](http://stackoverflow.com/questions/4317684/when-should-i-use-houtputlink-instead-of-hcommandlink) – BalusC May 01 '14 at 20:32
  • 3
    By the way, please stop reading JSF 1.x targeted books/tutorials/resources. Those page-to-page navigation actions by command links and those navigation rules are not JSF 2.x anymore. See also [Communication in JSF 2.0](http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html) for best practices and such on this all. – BalusC May 01 '14 at 20:34
  • Thanks for your replies, BalusC. Pretty useful, but I managed to solve the problem using the link that GauravS posted below. – vtomic85 May 01 '14 at 21:31

1 Answers1

2

It looks like it's generating the wrong URL, however that is the default JSF action on navigation.

The following page has a very good examples on Page Forward vs Page Redirect in JSF.

http://www.mkyong.com/jsf2/jsf-page-forward-vs-page-redirect/

GauravS
  • 81
  • 1
  • 6