异常类型:javax.faces.el.PropertyNotFoundException
技术框架:Ajax4jsf+Spring+Hibernate
运行环境:Tomcat5.5.20
异常情况:
org.apache.myfaces.el.PropertyResolverImpl.getPropertyDescriptor(PropertyResolverImpl.java: 483 )
org.apache.myfaces.el.PropertyResolverImpl.getPropertyDescriptor(PropertyResolverImpl.java: 454 )
org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java: 417 )
org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java: 82 )
org.apache.myfaces.el.ELParserHelper$MyPropertySuffix.evaluate(ELParserHelper.java: 532 )
org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java: 145 )
org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java: 383 )
javax.faces.component.UIOutput.getValue(UIOutput.java: 147 )
org.apache.myfaces.shared_impl.renderkit.RendererUtils.getStringValue(RendererUtils.java: 217 )
org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.renderInput(HtmlTextRendererBase.java: 135 )
org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java: 53 )
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java: 720 )
javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java: 623 )
javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java: 546 )
com.sun.faces.taglib.html_basic.InputTextTag.doEndTag(InputTextTag.java: 524 )
org.apache.jsp.video_jsp._jspx_meth_h_inputText_0(video_jsp.java: 565 )
org.apache.jsp.video_jsp._jspx_meth_h_form_0(video_jsp.java: 538 )
org.apache.jsp.video_jsp._jspx_meth_f_view_0(video_jsp.java: 327 )
org.apache.jsp.video_jsp._jspService(video_jsp.java: 114 )
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java: 97 )
javax.servlet.http.HttpServlet.service(HttpServlet.java: 802 )
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java: 334 )
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java: 314 )
org.apache.jasper.servlet.JspServlet.service(JspServlet.java: 264 )
javax.servlet.http.HttpServlet.service(HttpServlet.java: 802 )
org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java: 416 )
org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java: 234 )
org.ajax4jsf.framework.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java: 101 )
org.ajax4jsf.framework.ajax.AjaxViewHandler.renderView(AjaxViewHandler.java: 197 )
org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java: 384 )
javax.faces.webapp.FacesServlet.service(FacesServlet.java: 198 )
org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java: 67 )
org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java: 223 )
情况分析:从异常的信息来看是在UserBean中找不到comment属性!但是,我的UserBean本来就有两个属性,而且运行正常,comment的属性是后来加上去的,已经详细检查过Comment类的代码、Hibernate映射文件及faces-config.xml配置文件,均没发现错误所在,百思不得解。
(2007年01月18日续)
对于昨晚一直没有解决的问题,今天又继续上Google搜寻,结果只找到如下内容:
Everything look all right, all getters and setters are there. What does this exception mean?
If you declared something like
< h:selectOneMenu id ="selectId" value ="#{employee.user.name}" > the value binding expression is valid if you can call:
employee.getUser().getName();
getUser() returns null in this case
Checklist:
Declare the setters and getters for name _and_ user as public (public String getName()... public void setName(String name) etc.)
Check if the faces-config.xml file is being deployed. This prevents the faces servlet from setting up the beans.
Check for a typo in the faces-config.xml, where you declare the managed beans.
Check if your class name is really "User" and not "UserBean" or similar. Even if the accessor methods are getUser() and setUser() there will probably be a cast exception internally.
这个结果对问题的解决没起到什么作用,因为要找的这几个地方我都找过了,并没有发现问题,倒是Google上的另一处内容让我有点哭笑不得了,这是在一个邮件列表中找到的。
> > Hey everyone,
> >
> > I get a very weird PropertyNotFoundException when trying to
> > initialize a managed bean whose class implements an interface. It
> > can't find the setter for a property, even though the setter exists
> > on both the class and the interface.
> >
> > When I strip the "implements IInterface", it works great.
> >
> > This doesn't make any sense to me, as I didn't change any of the
> > face-config.xml (it still points to the original class).
> >
> > Has anyone seen this? I'm on 1.0.9.
注意,David Tashima提到了他碰到的与我相类似的问题,他用了一个词“weird”,中文意思是怪异的,不可思议的!他所提到的方法我也试了一下,还是不行。于是,我开始怀疑是不是JSF的ManagedBean对属性个数有限制,虽然觉得有得不可能,我还是试了一下,结果当然是我错了。
这时,我记起我的UserBean里还有两个属性,一个是User user,另一个是Video video,于是我又新建了一个属性User newUser,居然也不行,报出了同样原异常!
千难万难也要想办法解决这个问题,于是我开始另一个测试方案,在原有的UserBean里增加一个属性String errMsg,结果测试时抛出同样的异常,说找不到errMsg属性!!!
为什么之前添加的七个属性都能正常运行,而后面添加的就不行了呢?就连最基本的String类型都有问题?
在起身上了个厕所之后,我开始回忆昨天的工作过程,突然记起一件事,昨天先用MyEclipse打开工程出错,所以再用MyEclipse将工程重新载入,使用的是读web.xml方式的载入,一想到这,我立即打开资源管理器,检查我在workspace中的文件,这时突然发现除了我原有的WEB-ROOT文件夹之外,MyEclipse帮我自动生成了另一个WEBROOT文件夹,下面居然也有WEB-INF目录,再下面就是classes和lib目录,会不会是Exadel默认用了WEB-ROOT中的class文件而不是我修改后所生成的class文件呢?于是我将这个WEB-ROOT文件夹删除,然后重新载入工程,结果这个让我郁闷了将近一天的异常终于没有再来了,全是自己惹的祸啊!
结论:由于自己装了两个Eclipse,一个是带插件Exadel,一个是带插件MyEclipse,在载入工程的时候,这两个工具会自动的生成自己规范的文件夹以放置相应的文件,如源文件夹,一个叫src,一个叫JavaSource,而Web文件夹一个叫WEB-ROOT,一个叫WEBROOT,就少了个“-”符号,却会导致找不到类文件,而出现各种错误!