Login page With JSF

can anyone help me to read the database value and pass it to next page in jsf if it is success.

This is my code.

      <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <ui:composition 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"
template="/templates/template.xhtml"
xmlns:rich="http://richfaces.org/rich">

<ui:define name="body">
    <h:form>

        <rich:panel header="Employee Log In Page" style="width: 315px">
            <h:panelGrid columns="2">

                <h:outputText value="EmployeeId: " />

                <h:inputText id="employeeId" value="">

                    <f:validateLength minimum="30" maximum="30" />

                </h:inputText>

                <h:outputText id= "password" value="PassWord: " />

                <h:inputText value="">

                    <f:validateLength minimum="15" maximum="15" />
                </h:inputText>
                <h:commandButton action="#{ }" value="Log In" />
            </h:panelGrid>
        </rich:panel>
    </h:form>
</ui:define>
</ui:composition>

Connectivity.java

    import java.sql.DriverManager;
   import java.sql.ResultSet;
  import java.util.ArrayList;

  import antlr.collections.List;

   import com.model.UserDetails;
 import com.mysql.jdbc.Connection;
  import com.mysql.jdbc.Statement;


 public class Connectivity {

public static void main(String[] argv) {

    System.out.println("-------- MySQL JDBC Connection Testing ------------");

int i=0;

Connection con ;
Statement ps;
ResultSet rs;



  try
  {
  Class.forName("com.mysql.jdbc.Driver");
  con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/LeaveApp",
"root","root");

  ps = (Statement) con.createStatement();
  rs = ps.executeQuery("select * from Login");
  while(rs.next()){
  System.out.println(rs.getString(1));
  System.out.println(rs.getString(2));
  System.out.println(rs.getString(3));

  i++;

  }

  }
  catch (Exception e)
  {
  System.out.println("Error Data : " + e.getMessage());
  }
}  
}

UserDetails.java

       package com.model;

       public class UserDetails {
public int login_id;
public String user_name;
public String user_password;
public int getLogin_id() {
    return login_id;
}
public void setLogin_id(int login_id) {
    this.login_id = login_id;
}
public String getUser_name() {
    return user_name;
}
public void setUser_name(String user_name) {
    this.user_name = user_name;
}
public String getUser_password() {
    return user_password;
}
public void setUser_password(String user_password) {
    this.user_password = user_password;
}


}

i need to validate the login page.How to do it.

Answers


Set values and the action method in your view:

<h:outputText value="EmployeeId: " />
<h:inputText id="employeeId" value="#{userDetails.employeeId}">
   <f:validateLength minimum="30" maximum="30" />
</h:inputText>
<h:outputText id="password" value="PassWord: " />
<h:inputText value="#{userDetails.password}">
   <f:validateLength minimum="15" maximum="15" />
</h:inputText>
<h:commandButton action="#{userDetails.login}" value="Log In" />

And declare these fields and define this method in your backing bean :

private Integer employeeId;
private String password;

public String login() {      
   String result = null;
   boolean isValidUser = userDao.login(employeeId, password);  // verification user's data in db   
   if (isValidUser) {
      result = "success";
   } else { 
      result = "fail";
   }
   return result;
}

public Integer getImployeeId() {
   return employeeId;
}

public void setEmployeeId(Integer employeeId) {
   this.employeeId = employeeId;
}

public String getPassword() {
   return password;
}

public void setPassword(String password) {
   this.password = password;
}

Need Your Help

Why specify the database in the mongodb connection string if you aren't authenticating?

node.js mongodb

To connect to MongoDB, you need to use http://mongodb.github.io/node-mongodb-native/2.0/api/MongoClient.html#.connect.