I'm currently using appFuse with webwork + spring + hibernate.
I'm using displaytag to display tables of data for a variety of my hibernate
objects.
I'm looking for a best practice or existing library to help me implement a
search feature for the data I'm displaying in the display tag tables.
Currently, we just do a list of the objects resulting from a simple
hibernate find. I'd like a way to add a search function so I can display in
the table values that match by specified criteria.
For example, I have a hibernate object somewhat like
class Client {
String id;
String firstName;
String lastName;
Timestamp lastUpdated;
boolean public;
}
I'd like to add a search form at the top of the page formatted in such a way
that the action that receives the request can easily transform the Request
parameters into a hibernate Criteria object.
I can see a form something like this
<form name="searchClients" action="searchClients">
<!-- some input to indicate what hiberate object to search on, or this could
go in the action code -->
<input type="hidden" name="type" value="Client" />
First Name:
<Select name="restriction_firstName">
<Option value="like">like</Option>
<Option value="eq">equals</Option>
<Option value="gt">greater than</Option>
<Option value="lt">less than</Option>
<Option value="in">in</Option>
<Option value="isNull">is null</Option>
<Option value="isNotNull">is not null</Option>
<Option value="startsWith">starts with/Option>
<Option value="endsWith">starts with/Option>
</Select>
<input type="text" name="query_firstName" value="" >
Last Name:
<Select name="restriction_lastName">
<Option value="like">like</Option>
<Option value="eq">equals</Option>
<Option value="gt">greater than</Option>
<Option value="lt">less than</Option>
<Option value="in">in</Option>
<Option value="isNull">is null</Option>
<Option value="isNotNull">is not null</Option>
<Option value="startsWith">starts with/Option>
<Option value="endsWith">starts with/Option>
</Select>
<input type="text" name="query_lastName" value="" >
... <!-- dates would probably have some special handling or something -->
Last Updated
<Select name="restriction_lastUpdated">
<Option value="like">like</Option>
<Option value="eq">equals</Option>
<Option value="gt">greater than</Option>
<Option value="lt">less than</Option>
<Option value="in">in</Option>
<Option value="isNull">is null</Option>
<Option value="isNotNull">is not null</Option>
<Option value="startsWith">starts with/Option>
<Option value="endsWith">starts with/Option>
</Select>
<input type="text" name="query_lastUpdated" value="" >
</form>
So the input request could look like:
restriction__firstName=eq
query__firstName=John
restriction_lastName=like
query_lastName=Wal
And this would transform into sql:
select * from Clients where firstName = 'John' and lastName like '%Wal%'
The query_ parameter could support or, so a user could input "John or James"
restriction__firstName=eq
query__firstName=John or James
restriction_lastName=like
query_lastName=Wal
And this would transform into sql:
select * from Clients where (firstName = 'John' or firstName = 'James') and
lastName like '%Wal%'
The library that the form is submitted to, would then transform these inputs
into a hibernate criteria, likely using the hibernate Restrictions class. I
can see some sort of method going through each restriction_ and then getting
the query_ arg (if it's a binary restriction).
All kinds of things could be added to this: order by, sub queries, etc. It
basically requires some standard format for the input, and a library to
transform the http request parameters in to the hibernate criteria.
So my ultimate question, since I have no desired to reinvent the wheel, is
does something like this already exist? Does something exists that
accompolishes basically what I want?
Thanks,
Skip Walker
--
View this message in context:
http://www.nabble.com/html-search-form-for-hibernate-managed-object-Displaytag-displayed-data---Looking-for-Best-Practices-tf2822969s2369.html#a7879468
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]