title: JSF commandButton does not navigate to its action method's resulting page
body: <p><b>The goal:</b> The user enters in an email address. The submit button's action method checks for any existing emails in the database that are the same as the one entered. <br/><br/>
  If there is a duplicate then the registration.xhtml page reloads. <br/><br/>
  If there isn't a duplicate, then the userHome.xhtml page loads.</p>
  
  <p><b>The issue:</b> nothing happens when the submit button is clicked.</p>
  
  <p>I do not receive any errors in the console, so I'm thinking it has to be some misplaced logic.</p>
  
  <p><b>Side Note:</b>There is an index.xhtml and web.xml page that I didn't include. Didn't think it was necessary to solve the problem. If you need them, then I will be glad to provide them.</p>
  
  <p>registration.xhtml</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; 
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://java.sun.com/jsf/html"
        xmlns:c="http://java.sun.com/jsp/jstl/core"&gt; 
  
  &lt;h:head&gt;&lt;/h:head&gt; 
  &lt;body&gt; 
  
      &lt;h1&gt;Welcome to the Registration Page&lt;/h1&gt;
  
      &lt;h:form enctype="multipart/form-data"&gt;
  
          &lt;p&gt;Username:&lt;/p&gt;&lt;h:inputText value="#{user.name}" /&gt;
          &lt;p&gt;Email Address:&lt;/p&gt;&lt;h:inputText value="#{user.email}"/&gt;
          &lt;p&gt;Email Confirmation:&lt;/p&gt;&lt;h:inputText value="#{user.emailConf}"/&gt;
          &lt;p&gt;Password:&lt;/p&gt;&lt;h:inputText value="#{user.password}"/&gt;
          &lt;p&gt;Password Confirmation:&lt;/p&gt;&lt;h:inputText value="#{user.passwordConf}"/&gt;
          &lt;p&gt;Gender:&lt;/p&gt;&lt;h:selectOneRadio id ="genderSelection" value="#{user.gender}"&gt;
                  &lt;f:selectItem id="male" itemLabel="Male" itemValue="male" /&gt;
                  &lt;f:selectItem id="female" itemLabel="Female" itemValue="female" /&gt;
              &lt;/h:selectOneRadio&gt;
          &lt;p&gt;Birthday yy&lt;/p&gt;&lt;h:inputText value="#{user.age}"/&gt;
  
          &lt;h:commandButton action="#{user.getEmailDuplicateResults}" value="Submit"/&gt;
  
      &lt;/h:form&gt;
  
  &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>userHome.xhtml</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; 
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"&gt; 
  
  &lt;h:head&gt;&lt;/h:head&gt; 
  &lt;body&gt; 
  
      &lt;h:message title="Welcome to the userHome page"/&gt;
      &lt;h1&gt;Welcome to the userHome page2&lt;/h1&gt;
  
  &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>faces-config.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;faces-config 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-facesconfig_2_2.xsd"
      version="2.2"&gt;
  
      &lt;navigation-rule&gt;
  
          &lt;from-view-id&gt;*&lt;/from-view-id&gt;
          &lt;navigation-case&gt;
              &lt;from-action&gt;#{navigationClass.goToUserHome}&lt;/from-action&gt;
              &lt;from-outcome&gt;index&lt;/from-outcome&gt;
              &lt;to-view-id&gt;/userHome.xhtml&lt;/to-view-id&gt;
              &lt;redirect /&gt;
          &lt;/navigation-case&gt;
  
          &lt;navigation-case&gt;
              &lt;from-action&gt;#{navigationClass.goToRegistration}&lt;/from-action&gt;
              &lt;from-outcome&gt;index&lt;/from-outcome&gt;
              &lt;to-view-id&gt;/registration.xhtml&lt;/to-view-id&gt;
              &lt;redirect /&gt;
          &lt;/navigation-case&gt;
  
          &lt;navigation-case&gt;
              &lt;from-action&gt;#{user.getEmailDuplicateResults}&lt;/from-action&gt;
              &lt;from-outcome&gt;registration&lt;/from-outcome&gt;
              &lt;to-view-id&gt;/registration.xhtml&lt;/to-view-id&gt;
              &lt;redirect /&gt;
          &lt;/navigation-case&gt;
  
          &lt;navigation-case&gt;
              &lt;from-action&gt;#{user.getEmailDuplicateResults}&lt;/from-action&gt;
              &lt;from-outcome&gt;userHome&lt;/from-outcome&gt;
              &lt;to-view-id&gt;/userHome.xhtml&lt;/to-view-id&gt;
              &lt;redirect /&gt;
          &lt;/navigation-case&gt;
  
      &lt;/navigation-rule&gt;
  
      &lt;managed-bean&gt;
          &lt;managed-bean-name&gt;user&lt;/managed-bean-name&gt;
          &lt;managed-bean-class&gt;registrationView.User&lt;/managed-bean-class&gt;
          &lt;managed-bean-scope&gt;session&lt;/managed-bean-scope&gt;
      &lt;/managed-bean&gt;
  
  &lt;/faces-config&gt;
  </code></pre>
  
  <p>User.java</p>
  
  <pre><code>package registrationView;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.RequestScoped;
  
  @ManagedBean(name = "user")
  @RequestScoped
  public class User
  {
  
      private String name;
      private String email;
      private String emailConf;
      private String emailDatabaseTest;
      private String password;
      private String passwordConf;
      private String gender;
      private String age;
      private byte[] profileImage;
      private boolean isValidEmail = false;
  
      public String getName()
      {
          return name;
      }
  
      public void setName(String name)
      {
          this.name = name;
      }
  
      public String getEmail()
      {
          return email;
      }
  
      public void setEmail(String email)
      {
          this.email = email;
      }
  
      public String getEmailConf()
      {
          return emailConf;
      }
  
      public void setEmailConf(String emailConf)
      {
          this.emailConf = emailConf;
      }
  
      public String getPassword()
      {
          return password;
      }
  
      public void setPassword(String password)
      {
          this.password = password;
      }
  
      public String getPasswordConf()
      {
          return passwordConf;
      }
  
      public void setPasswordConf(String passwordConf)
      {
          this.passwordConf = passwordConf;
      }
  
      public String getGender()
      {
          return gender;
      }
  
      public void setGender(String gender)
      {
          this.gender = gender;
      }
  
      public String getAge()
      {
          return age;
      }
  
      public void setAge(String age)
      {
          this.age = age;
      }
  
      public byte[] getProfileImage()
      {
          return profileImage;
      }
  
      public void setProfileImage(byte[] profileImage)
      {
          this.profileImage = profileImage;
      }
  
      public boolean getValidEmail()
      {
  
          return isValidEmail;
      }
  
      public void setValidEmail(boolean valid)
      {
  
          this.isValidEmail = valid;
      }
  
      public String getEmailDuplicateResults()
      {
          checkForDuplicates();
  
          if (getValidEmail() == true)
          {
              return "userHome";
          } else
          {
              return "registration";
          }
      }
  
      public void checkForDuplicates()
      {
          // Create connection
          try
          {
              // Load driver
              Class.forName("com.mysql.jdbc.Driver");
              // Connect to the database
              Connection connection = DriverManager
                      .getConnection("jdbc:mysql://localhost/userProfile?user=root&amp;password=weston");
              // Set autocommit to false to manage it by hand
              connection.setAutoCommit(false);
  
              // Create the prepared statement object
              PreparedStatement statement = connection
                      .prepareStatement("SELECT * FROM userInfo WHERE email ='"
                              + getEmail() + "';");
  
              // assigning the query to a result set
              ResultSet rs = statement.executeQuery();
  
              // testing result set made from queries for text or if it is empty
              while (rs.next())
              {
  
                  emailDatabaseTest = rs.getString("email");
  
                  if (emailDatabaseTest.isEmpty())
                  {
                      isValidEmail = true;
                      setValidEmail(isValidEmail);
                  } else
                  {
                      isValidEmail = false;
                      setValidEmail(isValidEmail);
                  }
              }
  
              rs.close();
  
              // Commit &amp; close
              connection.commit();
              connection.close();
  
          }
  
          catch (Exception e)
          {
              e.printStackTrace();
  
              // create message for unsuccessful loading
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>NavigationClass.java</p>
  
  <pre><code>package nav;
  
  import java.io.Serializable;
  
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.RequestScoped;
  
  @ManagedBean(name = "navigationClass", eager = true)
  @RequestScoped
  public class NavigationClass implements Serializable
  {
  
      private static final long serialVersionUID = 1L;
  
      public String goToUserHome()
      {
          return "userHome";
      }
  
      public String goToRegistration()
      {
          return "registration";
      }
  
  }
  </code></pre>