javax.faces.FacesException:java.lang.ClassCastException:java.lang.String无法转换为javax.faces.component.UIComponent

发布于 2024-12-26 13:02:06 字数 3279 浏览 3 评论 0原文

我的 Java EE Web 应用程序在 Glassfish 2.1 上运行良好。现在我想迁移到 Glassfish 3.1.1,

我已按照提供的修改操作 这里

我对 richfaces 的依赖项如下:-

   <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 中添加了上下文参数,如下所示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 修改了我的应用程序描述符,例如:

<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">

faces-config 中的 如下:-

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

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

服务器日志如下:

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)

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

我该如何解决这个问题?

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

I have followed the modifications provided here

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>

my jsf dependencies are

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

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>

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">

my in faces-config is as follow:-

 <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 :

server log is as follow:

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 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??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心凉怎暖 2025-01-02 13:02:06

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

当您有一个 String 值属性(例如,

private String value;

并使用 binding 属性将其绑定到组件 时)会发生此特殊异常:

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

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

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

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

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

另请参阅:

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

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

private String value;

and are binding it to a component using the binding attribute:

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

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

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

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.

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.

See also:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文