• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


Search.JPG
[Thumbnail for Search.JPG]
Search filter prototype
 
Pupun Moh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can someone please look into my doubt?.
I would appreciate it.

I really need some pointers to go ahead.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.
 
Pupun Moh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Amit,
Thanks for providing me information about the naming policy. I have changed my name accordingly.
 
Saloon Keeper
Posts: 28424
210
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
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.
 
Pupun Moh
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Search.JPG
[Thumbnail for Search.JPG]
 
Tim Holloway
Saloon Keeper
Posts: 28424
210
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
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 28424
210
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
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
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi , I am new here. I am having problem in creating search and filter through datatable in JSF as the picture attached below. Please help me to understand better in it and do share some code for better understanding.I tried some code in Google and somehow , I couldn't get it. Thank you.
JSF.JPG
[Thumbnail for JSF.JPG]
 
reply
    Bookmark Topic Watch Topic
  • New Topic