aspose file tools*
The moose likes JSF and the fly likes Help Needed: Search/Filter on a Datatable for displaying records. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Help Needed: Search/Filter on a Datatable for displaying records." Watch "Help Needed: Search/Filter on a Datatable for displaying records." New topic
Author

Help Needed: Search/Filter on a Datatable for displaying records.

Pupun Moh
Greenhorn

Joined: Apr 14, 2009
Posts: 14
Hi,
I have a requirement of implementing Search and Filter over a datatable.
The datatable I am using has 5 columns Name, Surname, State, Dept, Location.

The requirement goes as, there would be a input text box for writing the searchable record and a drop-down menu beside it which will automatically take the column names as its values. This drop-down will act a filter.

One would type a record and select the column from the drop down where it has to be searched and click Search button. If found then the record is displayed in the datatable and if not then "No records found" will be displayed.
Again the Search will not retrieve records from the database, but only the records which are presesnt in the memory based on which the datatable is formed.

Ihave attached a picture of the requirement.
Please help me and provide me suggestions/code samples as how to proceed.

Regards,
Awe





[Thumbnail for Search.JPG]

Pupun Moh
Greenhorn

Joined: Apr 14, 2009
Posts: 14
Can someone please look into my doubt?.
I would appreciate it.

I really need some pointers to go ahead.
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

"Awe Striker " welcome to Javaranch
please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.


SCJP, SCWCD.
|Asking Good Questions|
Pupun Moh
Greenhorn

Joined: Apr 14, 2009
Posts: 14
Hi Amit,
Thanks for providing me information about the naming policy. I have changed my name accordingly.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

Thanks for fixing your display name.

The key thing to understand is that the JSF DataModel isn't necessarily supposed to simply act as a fa├žade for a database table. It's actually literally the model in the JSF Model/View/Controller scheme. You can refine the view by constructing a new ordered collection object (such as a List), adding ONLY the elements you want displayed to the collection, then wrapping that collection to produce the JSF DataModel. The original table is unaffected, since membership in a collection only means that the collection knows about its content items rather than actually owning those items.


Customer surveys are for companies who didn't pay proper attention to begin with.
Pupun Moh
Greenhorn

Joined: Apr 14, 2009
Posts: 14
Hi Tim,
Thanks for the reply. I appreciate it.
For the UI part, will developing a custom component be of any help? The custom component will have a datatable, input text box, drop down menu and a command button as show in the attached picture.
Please provide me links/pointer where I can similar custom component.

Now the search has to be done on the datatable which is currently in the memory, rather than fetching the result from database. Moreover the search criteria contains column name and row data. How can I perform the search in this scenario?
Will ResultSet which has been used to retrieved the table be of any use?

Rgrds,
Pupun


[Thumbnail for Search.JPG]

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

You could develop a custom component, but it's probably not worth the extra work. Unless you expect to do lots of displays like this one. Otherwise it's easier to just build up out of primitive components.

Repeating, the JSF DataModel does not have to be directly attached to the underlying data. You can design business logic to build a list that contain only the rows that you select from the base data and wrap that to create the DataModel. Whether the base data is a in-memory table or is built from JDBC or other persistence logic doesn't have any effect on the display list.
Pupun Moh
Greenhorn

Joined: Apr 14, 2009
Posts: 14
Hi Tim,
Now it has given me some clear picture about the Datamodel.....but alas I have to go for a custom component for Datatable which should have the componets as in the picture.
Can you please guide me on it?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

There are several ways to make a custom component. The easiest one is if you're using Facelets, in which case you can build them out of xhtml. I do that on a project I'm working on now.

If you're not using Facelets, you may be able to do something similar using regular JSP includes.

A JSF custom component is another matter. If you haven't done custom JSP tags, learn to do them first. JSF custom tags are a lot like JSP tags, except that they have some additional requirements, For one thing, JSF tag implementations separate the rendering code from the logic, since JSF is supposed to support multiple rendering systems, not just HTML.

This isn't a simple task, which is why I advise against it unless you intend to use this control in more than one place. I used Kito Mann's JavaServerFaces In Action book as my guideline when creating a custom JSF tag, but even then it was a bit of a challenge.
Pupun Moh
Greenhorn

Joined: Apr 14, 2009
Posts: 14
Yeah I understand the difficulties but anyway one or the other day I had to face it. So I have to ramp up on the tag thing. Will try to get hold of the book and do some practice this weekend.
It would be really helpful if you can give some links or pointers where I can get some examples/codes on it.
ashok chittela
Greenhorn

Joined: Dec 09, 2009
Posts: 2
Hi Pupan,

I know it's been long time that you posted this thread. In my current project i have to develop kind of something just want to check with you, if you have developed this search component. I already have a data table and i need a search for this table to filter the records. Appreciate your help.

Thanks,
Ashok
 
wood burning stoves
 
subject: Help Needed: Search/Filter on a Datatable for displaying records.