1 Replies - 1048 Views - Last Post: 10 July 2018 - 10:08 PM

#1 CrystalMeg   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 13-January 18

Managed bean class doesn't declare a public no-argument constructo

Posted 10 July 2018 - 03:14 PM

I'm trying to program signup.xhtml and login.xhtml wepgaes for my system but when I run them they give me an error that the Managed bean for my admin class for managed bean adminObj doesnt declare a public no-argument constructor. I do not understand where the problem is. Here is my admin class:
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "adminObj")
@SessionScoped

public class admin {
     public int id;
    public String username;
    public String password;
    public String email;
    public String CPassword;
    
    DBConnect db = new DBConnect();//db instance
    Connection myCon = db.myConnect(); //db connection instance
    HasherSha1 jk = new HasherSha1(); //hashing class instance
    
    
    public  admin(int anid ,String aname , String apassword , String anemail){
        this.id = anid;
        this.username = aname;
        this.password = apassword;
        this.email = anemail;
          
}

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

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

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
     public String getCPassword() {
        return CPassword;
    }

    public void setCPassword(String CPassword) {
        this.CPassword = CPassword;
    }
    public void clear(){
        setCPassword(null);
        setEmail(null);
        setUsername(null);
        setPassword(null);
    }
    
    public String login() throws SQLException{
         
    Statement statement = myCon.createStatement();
    
    String SQL = "SELECT email, password FROM admin WHERE email = '" + getEmail()
            + "' AND password = '" + jk.encryptPassword(getPassword()) + "';";

    ResultSet resultSet = statement.executeQuery(SQL);
    while (resultSet.next()) {
        if (getEmail().equals(resultSet.getString("email")) && jk.encryptPassword(getPassword()).equals(resultSet.getString("password"))) {
            return "home";
        } 
    }
    return "login";
    }
    
    public String saveUser() throws SQLException{
          Statement s = null;
         //creates an instance of the DBConnect class
         
         if(myCon!=null){
         System.out.println(myCon);
         s = myCon.createStatement();
         
                    String sql = "INSERT INTO admin "
                            + "(username,"
                            + "email,password,) "
                            + "VALUES ('" + getUsername() + "','"
                            + getEmail()+ "','"
                             + "'"+ jk.encryptPassword(getPassword()) +"')";
                    s.execute(sql);
                    clear();
                    
     }
    return "login";}
    
}



The signup.xhtml page:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
     <h:head>
        <title>Sign Up</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
         <link  rel="stylesheet" type="text/css" href="css/signup.css"/>
        
        <style type="text/css">
            body{
                background-size: cover;
                background-position: center;
                font-family: sans-serif;
                background-image: url("background.png");
            }
        </style>
    </h:head>
    <h:body>
          <div>
            <img src="img.png" class="avatar"/>
            <center><h1>SIGN UP</h1></center>
            
            <hr/><br/><br/><br/><br/>
            <h:form>
            <h:outputLabel>Username: </h:outputLabel>
            <h:inputText id="txtname" value="#{UserObj.username}" validatorMessage="Username is required..">
                <f:validateRequired/></h:inputText>
            <br/><br/>
            <h:outputLabel>Email: </h:outputLabel>
            <h:inputText id="txtemail" value="#{adminObj.email}" validatorMessage="Email is required..">
                <f:validateRequired/></h:inputText>
            <br/><br/>
            <h:outputLabel>Password: </h:outputLabel>
            <h:inputSecret id="txtpwd" value="#{adminObj.password}" validatorMessage="Password is required..">
                <f:validateRequired/></h:inputSecret>
            <br/><br/>
            <h:outputLabel>Confirm Password: </h:outputLabel>
            <h:inputSecret id="txtcpwd" value="#{adminObj.CPassword}" validatorMessage="Please Confirm Password..">
                <f:validateRequired/></h:inputSecret>
            <br/>
            <h:commandButton value="Save" action="#{adminObj.saveUser()}" class="btn btn-success btnWidth" />
            </h:form>
        </div>
    </h:body>
</html>



The login.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">
     <link href="./resources/css/mycss.css" rel="stylesheet" type="text/css"/> 
    <h:head>
        <title>Login</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
         <link  rel="stylesheet" type="text/css" href="css/loginstyle.css"/>
        
        <style type="text/css">
	body{
            background-size: cover;
            background-position: center;
            font-family: sans-serif;
            background-image: url("background.png");
            }
        </style>
    </h:head>
    <h:body>
        <div class="loginbox">
            <img src="img.png" class="avatar"/>
             <br/>
             <br/>
             <h1>LOGIN</h1>  
         
            <h:form>
                <br/>
                
            <h:outputLabel for="txtUsername">Username: </h:outputLabel>
            <h:inputText id="txtUsername" value="#{adminObj.username}" validatorMessage="Please Enter Username">
                <f:validateRequired/></h:inputText><br/><br/>
                
            <h:outputLabel for="txtPwd">Password:  </h:outputLabel>
            <h:inputSecret id="txtPwd" value="#{adminObj.password}" validatorMessage="Please Enter Password">
            <f:validateRequired/></h:inputSecret><br/><br/>
            
           <h:commandButton id="login" value="LOGIN" action="#{adminObj.login()}"></h:commandButton>
            <br/><br/>
            <h:link id="signup" value="Sign Up" outcome="signup.xhtml"></h:link>
            </h:form>
        </div>
    </h:body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: Managed bean class doesn't declare a public no-argument constructo

#2 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2995
  • View blog
  • Posts: 11,531
  • Joined: 03-December 12

Re: Managed bean class doesn't declare a public no-argument constructo

Posted 10 July 2018 - 10:08 PM

I don't understand how you don't see what the error message says. Please tell me what line you declare a public no-argument constructor.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1