您的位置:首页 > Web前端 > JavaScript

jsf常见错误

2008-06-04 23:30 246 查看
JSF常见错误分析

* According to TLD or attribute directive in tag file, attribute value does not accept any expressions
* Can't instantiate class:xxx.xxx.xxx
* java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter
* 导航出现问题,不工作
* value="#{userBean.user.userName}": Target Unreachable, 'user' returned null

* According to TLD or attribute directive in tag file, attribute value does not accept any expressions

1. 修改web.xml.

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
改为2.3版本的

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
2. 使用JSTL core RT库

JSTL core库的有两种taglib伪指令, 其中RT库即是依赖于JSP传统的请求时属性值, 而不是依赖于EL来实现(称为EL库.JSP2.0将支持EL)

JSP中使用<%@ taglib uri=http://java.sun.com/jstl/core prefix="c"%>在2.3版本都可以,在2.4就不行了, 难道是版本不兼容吗?

只要将

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
改为

<%@ taglib uri=http://java.sun.com/jstl/core_rt prefix="c"%>
另外:
JSF expressions can access stuff in the http session fine.

When expression #{foo} is encountered, JSF does this:
(1) look in the request-scope vars for name "foo"
(2) look in the http-session vars for name "foo"
(3) look in the app-scope vars for name "foo"
(4) look for a managed-bean declaration for "foo" and if found create an instance and put it in whatever scope was declared.
(5) report an error

The first 3 steps are identical to the JSP variable lookup. The var scopes are the same ones used by JSP. If there is an entry for "foo" in the http session then it will be found, regardless of what code put it there.

Note however that JSF does not have any equivalent to the JSP "page scope". That's a JSP-specific feature that is not in the servlet spec and is not accessable to anything other than JSP code.

The JSTL tags do NOT work well with JSF in general,
还有,就是换一个应用服务器,从Tomcat换到JBoss试试。

* Can't instantiate class:xxx.xxx.xxx

比如:de.mindmatters.faces.component.html
修改Web.xml中配置,把参数verifyObjects设置成false。(感觉不过只是个表面的修改方案。)
<context-param>
<param-name>com.sun.faces.verifyObjects</param-name>
<param-value>false</param-value>
</context-param>
修改后不再出现类似问题,不过会出现其他问题。

* java.lang.IllegalStateException: No thread-bound request: use RequestContextFilter

是因为在Web.xml中配置没有增加Spring的相应Listener, 将下面代码贴如Web.xml中即可。
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>

* 导航出现问题,不工作

这可能是你的faces-config.xml出现问题,比如你在配置<from-view-id>的时候没有给路径“/test.xhtml”,而是直接写的“test.xhtml”,是不行的。

* value="#{userBean.user.username}": Target Unreachable, 'user' returned null

主要是因为在faces-config.xml中对应的managed bean配置中,没有把user属性定义出来。
还会出现value="#{userBean.user.username}": Target Unreachable, 'user' returned null
主要是因为在Backing Bean的getUser方法中,直接返回了user,没有判断user是否为空,如果为空需要new一个User出来:
public User getUser(){
if (user == null) user = new User();
return user;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: