Javax.faces.FacesException: java.lang.ClassCastException: java.lang.String cannot be added to javax.faces.component.UIComponent

My Java EE web application works fine with Glassfish 2.1. Now I want to upgrade to Glassfish 3.1.1

I followed the changes made here

My dependencies for richfaces are as follows: -

<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

  <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 parameter in web.xml as follows: -

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

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

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

The application deploys successfully, but after that I get an error of class exception when the application starts in the browser:

The server log is as follows:

 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 works fine in glass planet 2, so I think there is no problem binding attributes with bean support.

how can i solve this problem?

+4
source share
1 answer

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

This particular exception will occur if you have a String value property, for example

 private String value; 

and bind it to the component using the binding attribute:

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

This is not true. The value must be bound using the value attribute:

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

binding used only to bind the entire component (which is an instance of UIComponent ) to the bean base, for example, to programmatically modify it.

login.xhtml your login.xhtml code. If necessary, cut as much code as possible while you can still reproduce the problem, so that you can get the smallest possible piece of code that reproduces this particular problem, which should allow you to find the culprit easier.

See also:

+17
source

Source: https://habr.com/ru/post/1390834/


All Articles