javax.el.E​​LException:在com.example.Bean类型上读取'foo'时出错 [英] javax.el.ELException: Error reading 'foo' on type com.example.Bean

查看:112
本文介绍了javax.el.E​​LException:在com.example.Bean类型上读取'foo'时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读以下教程:

h:dataTable/@ value中使用的表达式通常指定一个属性 定义了吸气剂的名称,这意味着在控制器中 定义了属性簿的BookController类(可选)以及一个 名为getBooks的方法(这是强制性的).在这种特殊情况下 只需定义getBooks方法就足够了,因为不需要 控制器类中的books属性

The expression used in the h:dataTable/@value normally specifies a property name for which a getter was defined, which means that in the controller BookController class a property books is defined (optional) as well as a method named getBooks (this is mandatory). In this particular case it is just sufficient to define the getBooks method since there is no need of the books property in the controller class

我一直在尝试在eclipse和tomcat 7中实现这样的想法,但它一直困扰着我:

I have been trying to work such an idea in my eclipse and tomcat 7. but it keeps tilling me:

javax.el.E​​LException:/views/books/listAll.xhtml @ 9,60 value =#{bookController.books}":读取类型为pl.ctrl.BookController的'books'时出错

javax.el.ELException: /views/books/listAll.xhtml @9,60 value="#{bookController.books}": Error reading 'books' on type pl.ctrl.BookController

我的问题是,可能有:

<h:dataTable value="#{bookController.books}" var="b">

#{bookController}托管bean中没有books属性,而只有getBooks() getter方法?

While there is no books property but just getBooks() getter method in #{bookController} managed bean?

推荐答案

您的问题与书中所讲的不同.如果JSF/EL找不到完整的getter方法,您将得到以下异常:

Your problem is different than what the book tells. If JSF/EL couldn't find the getter method in its entirety, you would have gotten the below exception:

javax.el.PropertyNotFoundException:在pl.ctrl.BookController类型上找不到属性"books"

或者找不到完整的bean:

Or if it couldn't find the bean itself in its entirety:

javax.el.PropertyNotFoundException:目标无法访问,标识符为'bookController'解析为空

但是您却得到了:

javax.el.E​​LException:读取类型为pl.ctrl.BookController的'books'时出错

javax.el.ELException: Error reading 'books' on type pl.ctrl.BookController

这意味着找到了bean和getter方法,但是调用getter方法引发了异常.基本上,以下是在JSF/EL的掩盖下发生的:

This means that the bean and the getter method was found, but invoking the getter method threw an exception. Basically, the following is happening under JSF/EL's covers:

try {
    Object result = bookController.getBooks();
} catch (Exception e) {
    throw new ELException("Error reading 'books' on type pl.ctrl.BookController", e);
}

请注意,将e作为ELException的原因而传递.因此,原始异常必须在堆栈跟踪中的最下方显示为由...引起",而您没有在问题中的任何位置发布该异常.最底层的问题是所有问题的根本原因,并且是您具体问题的答案.如果您无法解释它,只需将异常类型和消息复制粘贴到一个不错的搜索引擎中,以找到答案和线索.

Note the e being passed as cause of the ELException. The original exception must thus be visible as "Caused by" further down in the stack trace which you didn't post anywhere in the question. The bottommost one is the root cause of all and is the answer to your concrete problem. In case you're unable to interpret it, simply copypaste the exception type and message into a decent search engine to find answers and clues.

无关与具体问题无关,从getter方法引发的异常又表示可疑的代码. getter方法不应执行任何异常敏感的业务逻辑.即,每个bean的生命周期可以多次调用它,并且在所有bean的生命周期内重复一遍又一遍地重复相同的业务逻辑,这显然是低效的.停止这样做,并将业务逻辑移至一次性初始化或动作/事件侦听器方法. getter方法必须仅返回已经准备好的属性.另请参见为什么JSF多次调用getters

Unrelated to the concrete problem, an exception thrown from a getter method in turn indicates fishy code. A getter method isn't supposed to do any exception sensitive business logic. Namely, it can be invoked multiple times per bean's life and repeating the very same business logic over and over during all bean's life is plain inefficient. Stop doing that and move the business logic to an one time initialization or action/event listener method. The getter method must merely return the already-prepared property. See also Why JSF calls getters multiple times and How and when should I load the model from database for h:dataTable.

这篇关于javax.el.E​​LException:在com.example.Bean类型上读取'foo'时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆