Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the page change in JSF, but not the URL? [duplicate]

I have simple test web-application: First Page - index.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<html>
 <h:head>
    <title>Facelet Title</title>
 </h:head>
 <h:body>
    First page
    <h:form>
        <h:commandButton value="Go to Next page" action="next"/>
    </h:form>
 </h:body>
</html>

and Next Page - next.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<html>
<h:head>
    <title>Facelet Title</title>
 </h:head>
 <h:body>
    Next page
    <h:form>
        <h:commandButton value="Go to First page" action="index"/>
    </h:form>
 </h:body>
</html>

When I run my application i have that url on browser:

http://localhost:8080/Test/ 

and index.xhtml as first page.

Then when I click "Go to Next page" i have url

http://localhost:8080/Test/index.xhtml

and next.xhtml page. And when I click "Go to First page" page changes (to index.xhtml) but url its

http://localhost:8080/Test/next.xhtml

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app>
 <context-param>
     <param-name>javax.faces.PROJECT_STAGE</param-name>
     <param-value>Development</param-value>
 </context-param>
 <listener>
     <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
 </listener>
 <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>
 </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>

What should I do to make that the first page in my application has a URL,

http://localhost:8080/Test/index.xhtml 

rather than

http://localhost:8080/Test/

?

I use Tomcat (TomEE)/7.0.37

like image 708
kuba44 Avatar asked Sep 06 '13 11:09

kuba44


1 Answers

Though it's an old thread, if someone is still looking for it can try "?faces-redirect=true". Like:

<h:commandButton value="Go to Next page" action="next?faces-redirect=true"/>
like image 185
Gouranga Tarafder Avatar answered Nov 15 '22 21:11

Gouranga Tarafder