现在的位置: 首页 > 综合 > 正文

JSF常见错误

2013年08月10日 ⁄ 综合 ⁄ 共 2484字 ⁄ 字号 评论关闭

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;
}

View中的UIInput组件的值不能传递给Backing Bean,或者EventListener, Action方法没有被执行
这个情况的一种可能是你的Backing Bean中用了一个Class类型的property,然后在UIInput的value绑定使用了object.propertyObj.property的方式。
在Backing Bean中的property如果是类时,其getter方法不能简单的return person; 因为这个时候可能person还没有初始化,需要先判断是否为null,if (person == null) person = new Person(); 这样就OK了。

java.lang.ClassCastException错误:
Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener
javax.faces.FacesException: java.lang.ClassCastException: org.apache.myfaces.application.ApplicationImpl

原因:在libarary中使用了myface实现,但是却还有sun RI的包,只需要把这些重复的包删除掉即可。

 

JSCookMenu不能导航的问题
使用了JSCookMenu做导航,把菜单放在了一个header.jsp中,main.jsp include header.jsp。
在config文件中,配置了导航规则:

 <navigation-rule>
  <from-view-id>header.jsp</from-view-id>
  <navigation-case>
   <from-outcome>goto_add_relatedness</from-outcome>
   <to-view-id>/add_relatedness.jsp</to-view-id>
  </navigation-case>
 </navigation-rule>

java.lang.ClassCastException错误:
Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener
javax.faces.FacesException: java.lang.ClassCastException: org.apache.myfaces.application.ApplicationImpl

JSF中PropertiesNotFound错误:
郁闷了一天了,做一个简单的jsf例子,为了实现国际化,做了一个资源文件application.properties,放在resource package中。
代码片段如下:
<f:view>
<f:loadBundle var="bundle" basename="resources.application"/>
...
<h:outputText value="#{bundle.addperson.head}"/>

每次运行都出现如下错误:
javax.faces.el.PropertyNotFoundException: Error getting property 'head' from bean of type java.lang.String

把value变成Hard String: <h:outputText value="Head"/>问题就没有了。
查了一天的资料,终于发现了解决办法:
改写成:
<h:outputText value="#{bundle['addperson.head']}"/>
就好了,唉,在编写jsf的component时,输完“#{bundle.”之后出现的代码提示就是“['addperson.head']”,当时还以为是有错误,结果发现是自己的错误,郁闷!
经常就是这些诸如:环境搭建问题,或者拼写错误,或者这样那样的低级错误导致了大量时间的浪费。

 

来源:http://blog.csdn.net/smilingleo/archive/2007/09/03/1769763.aspx

抱歉!评论已关闭.