1

My web application includes 3 pages:

  1. index.xhtml
  2. welcome.xhtml
  3. nextround.xhtml

I have two javaBean classes:

1.webTimeBean 2.userBean

the webtimeBean class is @ApplicationScoped. the userBean class is @SessionScoped. I also have class for SQL requests and User class for user information.

I have a navigation issue. After the user login (index.xhtml) the welcome page loads correctly with data from database. Then the user can click on a next round link but instead to navigate to nextround.xjtml the application send him back to the index.xhtml page.

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"/>
    <h:head>
        <title>Web TIme :  A simple example Title</title>
        <meta http-equiv="refresh" content="60"/>
    </h:head>
    <h:body>
        <div class="w3-container w3-light-grey w3-border">
        <p>Today : #{webTimeBean.time}</p>
        </div>    
        <h:form>          
                <br></br>
                <h:inputText  value="#{userBean.email}" class="w3-input" /> 

                <h:inputText  value="#{userBean.password}" class="w3-input" />

                <h:commandButton  value="Log In" class="w3-btn-block w3-teal" action="#{userBean.verifyLogin()}"   />
        </h:form>   
    </h:body>
</html>

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"/>
    <h:head>
        <title>Goalim Game </title>
        <meta http-equiv="refresh" content="300"/>
    </h:head>
    <h:body>

        <div class="w3-container w3-light-grey w3-border">
        <p>Today : #{webTimeBean.time}</p>
        </div>     


        <table class="w3-table w3-bordered w3-striped">
       <tr>
            <th>User Name</th>
            <th>Score</th>
      </tr>
         <ui:repeat var="elem" value="#{userBean.tblScore}" >
        <tr>
            <td>
                <h:outputText value="#{elem.userName}" />
            </td>
            <td>
                <h:outputText value="#{elem.totalPoints}" />
            </td>
                </tr>
            </ui:repeat>
        </table>
        <form>
            <h:commandButton  value="Next Round" class="w3-btn-block w3-teal" action="/nextround.xhtml"   /> 
        </form>
    </h:body>

</html>

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core" 
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"/>
    <h:head>
        <title>Web TIme :  A simple example Title</title>
        <meta http-equiv="refresh" content="60"/>
    </h:head>
    <h:body>
        <div class="w3-container w3-light-grey w3-border">
        <p>Today : #{webTimeBean.time}</p>
        <p>Hello : #{userBean.userName}</p>
        </div>    

    </h:body>
</html>

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <session-config>
        <session-timeout>
            30
        </session-timeout> 
    </session-config>
    <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>/faces/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
    <resource-ref>
        <description>postgress database</description>
        <res-ref-name>jdbc/postgres</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
</web-app>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
S.P
  • 11
  • 3
  • 1
    In general, use `h:form` instead of `form` while you're using JSF. Otherwise, JSF won't interact properly with the managed bean. On the other hand, if you want to perform plain navigation with a button, use `h:button` instead of `h:comandButton`. Have a look at [this](http://stackoverflow.com/a/15035600/1199132). – Aritz May 17 '16 at 08:44
  • Thanks BalusC its work now !! – S.P May 17 '16 at 11:44

0 Answers0