Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

jsf data table

 
Ravi Thumma
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Anil
 
Tim Holloway
Bartender
Posts: 18419
60
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ravi Thumma
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim

Can you please give me the example.

Thanks for your reply.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!