java - Unable to display result from DB with @ManagedProperty -



java - Unable to display result from DB with @ManagedProperty -

the question asking simple one. want display user details 1 time login successfull.

my logincontroller

public logincontroller() { } public string getpassword() { homecoming password; } public string getusername() { homecoming username; } public void setpassword(string password) { this.password = password; } public void setusername(string username) { this.username = username; } public string isvaliduser() { string isvalid="invalid user"; entitymanager em = null; seek { em = getentitymanager(); query query = em.createnamedquery("clientdetails.findbyclientid"); query.setparameter("clientid", username); //hashpassword(password); clientdetails record = (clientdetails) query.getsingleresult(); system.out.print(record); string passwordhash=hashpassword(password); if (record.getpassword().equals(passwordhash)) { system.out.print("valid user"); isvalid = "valid"; } else { system.out.print("invalid user"); isvalid="invalid"; } } grab (exception e) { e.printstacktrace(); } { em.close(); } system.out.println("login status = " + isvalid); homecoming isvalid; } private entitymanager getentitymanager() { homecoming emf.createentitymanager(); } public string hashpassword(string password) { string protectedpassword = null; seek { system.out.println("password entered....." + password); messagedigest md5 = messagedigest.getinstance("md5"); md5.update(password.getbytes()); biginteger hash = new biginteger(1, md5.digest()); protectedpassword = hash.tostring(16); system.out.println("password hashed....." + protectedpassword); } grab (nosuchalgorithmexception e) { e.printstacktrace(); } homecoming protectedpassword; }

i have editcontroller managed bean class

@resource private usertransaction utx = null; @persistenceunit(unitname = "adminpu") private entitymanagerfactory emf = null; private clientdetails clientdetails; private clientwebsitedetails clientwebsitedetails; @managedproperty(value="#{logincontroller}") private logincontroller login; private boolean booleanfacebook; private boolean booleantwitter; private boolean booleanclientsocial; public editaccountcontroller() { } public boolean getbooleanclientsocial() { homecoming booleanclientsocial; } public boolean getbooleanfacebook() { homecoming booleanfacebook; } public boolean getbooleantwitter() { homecoming booleantwitter; } public void setbooleanclientsocial(boolean booleanclientsocial) { this.booleanclientsocial = booleanclientsocial; } public void setbooleanfacebook(boolean booleanfacebook) { this.booleanfacebook = booleanfacebook; } public void setbooleantwitter(boolean booleantwitter) { this.booleantwitter = booleantwitter; } public clientdetails getclientdetails() { if (clientdetails == null) { clientdetails = new clientdetails(); } homecoming clientdetails; } public clientwebsitedetails getclientwebsitedetails() { if (clientwebsitedetails == null) { clientwebsitedetails = new clientwebsitedetails(); } homecoming clientwebsitedetails; } public logincontroller getlogin() { homecoming login; } public void setlogin(logincontroller login) { this.login = login; } public string getaccountdetails() { string result = "details not saved"; entitymanager em = null; seek { system.out.println("retreiving client details"); utx.begin(); em = getentitymanager(); clientdetails.setclientid(login.getusername()); query customerdetails = em.createquery("clientdetails.findbyclientid"); query websitedetails = em.createquery("clientwebsitedetails.findbyclientaccountid"); list customerlist = customerdetails.getresultlist(); list websitelist = websitedetails.getresultlist(); iterator clientit = customerlist.iterator(); iterator websiteit = websitelist.iterator(); while (clientit.hasnext()) { clientdetails = (clientdetails) clientit.next(); clientdetails.setprimarycontactname(clientdetails.getprimarycontactname()); clientdetails.setcompany(clientdetails.getcompany()); clientdetails.setprimaryemailid(clientdetails.getprimaryemailid()); clientdetails.setprimarycontactno(clientdetails.getprimarycontactno()); clientdetails.setprimarydesignation(clientdetails.getprimarydesignation()); } while (websiteit.hasnext()) { clientwebsitedetails = (clientwebsitedetails) websiteit.next(); clientwebsitedetails.setproductionurl(clientwebsitedetails.getproductionurl()); clientwebsitedetails.setsitename(clientwebsitedetails.getsitename()); clientwebsitedetails.setdescription(clientwebsitedetails.getdescription()); clientwebsitedetails.setfacebook(clientwebsitedetails.getfacebook()); clientwebsitedetails.settwitter(clientwebsitedetails.gettwitter()); clientwebsitedetails.setclientsocial(clientwebsitedetails.getclientsocial()); } if ((clientwebsitedetails.getfacebook().equals("y")) && (clientwebsitedetails.gettwitter().equals("y"))) { booleanfacebook = true; booleantwitter = true; booleanclientsocial = false; } else if ((clientwebsitedetails.getfacebook().equals("n")) && (clientwebsitedetails.gettwitter().equals("n") && (clientwebsitedetails.getclientsocial().equals("n")))) { booleanfacebook = false; booleantwitter = false; booleanclientsocial = false; } system.out.print(utx.getstatus()); utx.commit(); } grab (exception e) { e.printstacktrace(); } homecoming result;

}

editaccount.xhtml

<h:form id="registerform"> <h:commandlink value="logout" action=""></h:commandlink> <h:commandlink value="change password" action=""></h:commandlink> <h:outputlabel value=""></h:outputlabel> <h:panelgrid> <h1>customer information</h1> <h:outputlabel value="name:" for="name" /> <h:inputtext id="name" required="true" requiredmessage="please come in name" value="#{editaccountcontroller.clientdetails.primarycontactname}"> <f:validatelength maximum="50"></f:validatelength> </h:inputtext> <h:message for="name"></h:message> <h:outputlabel value="company:" for="company" /> <h:inputtext id="company" required="true" requiredmessage="please come in company" value="#{editaccountcontroller.clientdetails.company}"> <f:validatelength maximum="50"></f:validatelength> </h:inputtext> <h:message for="company"></h:message> <h:outputlabel value="designation:" for="designation" /> <h:inputtext id="designation" required="true" requiredmessage="please come in designation" value="#{editaccountcontroller.clientdetails.primarydesignation}"> <f:validatelength maximum="50"></f:validatelength> </h:inputtext> <h:message for="designation"></h:message> <h:outputlabel value="email id:" for="email" /> <h:inputtext id="email" required="true" requiredmessage="please come in email, eg:yourid@domain.com" value="#{editaccountcontroller.clientdetails.primaryemailid}"> <f:validatelength maximum="70"></f:validatelength> </h:inputtext> <h:message for="email"></h:message> <h:outputlabel value="contact no:" for="phone" /> <h:inputtext id="phone" required="true" requiredmessage="please come in contact number" value="#{editaccountcontroller.clientdetails.primarycontactno}"> <f:validatelength minimum="10" maximum="25"></f:validatelength> </h:inputtext> <h:message for="phone"></h:message> <h2>website information</h2> <h:outputlabel value="domain:" for="production_url" /> <h:inputtext id="production_url" required="true" requiredmessage="please come in domain name,eg:www.domain.com or yourip/app_name" value="#{editaccountcontroller.clientwebsitedetails.productionurl}"> <f:validatelength maximum="50"></f:validatelength> </h:inputtext> <h:message for="production_url"></h:message> <h:outputlabel value="site name:" for="site_name" /> <h:inputtext id="site_name" required="true" requiredmessage="please come in website name" value="#{editaccountcontroller.clientwebsitedetails.sitename}"> <f:validatelength maximum="255"></f:validatelength> </h:inputtext> <h:message for="site_name"></h:message> <h:outputlabel value="description:" for="description" /> <h:inputtextarea id="description" rows="2" cols="40" requiredmessage="please come in website description" value="#{editaccountcontroller.clientwebsitedetails.description}" title="description website in few lines" required="required"> <f:validatelength maximum="250"></f:validatelength> </h:inputtextarea> <h:message for="description"></h:message> <h3>social integration</h3> <h:outputlabel for="fb" value="facebook:"></h:outputlabel> <h:selectbooleancheckbox id="fb" value="#{editaccountcontroller.booleanfacebook}" title="select integrate our facebook app in site"> </h:selectbooleancheckbox> <h:outputlabel for="tweet" value="twitter:"></h:outputlabel> <h:selectbooleancheckbox id="tweet" value="#{editaccountcontroller.booleantwitter}" title="select integrate our twitter app in site"></h:selectbooleancheckbox> <h:outputlabel for="your_app" value="integrate social app bazaar:"></h:outputlabel> <h:selectbooleancheckbox id="your_app" value="#{editaccountcontroller.booleanclientsocial}" title="select integrate social apps"></h:selectbooleancheckbox> <h:commandbutton value="register" type="submit" action="#{editaccountcontroller.saveaccountdetails}"></h:commandbutton> </h:panelgrid> </h:form>

both managed beans , in session scope. app java ee 5.

i need username entered user in editcontroller. figure using manageproperty wrong. can guys point out how utilize manageproperty can value if username set email field in clientdetails pojo.

you need set el-expression managedproperty:

@managedproperty(value="#{logincontroller}")

make sure name right. , logincontroller has right annotations.

java java-ee jpa jsf-2

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -