javax.faces.FacesException:java.lang.ClassCastException:java.lang.String无法强制转换为javax.faces.component.UIComponent [英] javax.faces.FacesException: java.lang.ClassCastException: java.lang.String cannot be cast to javax.faces.component.UIComponent

查看:472
本文介绍了javax.faces.FacesException:java.lang.ClassCastException:java.lang.String无法强制转换为javax.faces.component.UIComponent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Java EE Web应用程序与Glassfish 2.1一起正常工作。现在我想迁移到Glassfish 3.1.1

My Java EE web application is working fine with Glassfish 2.1. Now I want to migrate to Glassfish 3.1.1

我已关注修改提供此处

我的依赖项对于richfaces如下: -

my dependencies for richfaces are as follow:-

   <dependency>
        <groupId>org.richfaces.framework</groupId>
        <artifactId>richfaces-api</artifactId>
        <version>3.3.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.richfaces.framework</groupId>
        <artifactId>richfaces-impl-jsf2</artifactId>
        <version>3.3.3.Final</version>
    </dependency>
    <dependency>
        <groupId>org.richfaces.ui</groupId>
        <artifactId>richfaces-ui</artifactId>
        <version>3.3.3.Final</version>
    </dependency>

我的jsf依赖是

        <dependency>
            <groupId>com.sun.faces</groupId> 
            <artifactId>jsf-api</artifactId> 
            <version>2.0.2</version> 
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId> 
            <artifactId>jsf-impl</artifactId> 
            <version>2.0.2</version> 
        </dependency>

在web.xml中添加了上下文参数,如下所示: -

added context param in web.xml as follow:-

<context-param>
    <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
    <param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.DISABLE_FACELET_JSF_VIEWHANDLER</param-name>
    <param-value>true</param-value>
</context-param>

使用2.5版修改了我的应用程序描述符,如:

modified my application descriptor with version 2.5 like:

<web-app version="2.5" 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/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

我的 如下: -

 <application>
        <navigation-handler >
            org.navigation.CustomNavigationHandler
        </navigation-handler>

        <view-handler>
            org.ajax4jsf.application.AjaxViewHandler
        </view-handler>
<!--        <view-handler>
            com.sun.facelets.FaceletViewHandler
        </view-handler>-->
        <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
        <message-bundle>MyMessages</message-bundle>
    </application>

应用程序成功部署但在此之后我在启动应用程序时遇到类强制转换异常错误在浏览器中:

Application get deployed successfully but after that i am getting error of class cast exception at the time starting an application in browser :

服务器日志如下:

INFO: myApp was successfully deployed in 21,635 milliseconds.
SEVERE: Error Rendering View[/login.xhtml]
javax.faces.FacesException: java.lang.ClassCastException: java.lang.String cannot be cast to javax.faces.component.UIComponent
    at com.sun.faces.application.ApplicationImpl.createComponentApplyAnnotations(ApplicationImpl.java:1923)

It在glassfish 2中正常工作,所以我认为没有关于属性与支持bean绑定的问题。

It is working fine in glassfish 2 so i think there is no issue regarding binding of attributes with backing bean.

我该如何解决这个问题?

how can i resolve this??

推荐答案


java.lang.ClassCastException:java.lang.String无法转换为javax.faces.component.UIComponent
at com.sun.faces.application.ApplicationImpl.createComponentApplyAnnotations

java.lang.ClassCastException: java.lang.String cannot be cast to javax.faces.component.UIComponent at com.sun.faces.application.ApplicationImpl.createComponentApplyAnnotations

当你有一个 String 值属性时会发生这个特殊的例外,例如

This particular exception will occur when you have a String value property like

private String value;

并使用绑定将其绑定到组件属性:

<h:inputText binding="#{bean.value}" />

这是不正确的。该值应使用属性绑定:

This is incorrect. The value should be bound using the value attribute:

<h:inputText value="#{bean.value}" />

绑定仅用于将整个组件(它是 UIComponent 的实例)绑定到辅助bean,例如以编程方式修改它。

The binding is only to be used to bind the whole component (which is an instance of UIComponent) to the backing bean, for example to programmaticlly modify it.

验证您的 login.xhtml 代码。如果有必要尽可能地删除代码,只要你仍然可以重现问题,这样你就可以得到尽可能小的代码片段,它会重现这个问题,这样你就可以更容易地找到罪魁祸首。

Verify your login.xhtml code. If necessary cut out as much as possible code as long as you can still reproduce the problem so that you can end up with the smallest possible code snippet which reproduces exactly this problem which should allow you to find the culprit easier.

  • How does the 'binding' attribute work in JSF? When and how should it be used?

这篇关于javax.faces.FacesException:java.lang.ClassCastException:java.lang.String无法强制转换为javax.faces.component.UIComponent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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