For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub
- This topic has 6 replies, 2 voices, and was last updated 10 years, 5 months ago by
Mork.
-
AuthorPosts
-
I worked through the “Using JSF for Web Applications” demo, which seems quite good, but when I try to use the form by clicking the command button, I get:
An Error Occurred:/userLogin.jsp(34,6) ‘#{UserBean.userName}’ Target Unreachable, identifier ‘UserBean’ resolved to null
—-
Here are my files. I don’t see the issue after having looked at it a while.
Do you see why I get the error above?
MessageBundle.properties:
user_name_label=User Name\:
user_password_label=Password\:
login_button_label=Login
UserBean.java:package net.jsfdemo.bean;
public final class UserBean
{
private String password;
private String userName;public UserBean() {
super();
// TODO Auto-generated constructor stub
}/**
* @return Returns the password.
*/public String getPassword() {
return password;
}/**
* @param password The password to set.
*/public void setPassword(String password) {
this.password = password;
}/**
* @return Returns the userName.
*/public String getUserName() {
return userName;
}/**
* @param userName The userName to set.
*/public void setUserName(String userName) {
this.userName = userName;
}public String loginUser() {
if(“myeclipse”.equals(getUserName()) && “myeclipse”.equals(getPassword()))
return “success”;
return “failure”;
}
}————-
faces-config.xml:<?xml version=”1.0″ encoding=”UTF-8″?>
<faces-config
xmlns=”http://xmlns.jcp.org/xml/ns/javaee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd”
version=”2.2″>
<managed-bean>
<managed-bean-name>userBean</managed-bean-name>
<managed-bean-class>net.jsfdemo.bean.UserBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>password</property-name>
<property-class>java.lang.String</property-class>
<value></value>
</managed-property>
<managed-property>
<property-name>userName</property-name>
<property-class>java.lang.String</property-class>
<value></value>
</managed-property>
</managed-bean>
<navigation-rule>
<display-name>userLogin</display-name>
<from-view-id>/userLogin.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/userLoginSuccess.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<display-name>userLogin</display-name>
<from-view-id>/userLogin.jsp</from-view-id>
<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/userLogin.jsp</to-view-id>
</navigation-case>
</navigation-rule></faces-config>
————–
userLogin.jsp:
<%@taglib uri=”http://java.sun.com/jsf/core” prefix=”f”%><%@taglib
uri=”http://java.sun.com/jsf/html” prefix=”h”%><%@ page language=”java” import=”java.util.*” pageEncoding=”US-ASCII”%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
%><!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<base href=”<%=basePath%>”><title>My JSP ‘userLogin.jsp’ starting page</title>
<meta http-equiv=”pragma” content=”no-cache”>
<meta http-equiv=”cache-control” content=”no-cache”>
<meta http-equiv=”expires” content=”0″>
<meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″>
<meta http-equiv=”description” content=”This is my page”>
<!–
<link rel=”stylesheet” type=”text/css” href=”styles.css”>
–></head>
<body style=”height: 212px; “>
<f:view>
<f:loadBundle basename=”net.jsfdemo.MessageBundle” var=”bundle”/><br><h:form id=”loginForm” style=”height: 117px; “>
<h:outputLabel value=”#{bundle.user_name_label}” for=”userName”>
<h:inputText id=”userName” value=”#{UserBean.userName}” required=”true”></h:inputText>
</h:outputLabel><br>
<h:outputLabel value=”#{bundle.user_password_label}” for=”password”>
<h:inputSecret id=”password” value=”#{UserBean.password}” required=”true” />
</h:outputLabel>
<br><h:commandButton value=”#{bundle.login_button_label}” action=”#UserBean.loginUser}”></h:commandButton></h:form>
</f:view>
</body>
</html>——————-
userLoginSuccess.jsp:
<%@taglib uri=”http://java.sun.com/jsf/core” prefix=”f”%><%@taglib
uri=”http://java.sun.com/jsf/html” prefix=”h”%><%@ page language=”java” import=”java.util.*” pageEncoding=”US-ASCII”%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;
%><!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<base href=”<%=basePath%>”><title>My JSP ‘userLoginSuccess.jsp’ starting page</title>
<meta http-equiv=”pragma” content=”no-cache”>
<meta http-equiv=”cache-control” content=”no-cache”>
<meta http-equiv=”expires” content=”0″>
<meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″>
<meta http-equiv=”description” content=”This is my page”>
<!–
<link rel=”stylesheet” type=”text/css” href=”styles.css”>
–></head>
<body>
<f:view>Hello <h:outputText value=”#{UserBean.userName}”></h:outputText>, you successfully logged in.</f:view>
<br>
</body>
</html>Attachments:
You must be logged in to view attached files.June 23, 2015 at 5:41 am #393923
support-swapnaModeratorJim,
Sorry that you are seeing this issue.
In the faces-config.xml, the managed bean name should be capitalized.
Replace the below line
<managed-bean-name>userBean</managed-bean-name>with :
<managed-bean-name>UserBean</managed-bean-name>Redeploy the project and check if it fixes the issue.
The New Managed Bean wizard by default populates the Name with ‘userName’ and you should change it to ‘UserName’ which is already mentioned in the tutorial (3.Create Managed Beans section, point no 5 : Capitalize the default name – UserBean.). We will take a look if we can modify the wizard to populate the capitalized bean name instead of correcting it manually.
Let us know how it works for you.
–Swapna
MyEclipse SupportJune 23, 2015 at 6:18 am #393924Thanks, Yes, that fixed an issue and let me discover another I’m working on now. 🙂
Would it be possible, as you suggested, to have the wizard generate code that doesn’t need to be manually changed?
Since the tutorial was so long, I missed that step and spent a couple hours trying to figure out what was going on.
Thanks,
– m
June 23, 2015 at 7:05 am #393926
support-swapnaModeratorJim,
Glad that it worked. I have raised a PR for the dev team to check if we can make the changes on the wizard level to fix this issue.
Sorry for inconvenience caused.
Let us know if you see any issues.
–Swapna
MyEclipse SupportJune 23, 2015 at 7:51 am #393930Thanks. Should be an easy fix and was probably just an oversight when you coded the wizard.
Thanks very much for your support! 🙂
– m
June 24, 2015 at 8:16 am #394006
support-swapnaModeratorJim,
Apologies for the confusion. The issue with the bean name is not a bug with MyEclipse wizard.
The wizard correctly populates the bean name as ‘userBean’. I assume you have copy pasted the code just like I did when following the tutorial and in the tutorial since the bean name is ‘UserBean’ in the userLogin.jsp and userLoginSuccess.jsp, the error occurred at runtime.To summarize, the wizard is correct and you can give any name for bean name but make sure that the same name is used in all the declarations.
In JSF 2.0 and higher, managed beans can be configured using the @ManagedBean annotation in the Java class, rather than in the faces-config.xml file.Let us know if you have any questions.
–Swapna
MyEclipse SupportJune 24, 2015 at 8:27 am #394007Thanks very much for the follow up. 🙂
Appreciate your help on this.
– m
-
AuthorPosts

