• Post Reply Bookmark Topic Watch Topic
  • New Topic

HTTP Status 500 - /test.xhtml @94,58 value="#{user.firstName}": Target Unreachable, identifier 'user

 
Shivprasad Pashupatimath
Greenhorn
Posts: 3
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am getting error while implementing jsf using primefaces and while entering username and password in the fields.

HTTP Status 500 - /test.xhtml @94,58 value="#{user.firstName}": Target Unreachable, identifier 'user' resolved to null type Exception report

message /test.xhtml @94,58 value="#{user.firstName}": Target Unreachable, identifier 'user' resolved to null

description The server encountered an internal error that prevented it from fulfilling this request.exception

javax.servlet.ServletException: /test.xhtml @94,58 value="#{user.firstName}": Target Unreachable, identifier 'user' resolved to null
javax.faces.webapp.FacesServlet.service(FacesServlet.java:325)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)root cause

javax.el.PropertyNotFoundException: /test.xhtml @94,58 value="#{user.firstName}": Target Unreachable, identifier 'user' resolved to null
com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:1028)
javax.faces.component.UIInput.validate(UIInput.java:958)
javax.faces.component.UIInput.executeValidate(UIInput.java:1209)
javax.faces.component.UIInput.processValidators(UIInput.java:698)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1085)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1085)
javax.faces.component.UIForm.processValidators(UIForm.java:244)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1085)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1085)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1085)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1085)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1165)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.57 logs.


User.java
package org.primefaces.examples.domain;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

@ManagedBean(name = "user")
@RequestScoped
public class User {

private String firstName;
private String lastName;
private String email;
private String password;
private String dbPassword;
private String dbName;
DataSource ds;

public User() {
try {
Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/env/jdbc/database");
} catch (NamingException e) {
e.printStackTrace();
}
}

public String getDbPassword() {
return dbPassword;
}

public String getDbName() {
return dbName;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String name) {
this.firstName = name;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getEmail() {
return email;
}

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

public String getPassword() {
return password;
}

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

public String add() {
int i = 0;
if (firstName != null) {
PreparedStatement ps = null;
Connection con = null;
try {
if (ds != null) {
con = ds.getConnection();
if (con != null) {
String sql = "INSERT INTO user(firstname, password, lastname, email) VALUES(?,?,?,?)";
ps = con.prepareStatement(sql);
ps.setString(1, firstName);
ps.setString(2, password);
ps.setString(3, lastName);
ps.setString(4, email);
i = ps.executeUpdate();
System.out.println("Data Added Successfully");
}
}
} catch (Exception e) {
System.out.println(e);
} finally {
try {
con.close();
ps.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (i > 0) {
return "success";
} else
return "unsuccess";
}

public void dbData(String uName) {
if (uName != null) {
PreparedStatement ps = null;
Connection con = null;
ResultSet rs = null;

if (ds != null) {
try {
con = ds.getConnection();
if (con != null) {
String sql = "select firstname,password from user where firstname = '"
+ uName + "'";
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
rs.next();
dbName = rs.getString("firstname");
dbPassword = rs.getString("password");
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
}
}

public String login() {
dbData(firstName);
if (firstName.equals(dbName) && password.equals(dbPassword)) {
return "output";
} else
return "invalid";
}

public void logout() {
FacesContext.getCurrentInstance().getExternalContext()
.invalidateSession();
FacesContext.getCurrentInstance()
.getApplication().getNavigationHandler()
.handleNavigation(FacesContext.getCurrentInstance(), null, "/login.xhtml");
}
}

 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch!

Please make sure to use code tags when you provide source code as part of your post! http://www.coderanch.com/how-to/java/UseCodeTags

Looks like the user object is not in whatever scope your JSF page is executing.
 
Tim Holloway
Bartender
Posts: 18418
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Shivprasad!

Request scope is almost 100% useless in JSF. Try ViewScoped or SessionScoped. Request-scoped objects get created and destroyed each time a submit is done, so there's no carryover of state from one request to the next.

The stacktrace says that identifier "user" is resolving to null, instead of a JSF backing bean. That should not be. JSF's Managed Bean capability ensures that when you request a View, if the bean isn't defined then JSF will automatically construct an instance, set any Managed Properties and use that with the View. You appear to have managed to confuse that mechanism. One possibility is that the client is requesting the resource template for the View (".xhtml") instead of the View itself (".jsf").
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!