wood burning stoves*
The moose likes JSF and the fly likes JSF ArralyList rendering to Target page is throwing Class Cast Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF ArralyList rendering to Target page is throwing Class Cast Exception" Watch "JSF ArralyList rendering to Target page is throwing Class Cast Exception" New topic
Author

JSF ArralyList rendering to Target page is throwing Class Cast Exception

jvh cj
Greenhorn

Joined: Jan 03, 2011
Posts: 2
Please provide an solution for the problem i am facing when i call a method from my action button and retrieving data in a bean passing the result set to the target page is giving me an class cast exception with an message could not convert from ArrayList to String,but i return a String in stead of ArrayList target page is displaying,but with ArrayList as return parameter i am having Problem,here is the snippet of code i am using,

Error Description:-com.sun.faces.lifecycle.InvokeApplicationPhase execute java.util.ArrayList incompatible with java.lang.String
java.lang.ClassCastException: java.util.ArrayList incompatible with java.lang.String
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:73)



package roseindia;
import java.sql.*;
import java.util.*;

public class TableBean {

Connection con ;
Statement ps;
ResultSet rs;
private List perInfoAll = new ArrayList();

public List getperInfoAll() {
int i = 0;
try
{

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/userdetails","root","root");
ps = con.createStatement();
rs = ps.executeQuery("select * from user");
while(rs.next()){
System.out.println(rs.getString(1));
perInfoAll.add(i,new perInfo(rs.getString(1),rs.getString(2),rs.getString(3)));
i++;

}

}
catch (Exception e)
{
System.out.println("Error Data : " + e.getMessage());
}
return perInfoAll;//If i return String here target page is getting displayed,but with the List getting error page.
}


public class perInfo {

String uname;
String firstName;
String lastName;


public perInfo(String firstName,String lastName,String uname) {
this.uname = uname;
this.firstName = firstName;
this.lastName = lastName;

}

public String getUname() {
return uname;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

}

}


JSF page as below,



<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

<f:view><html>
<head>

</head>
<body>
<center>




<h:dataTable id="dt1" value="#{tableBean.perInfoAll}" var="item" bgcolor="#F1F1F1" border="10" cellpadding="5" cellspacing="3" rows="4" width="50%" dir="LTR" frame="hsides" rules="all" summary="This is a JSF code to create dataTable." >

<f:facet name="header">
<h:outputText value="This is 'dataTable' demo" />
</f:facet>

<h:column>
<f:facet name="header">
<h:outputText value="First Name" />
</f:facet>
<h:outputText style="" value="#{item.firstName}" ></h:outputText>
</h:column>

<h:column>
<f:facet name="header">
<h:outputText value="Last Name"/>
</f:facet>
<h:outputText value="#{item.lastName}"></h:outputText>
</h:column>

<h:column>
<f:facet name="header">
<h:outputText value="Username"/>
</f:facet>
<h:outputText value="#{item.uname}"></h:outputText>
</h:column>

<f:facet name="footer">
<h:outputText value="The End" />
</f:facet>

</h:dataTable>



</center>
</body></html></f:view>


faces-config.xml

<?xml version="1.0"?>

<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
<managed-bean>
<managed-bean-name>table</managed-bean-name>
<managed-bean-class>search.TableBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/searchclient.jsp</from-view-id>
<navigation-case>
<to-view-id>/clientSearchResults.jsp</to-view-id>
</navigation-case>
</navigation-rule>


John Tannel
Greenhorn

Joined: Dec 17, 2010
Posts: 23
Jvh,

Try cleaning up your post. Put code inside code tags for readability. Also please post the actual error.

You might try making the list of the appropriate type. I'm not sure if this will help, but it can't hurt.

John
jvh cj
Greenhorn

Joined: Jan 03, 2011
Posts: 2
Thanks John,i posted the code with suggestions.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSF ArralyList rendering to Target page is throwing Class Cast Exception