JSF in bean of type null

阿狸Jay(塘主) 2008-06-20 06:54:53

严重: Servlet.service() for servlet Faces Servlet threw exception
javax.faces.el.PropertyNotFoundException: Error testing property 'userName' in bean of type null
at com.sun.faces.el.PropertyResolverImpl.getType(PropertyResolverImpl.java:342)
at com.sun.faces.el.impl.ArraySuffix.getType(ArraySuffix.java:240)
at com.sun.faces.el.impl.ComplexValue.getType(ComplexValue.java:208)
at com.sun.faces.el.ValueBindingImpl.getType(ValueBindingImpl.java:338)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:111)

我的face-config.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

<faces-config >
<managed-bean>
<managed-bean-name>UserBean</managed-bean-name>
<managed-bean-class>
com.jsfdemo.bean.UserBean
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>userName</property-name>
<property-class>java.lang.String</property-class>
<value></value>
</managed-property>
<managed-property>
<property-name>password</property-name>
<property-class>java.lang.String</property-class>
<value></value>
</managed-property>
</managed-bean>
<navigation-rule>
<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-case>
<from-outcome>failure</from-outcome>
<to-view-id>/userLogin.jsp</to-view-id>
</navigation-case></navigation-rule>
<navigation-rule>
<from-view-id>/userLoginSuccess.jsp</from-view-id>
</navigation-rule>
<application>
<locale-config>
<default-locale>zh_CN</default-locale>
<supported-locale>en</supported-locale>
<supported-locale>ja</supported-locale>
</locale-config>
</application>

</faces-config>


我的userLogin.jsp

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<%

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 JSF 'userLogin.jsp' starting page</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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>
<f:loadBundle basename="com.jsfdemo.Messeages_zh_CN" var="bundle" />

<h:form>
<h:outputLabel for="userName" value="#{bundle.user_name_lable}" />
<h:inputText id="userName" value="#{userBean.userName}" required="true"/>
<h:outputLabel for="password" value="#{bundle.user_password_lable}" />
<h:inputSecret id="password" value="#{userBean.password}" rendered="true" required="true" /><br>
<h:commandButton type="submit" value="#{bundle.login_botoom_lable}" action="#{userBean.loginUser}"></h:commandButton>
</h:form>

</f:view>
</body>
</html>
...全文
296 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
阿狸Jay(塘主) 2008-06-21
  • 打赏
  • 举报
回复
一个人工作就是很难检查出自己的低级错误。原来配置文件中我的受管BEAN的名字userBean的u,竟然写成大写U了
阿狸Jay(塘主) 2008-06-20
  • 打赏
  • 举报
回复
UserBean类
/**
*
*/
package com.jsfdemo.bean;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
* @author Administrator
*
*/
public final class UserBean extends Object {

/**
*
*/
private String userName;
/**
*
*/
private String password;
/**
* @return the userName
*/
public String getUserName() {
return userName;
}
/**
* @param userName the userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}

public String loginUser(){
if("myeclipse".equals(getUserName())&&"myeclipse".equals(getPassword()))
return "success";
FacesContext facesContext=FacesContext.getCurrentInstance();
FacesMessage facesMessage=new FacesMessage("username or password is invaild!");
facesContext.addMessage("loginForm", facesMessage);
return "failure";
}

}

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧