• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsf data table

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
}
}
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Anil
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim

Can you please give me the example.

Thanks for your reply.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic