• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Target Unreachable, identifier 'employee' resolved to null

 
Greenhorn
Posts: 3
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i am trying to implement the JSF 2.0 project with Primefaces from one of the tutorial, i con login with only jsf but not when i use primeface where i am getting following error.

Error Log

HTTP Status 500 - /login2.xhtml @23,98 value="#{employee.userName}": Target Unreachable, identifier 'employee' resolved to null type Exception report
message /login2.xhtml @23,98 value="#{employee.userName}": Target Unreachable, identifier 'employee' resolved to null description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: /login2.xhtml @23,98 value="#{employee.userName}": Target Unreachable, identifier 'employee' resolved to null
javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)root cause
javax.el.PropertyNotFoundException: /login2.xhtml @23,98 value="#{employee.userName}": Target Unreachable, identifier 'employee' resolved to null
com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:97)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:91)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:1023)
javax.faces.component.UIInput.validate(UIInput.java:953)
javax.faces.component.UIInput.executeValidate(UIInput.java:1204)
javax.faces.component.UIInput.processValidators(UIInput.java:693)
javax.faces.component.UIForm.processValidators(UIForm.java:240)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1081)
javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1159)
com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:72)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
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. in Apache Tomcat/7.0.57

Employee.java

package com.login.sample;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

@ManagedBean(name= "employee" )
public class Employee {
private String userName;
private String endName;
private String pass;
private String email;
private String dbPassword;
private String dbName;
DataSource ds;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getEndName() {
return endName;
}
public void setEndName(String endName) {
this.endName = endName;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getDbPassword() {
return dbPassword;
}
public void setDbPassword(String dbPassword) {
this.dbPassword = dbPassword;
}
public String getDbName() {
return dbName;
}
public void setDbName(String dbName) {
this.dbName = dbName;
}
public Employee() {

try {
Context ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/env/jdbc/database");
} catch (NamingException e) {
e.printStackTrace();
}
}
public String add() {
int i = 0;
if (userName != null) {
PreparedStatement ps = null;
Connection con = null;
try {
if (ds != null) {
con = ds.getConnection();
if (con != null) {
String sql = "INSERT INTO employee(firstname, lastname, password, email) VALUES(?,?,?,?)";
ps = con.prepareStatement(sql);
ps.setString(1, userName);
ps.setString(2, endName);
ps.setString(3, pass);

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 employee 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(userName);
if (userName.equals(dbName) && pass.equals(dbPassword)) {
return "output";
} else
return "invalid";
}

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

}

login2.xhtml

<!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"
xmlns:p="http://primefaces.prime.com.tr/ui">

<h:head>
<title>Login Page</title>
</h:head>
<h:body>
<f:view>

<h:form id="loginForm">
<table frame="box">
<tr>
<th>Login Page</th>
</tr>
<tr>
<td><h:outputText value="Enter Your Name : " /></td>
<td><h:inputText id="inputName" value="#{employee.userName}"
required="true" requiredMessage="Name field must not be empty" />
</td>
<td><h:message for="inputName" style="color:red" /></td>
</tr>
<tr>
<td><h:outputText value="Enter password :" /></td>
<td><h:inputSecret id="inputPassword" value="#{employee.pass}"
required="true"
requiredMessage="Password field must not be empty" /></td>
<td><h:message for="inputPassword" style="color:red" /></td>
</tr>
<tr>
<td><h:commandButton value="Sign In" action="#{employee.login2}" /></td>
<td><h:outputText value="Not a User " />
<h:outputLink value="register.xhtml">Sign Up</h:outputLink>
</td>
</tr>
</table>
</h:form>
</f:view>
</h:body>
</html>

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<message-bundle>resources.application</message-bundle>
<resource-bundle>
<base-name>resources.application</base-name>
<var>ErrMsg</var>
</resource-bundle>
<locale-config>
<default-locale>en</default-locale>
</locale-config>
</application>
<navigation-rule>
<description>login user</description>
<from-view-id>/login.xhtml</from-view-id>
<navigation-case>
<from-action>#{user.login}</from-action>
<from-outcome>output</from-outcome>
<to-view-id>/success.xhtml</to-view-id>
</navigation-case>

<navigation-case>
<from-action>#{user.login}</from-action>
<from-outcome>invalid</from-outcome>
<to-view-id>/error.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{employee.login}</from-action>
<from-outcome>output</from-outcome>
<to-view-id>/success.xhtml</to-view-id>
</navigation-case>

<navigation-case>
<from-action>#{employee.login}</from-action>
<from-outcome>invalid</from-outcome>
<to-view-id>/error.xhtml</to-view-id>
</navigation-case>
</navigation-rule>

<navigation-rule>
<description>register new user</description>
<from-view-id>/register.xhtml</from-view-id>
<navigation-case>
<from-action>#{user.add}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/success.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{user.add}</from-action>
<from-outcome>unsuccess</from-outcome>
<to-view-id>/unsuccess.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{employee.add}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/success.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{employee.add}</from-action>
<from-outcome>unsuccess</from-outcome>
<to-view-id>/unsuccess.xhtml</to-view-id>
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>/template.xhtml</from-view-id>
<navigation-case>
<from-outcome>grid center</from-outcome>
<to-view-id>/WEB-INF/templates/gridcenter.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/template.xhtml</from-view-id>
<navigation-case>
<from-outcome>grid left</from-outcome>
<to-view-id>/WEB-INF/templates/gridleft.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/template.xhtml</from-view-id>
<navigation-case>
<from-outcome>grid top</from-outcome>
<to-view-id>/WEB-INF/templates/gridtop.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/template.xhtml</from-view-id>
<navigation-case>
<from-outcome>sidebar</from-outcome>
<to-view-id>/WEB-INF/templates/sidebar.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/template.xhtml</from-view-id>
<navigation-case>
<from-outcome>sidebar</from-outcome>
<to-view-id>/WEB-INF/templates/sourceview.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>jsfLoginExample</display-name>
<welcome-file-list>
<welcome-file>/home.xhtml</welcome-file>
</welcome-file-list>
<resource-ref>
<description>Login Database</description>
<res-ref-name>jdbc/database</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>


I am trying to create a login page with a database in which i am getting this error. Please help me on this issue as i am not getting this bean properties.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll get more help and get it sooner if you do 2 things:

1. Use Code Tags to make your XML and Java code samples easier to read (the message editor has a "Code" button that can insert them).

2. Keep your samples short. Remove non-essential code from the samples. When your samples are too big to fit on the screen without being scrolled, a lot of people won't bother to try and read them.

I THINK that your problem is that you didn't define a scope for your managed bean. And to avert other problems, don't use Request scope. It's nearly worthless in JSF.

3. Any page that gets rendered directly by the webapp server may not route properly through the FacesServlet, since the usual URL path processing isn't being used. Results can be unpredictable. These are the pages specified in web.xml such as the welcome-page, login/loginfail pages and error pages. It's better to define them as HTML or straight (non-JSF) JSP. Have them forward to a JSF URL if you want JSF to handle them. Except for login/loginfail, which cannot be forwarded.

4. Please don't add to the rampant security problems the Internet already has by attempting to use your user-written login function in a production application. I don't care HOW MANY books use a "login" as a JSF example, user-written security is an oxymoron. J2EE defines a built-in security framework. It comes with EVERY Java webapp server, even the minimalist ones like Tomcat and jetty. It has been around for over 10 years, never been hacked to my knowledge, it's pre-debugged, you can easily find docs on how to use it (unlike custom systems), and it integrates with the JEE API in ways that user-written systems cannot. Finally, it was designed by full-time security experts who knew security as their basic job function, not done as a rushed addition by someone whose main priority was to get the application running.

It's OK if you want to use your sample to learn JSF, just don't use it for anything "real".
 
Shivprasad Pashupatimath
Greenhorn
Posts: 3
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much Tim Holloway for brief description about JSF. However can i know how to define scope for managed bean so than i can resolve this issue.
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Will inform JSF to place the "employee" bean in Session scope.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, please try like tihis.My problem solved like tihs.
In Apache you'd rather write "implements Serializable" after your classname.

import java.io.Serializable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;


@ViewScoped
@ManagedBean(name="growlView")
public class GrowlView implements Serializable {
 
Tim Holloway
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Hakki!

You are correct. A bean with Session (or View) scope should be Serializable. Many webapp servers will complain if it isn't.
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic