| Author |
jsf data table
|
Ravi Thumma
Greenhorn
Joined: Jul 04, 2009
Posts: 13
|
|
I am new to JSF. I am using <h:datatable> tag to retrieve data from database. Below is the method I have used but I am getting exception. Please help me in this regard.
I cannot understand what statement I am missing. I can see the values getting while debugging but cannot render back the request to the calling page.
Thanks in advance.
Exception is java.lang.ClassCastException: java.util.ArrayList
public List getPatient() {
List li = new ArrayList();
try {
con = ds.getConnection();
System.out.println("Connection Created");
} catch (SQLException s) {
s.printStackTrace();
}
try {
String query =
"SELECT last_name, first_name FROM h37patient_akas where patr_patient_id=" +
getPatientid();
ps = con.prepareStatement(query);
rs = ps.executeQuery();
while (rs.next()) {
li.add(new GetData(rs.getString("last_name"),
rs.getString("first_name")));
}
} catch (SQLException s) {
s.printStackTrace();
} finally {
try {
ps.close();
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return li;
}
}
|
 |
Anil Gorthy
Greenhorn
Joined: Oct 30, 2008
Posts: 13
|
|
Hello Ravi,
Firstly, this is not a JSF related error. There could be several reasons why you are getting a ClassCastException. It may help if you copy/paste your stack trace or look at the stack trace yourself for text beginning with "at <classname>".
I suspect your iterating through the ResultSet and adding them to the ArrayList is not appropriate. Break that step into multiple and ensure that you are retrieving Strings from the ResultSet and adding them to GetData() method before adding this object to the ArrayList. That is a lot of computation in one step.
Best,
Anil.
|
 |
Ravi Thumma
Greenhorn
Joined: Jul 04, 2009
Posts: 13
|
|
|
Thanks Anil
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14572
|
|
Technically speaking, the datatable tag doesn't do datatable retrieval. All it does is present the data in its datamodel.
Which is probably your problem. The dataTable tag cannot use raw collections or arrays directly. You have to wrap them in a JSF dataModel object and have the dataTable reference the dataModel.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Ravi Thumma
Greenhorn
Joined: Jul 04, 2009
Posts: 13
|
|
Tim
Can you please give me the example.
Thanks for your reply.
|
 |
 |
|
|
subject: jsf data table
|
|
|