| Author |
Showing results of dynamic database query in jsf
|
ajaay shereen
Greenhorn
Joined: Feb 09, 2010
Posts: 3
|
|
Hi,
Sorry if i am posting for a previously answered question or a basic one. I am a newbie to jsf.
I want to process a query passed at runtime through webpage and display the results in another page. i have tried passing resultset directly to the datatable tag and it didnt give me desired reults.
somewhere i saw that said to change resultset to result. that didnt work for all the query results as well.
please help me on this. please tell which is the right way to show database results in jsf
Thanks in advance.
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14486
|
|
Welcome to the JavaRanch, ajaay!
You cannot pass a ResultSet directly to a dataTable. DataTables display what they get from a DataModel object, so you need to construct a ResultsetDataModel and supply your resultset to it. You construct a dataTable tag to reference that DataModel object.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
Nick Potter
Ranch Hand
Joined: May 07, 2008
Posts: 125
|
|
|
Hello, I'm curious, why does dataTable needs a DataModel? It works with Lists for example, so as long as you assign the entries to a list there shouldn't be any problem. Or am I misunderstanding the question?
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14486
|
|
The DataModel provides the cursor services that the controller uses to iterate the rows in the table. Among other things, it allows you to bind actions to items in the table and know which item was selected.
You can't supply a List directly to a DataTable. There's a ListDataModel class that can be used for wrapping Lists, however.
|
 |
Nick Potter
Ranch Hand
Joined: May 07, 2008
Posts: 125
|
|
For binding purposes and additional functionality, yes, but for simply displaying the results of a query, a list is enough.
This works and accomplishes its goal.
|
 |
Bart Kummel
author
Ranch Hand
Joined: Nov 30, 2007
Posts: 81
|
|
Hi Nick,
You are right. However, in the example in your last post, the dataTable component still wraps the list in a javax.faces.model.ListDataModel internally. Most of the time you do not notice this, but it is good to know that this is happening behind the scenes.
Best regards,
Bart
|
SCJP 1.4 | SCJD 1.6 | Visit my website | Author of the book Apache MyFaces 1.2 Web Application Development
|
 |
Nick Potter
Ranch Hand
Joined: May 07, 2008
Posts: 125
|
|
Aha! ... good to know then.
Thanks,
|
 |
ajaay shereen
Greenhorn
Joined: Feb 09, 2010
Posts: 3
|
|
Thank you guys for clarifying my doubt.
@Tim: I will try what you have said about datamodel and post the result tomorrow.
Bart,
From what you have said about list converting into listdatamodel internally, i take it that all the Collection types change to corresponding DataModels when using in JSF. Please tell whether it is so.
Thanks once again.
|
 |
Bart Kummel
author
Ranch Hand
Joined: Nov 30, 2007
Posts: 81
|
|
Hi Ajaay,
No, not all Collection types are wrapped in a DataModel automatically. According to the JSF 1.2 specification, only java.util.List or array of Objects are autmatically wrapped. I just read that part of the spec, and it actually says:
So it should be possible to use a ResultSet, as you tried. However, I never tried this and I think it isn't common use to do so.
Best regards,
Bart
|
 |
 |
|
|
subject: Showing results of dynamic database query in jsf
|
|
|