jpa - Controller Bean not picking up the username -
i'm in grave problem this. of sudden working code has stopped working. have no clue ever why!!!! , worst of have deploy project today :( . don't know if right or not of started 2 days after adding primefaces in build path. can please direct me right direction. great help!
i have following configuration:
- glassfish v3
- mojara 2.1.6-fcs
- jpa eclipselink
controller bean
public list<usergroupdetail> getusergroupdetail_list() { list<usergroupdetail> myusergroupdetail = new arraylist<usergroupdetail>( lodbn.listusergroupdetail(loginbean.getusername())); system.out.println("username found is:" + loginbean.getusername()); return myusergroupdetail; }
for getting complete list of data jpa pojo usergroupreport
public list<usergroupreport> getgroupid_list() { list<usergroupreport> myallgroupids = new arraylist<usergroupreport>( lodbn.findallgroupidbyuser(loginbean.getusername())); return myallgroupids; }
stack trace
warning: pwc4011: unable set request character encoding iso-8859-1 context /webapp, because request parameters have been read, or servletrequest.getreader() has been called fine: select rowid, groupid, groupname, username usergroupdetail (username = ?) bind => [1 parameter bound] info: [] info: username found is:null fine: select rowid, groupid, groupname, username usergroupdetail (username = ?) bind => [1 parameter bound] info: [] info: username found is:null fine: select rowid, groupid, groupname, username usergroupdetail (username = ?) bind => [1 parameter bound] info: [] info: username found is:null fine: select rowid, lod1costcenter, lod1displayname, lod1domain, lod1mail, lod1user, lod2costcenter, lod2displayname, lod2domain, lod2mail, lod2user, access, authentifiziertebenutzer, auto, comment, comment1, comment2, comment3, domain1, domain2, emailfeedback, emailsendstatus, rechtegruppechange, rechtegrupperead, security, type, username lodreport (username = ?) bind => [1 parameter bound] info: [] info: lod list username :null fine: select rowid, lod1costcenter, lod1displayname, lod1domain, lod1mail, lod1user, lod2costcenter, lod2displayname, lod2domain, lod2mail, lod2user, access, authentifiziertebenutzer, auto, comment, comment1, comment2, comment3, domain1, domain2, emailfeedback, emailsendstatus, rechtegruppechange, rechtegrupperead, security, type, username lodreport (username = ?) bind => [1 parameter bound] info: [] info: lod list username :null fine: select rowid, lod1costcenter, lod1displayname, lod1domain, lod1mail, lod1user, lod2costcenter, lod2displayname, lod2domain, lod2mail, lod2user, access, authentifiziertebenutzer, auto, comment, comment1, comment2, comment3, domain1, domain2, emailfeedback, emailsendstatus, rechtegruppechange, rechtegrupperead, security, type, username lodreport (username = ?) bind => [1 parameter bound] info: [] info: lod list username :null
login bean
package bean; import java.io.serializable; import java.util.arraylist; import java.util.list; //import javax.annotation.postconstruct; import javax.ejb.ejb; import javax.faces.application.facesmessage; import javax.faces.bean.managedbean; import javax.faces.bean.sessionscoped; import javax.faces.context.facescontext; import ejb.userdaobean; import ejb.usergroupdaobean; import model.user; @managedbean(name = "loginbean") @sessionscoped public class loginbean implements serializable { /** * */ private static final long serialversionuid = 1l; @ejb private userdaobean udb; @ejb private usergroupdaobean ugdb; private user userid; public list<user> usernamefirstlastname; public string getfirstname() { return firstname; } public void setfirstname(string firstname) { this.firstname = firstname; } public string getlastname() { return lastname; } public void setlastname(string lastname) { this.lastname = lastname; } public string firstname; public string lastname; public string password; public string getpassword() { return password; } public void setpassword(string password) { this.password = password; } public list<user> getusernamefirstlastname() { list<user> myname = new arraylist<user>(udb.findfirtlastnames(username)); return myname; } public void setusernamefirstlastname(list<user> usernamefirstlastname) { this.usernamefirstlastname = usernamefirstlastname; } private string username; public user getuserid() { return userid; } public void setuserid(user userid) { this.userid = userid; } public string getusername() { return username; } public void setusername(string username) { this.username = username; } public string login() { facescontext context = facescontext.getcurrentinstance(); if (udb.validateuser(username,password)) { userid = udb.finduser(username); context.getexternalcontext().getsessionmap().put("userid", userid); if (ugdb.validategroup(userid)) { return "home.jsf?faces-redirect=true&includeviewparams=true"; } return "normalhome.jsf?faces-redirect=true&includeviewparams=true"; } else { facesmessage message = new facesmessage(); message.setseverity(facesmessage.severity_error); message.setsummary("username doesn't exists! or user trying login else's account"); context.addmessage("", message); return "newloginerror.jsf?faces-redirect=true"; } } public string logout() { facescontext.getcurrentinstance().getexternalcontext() .invalidatesession(); return "logout.jsf?faces-redirect=true"; } }
login page
<?xml version="1.0" encoding="iso-8859-1" ?> <!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://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"> <h:head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <link href="./css/pagelayout.css" rel="stylesheet" type="text/css" /> <title>login</title> </h:head> <h:body> <f:view> <div style="background-color: #205a8c; width: auto; height: 60px"> <h3 style="font-size: large; position: relative;" align="left">lord of data web app</h3> </div> <div id="wrappers"> <div class="content pls centering"> <h:form> <table class="form_table" style="background-color: silver;"> <tbody> <tr> <td>username</td> <td><h:inputtext id="inputusername" value="#{loginbean.username}" required="true" requiredmessage="username required!"></h:inputtext> <h:message for="inputusername"></h:message></td> </tr> <tr> <td>password</td> <td><h:inputsecret id="inputpassword" value="#{loginbean.password}" required="true" requiredmessage="password required!"></h:inputsecret> <h:message for="inputpassword"></h:message></td> </tr> </tbody> </table> <div id="buttonsoptions" align="center" style="padding-top: 10px;"> <h:panelgroup> <tr> <td><h:commandbutton id="login" value="login" action="#{loginbean.login}"></h:commandbutton></td> </tr> </h:panelgroup> </div> </h:form> </div> </div> </f:view> </h:body> </html>
ejb code snippet login authentication
public boolean validateuser(string username, string password) { try { query myquery = entitymanager.createnamedquery("userverification") .setparameter("username", username) .setparameter("password", password); user result = (user) myquery.getsingleresult(); if (result != null) { system.out.println("loggin sucessful!"); return true; } else { system.out.println("user not exists in system"); return false; } } catch (noresultexception e) { return false; } }
and tried use username other session bean working fine until 2 days back. here code bean trying call username picked login bean
bean
package bean; import java.io.serializable; import java.util.arraylist; import java.util.list; import javax.annotation.postconstruct; import javax.ejb.ejb; import javax.faces.bean.managedbean; import javax.faces.bean.managedproperty; import javax.faces.bean.sessionscoped; import ejb.lodreportdaobean; import ejb.lordofdatadaobeannormal; import ejb.userdaobean; import model.lodreport; import model.usergroupdetail; import model.usergroupreport; @managedbean(name = "lordofdatanormaluserbean") @sessionscoped public class lordofdatanormaluserbean implements serializable { /** * @author sushant pandey */ private static final long serialversionuid = 1l; @ejb private lordofdatadaobeannormal lodbn; @ejb private userdaobean udb; @ejb private lodreportdaobean lonrdb; @managedproperty(value = "#{loginbean}") private loginbean loginbean; public loginbean getloginbean() { return loginbean; } public void setloginbean(loginbean loginbean) { this.loginbean = loginbean; } public list<lodreport> lodnormal_list; public list<usergroupreport> usergroup_list; public list<usergroupdetail> usergroupdetail_list; public list<lodreport> finddatabyrowid; private lodreport myreport = new lodreport(); public lodreport getmyreport() { return myreport; } public void setmyreport(lodreport myreport) { this.myreport = myreport; } public void setfinddatabyrowid(list<lodreport> finddatabyrowid) { this.finddatabyrowid = finddatabyrowid; } public int security; public string username; public string access; public string authentifiziertebenutzer; public string auto; public string comment; public string comment1; public string comment2; public string comment3; public string domain1; public string domain2; public string emailfeedback; public string emailsendstatus; public string lod1costcenter; public string lod1displayname; public string lod1domain; public string lod1mail; public string lod1user; public string lod2costcenter; public string lod2displayname; public string lod2domain; public string lod2mail; public string lod2user; public string rechtegruppechange; public string rechtegrupperead; public string type; public int rowid; public list<usergroupreport> groupid_list; public boolean edit; public boolean isedit() { return edit; } public void setedit(boolean edit) { this.edit = edit; } public void setgroupid_list(list<usergroupreport> groupid_list) { this.groupid_list = groupid_list; } public void setlodnormal_list(list<lodreport> lodnormal_list) { this.lodnormal_list = lodnormal_list; } public int getsecurity() { return security; } public void setsecurity(int security) { this.security = security; } public string getusername() { return username; } public void setusername(string username) { this.username = username; } public string getaccess() { return access; } public void setaccess(string access) { this.access = access; } public string getauthentifiziertebenutzer() { return authentifiziertebenutzer; } public void setauthentifiziertebenutzer(string authentifiziertebenutzer) { this.authentifiziertebenutzer = authentifiziertebenutzer; } public string getauto() { return auto; } public void setauto(string auto) { this.auto = auto; } public string getcomment() { return comment; } public void setcomment(string comment) { this.comment = comment; } public string getcomment1() { return comment1; } public void setcomment1(string comment1) { this.comment1 = comment1; } public string getcomment2() { return comment2; } public void setcomment2(string comment2) { this.comment2 = comment2; } public string getcomment3() { return comment3; } public void setcomment3(string comment3) { this.comment3 = comment3; } public string getdomain1() { return domain1; } public void setdomain1(string domain1) { this.domain1 = domain1; } public string getdomain2() { return domain2; } public void setdomain2(string domain2) { this.domain2 = domain2; } public string getemailfeedback() { return emailfeedback; } public void setemailfeedback(string emailfeedback) { this.emailfeedback = emailfeedback; } public string getemailsendstatus() { return emailsendstatus; } public void setemailsendstatus(string emailsendstatus) { this.emailsendstatus = emailsendstatus; } public string getlod1costcenter() { return lod1costcenter; } public void setlod1costcenter(string lod1costcenter) { this.lod1costcenter = lod1costcenter; } public string getlod1displayname() { return lod1displayname; } public void setlod1displayname(string lod1displayname) { this.lod1displayname = lod1displayname; } public string getlod1domain() { return lod1domain; } public void setlod1domain(string lod1domain) { this.lod1domain = lod1domain; } public string getlod1mail() { return lod1mail; } public void setlod1mail(string lod1mail) { this.lod1mail = lod1mail; } public string getlod1user() { return lod1user; } public void setlod1user(string lod1user) { this.lod1user = lod1user; } public string getlod2costcenter() { return lod2costcenter; } public void setlod2costcenter(string lod2costcenter) { this.lod2costcenter = lod2costcenter; } public string getlod2displayname() { return lod2displayname; } public void setlod2displayname(string lod2displayname) { this.lod2displayname = lod2displayname; } public string getlod2domain() { return lod2domain; } public void setlod2domain(string lod2domain) { this.lod2domain = lod2domain; } public string getlod2mail() { return lod2mail; } public void setlod2mail(string lod2mail) { this.lod2mail = lod2mail; } public string getlod2user() { return lod2user; } public void setlod2user(string lod2user) { this.lod2user = lod2user; } public string getrechtegruppechange() { return rechtegruppechange; } public void setrechtegruppechange(string rechtegruppechange) { this.rechtegruppechange = rechtegruppechange; } public string getrechtegrupperead() { return rechtegrupperead; } public void setrechtegrupperead(string rechtegrupperead) { this.rechtegrupperead = rechtegrupperead; } public string gettype() { return type; } public void settype(string type) { this.type = type; } public int getrowid() { return rowid; } public void setrowid(int rowid) { this.rowid = rowid; } public void setusergroup_list(list<usergroupreport> usergroup_list) { this.usergroup_list = usergroup_list; } public void setusergroupdetail_list( list<usergroupdetail> usergroupdetail_list) { this.usergroupdetail_list = usergroupdetail_list; } @postconstruct public void init() { // getlodnormal_list(); getusergroupdetail_list(); // getgroupid_list(); getusername(); } public string displayreport() { getlodnormal_list(); return "reportlordofdatanormal.jsf?faces-redirect=true"; } public list<lodreport> getlodnormal_list() { list<lodreport> mylodreport = new arraylist<lodreport>( lodbn.reportlodnormal(loginbean.getusername())); system.out.println("lod list username :" + loginbean.getusername() ); return mylodreport; } public list<usergroupreport> getusergroup_list() { return usergroup_list; } public list<usergroupdetail> getusergroupdetail_list() { list<usergroupdetail> myusergroupdetail = new arraylist<usergroupdetail>( lodbn.listusergroupdetail(loginbean.getusername())); system.out.println("username found is:" + loginbean.getusername()); return myusergroupdetail; } public string editloddatanormal() { lodbn.updateexistingloddatanormal(security, loginbean.getusername(), access, authentifiziertebenutzer, auto, comment, comment1, comment2, comment3, domain1, domain2, emailfeedback, emailsendstatus, lod1costcenter, lod1displayname, lod1domain, lod1mail, lod1user, lod2costcenter, lod2displayname, lod2domain, lod2mail, lod2user, rechtegruppechange, rechtegrupperead, type, rowid); return "reportlordofdatanormal.jsf?faces-redirect=true"; } public list<usergroupreport> getgroupid_list() { list<usergroupreport> myallgroupids = new arraylist<usergroupreport>( lodbn.findallgroupidbyuser(loginbean.getusername())); return myallgroupids; } public void edit(lodreport myreport) { this.myreport = myreport; edit = true; } public void savemyreport(){ lonrdb.updatereport(myreport); } }