It's not a secret anymore!
The moose likes Struts and the fly likes Struts: search page functionality Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts: search page functionality" Watch "Struts: search page functionality" New topic

Struts: search page functionality

Mike Himstead
Ranch Hand

Joined: Apr 12, 2006
Posts: 178

I'm working on a web app making use of Struts 1.1 and JSTL 1.0. One of my tasks is to
implement a search form that will display search results. A search result is basically a file stored in a database. These search results have to offer two additional user actions each: a link for downloading the specific file (the search results contain the files DB id) and a user-specific link to delete the file. The search and display logic is more or less done (the search results are put in request in search action). I do have a problem with something I'd call standard behavior at search pages: if a user chooses to delete a file (I intend to offer an action for this) I think it is standard to show the result list afterwards again. This means that I have to re-run the search again and I need access to the search form search values. Right now I do something like this:

This snippet is inside the search form tags, by the way. The problem is that the only value I can access in the appropriate "DeleteAction" is the protocolId, not the search form's values, so I can't re-run the search. The basic problem is the very same if the user hits the download link leading to a download action: when the download action is done the search results are gone. I am very grateful if you can give me tips and hints for this.

By the way, are there special Struts/JSTL tags for downloads?

PS: couldn't check the FAQ because it's under maintenance

[ October 12, 2007: Message edited by: Mike Himstead ]

[ October 12, 2007: Message edited by: Mike Himstead ]
[ October 12, 2007: Message edited by: Mike Himstead ]
John Simpson

Joined: Sep 10, 2007
Posts: 25
Although it can be somwhat complex and time consuming, one solution that I believe could be useful here is Ajax/Javascript.

Once the delete Action takes place, call an event that will submit a request to the SearchAction asynchronously then update the display with the results.

Might not be the best approach, but it seems to be more and more common these days. I've been reading up on it recently.

Hope it helps!
Chris Boldon
Ranch Hand

Joined: Aug 10, 2006
Posts: 190
Populate a div with the search results. Then when you delete or make a change refresh the div.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I have typically stored the form that has the search criteria values in the session. Then when you need to refresh the search page you can pull the form out of the session and rerun the same query. This help out with basic edit flow as well so you can rebuild the search results page after the user edits an item.

- Brent
Mike Himstead
Ranch Hand

Joined: Apr 12, 2006
Posts: 178
Hi again,

thank you very much for your answers. Please allow to let me make additional comments:

- Ajax is no option because of lack of time, my own experience (the lack thereof) and project requirements.

- When you store the search results in the session the page will display search results when the user leaves the page and returns later on. The search form containing the search parameters is stored in request only and outside of the form, so the page would display results without parameters. A solution could be to put the search results inside the form and store the form in the session. So far I hesitated to populate the session with too much data, but I can't name specific reasons apart from a obscure fear of a possible performance bottleneck.

I experimented with three different actions (and Action classes) for searching, deleting and downloading, each class populating the same form. Could it be that one gets a new form instance for every action? After searching the form is completely empty when entering the downloading action.

Any more comments are welcome.
[ October 12, 2007: Message edited by: Mike Himstead ]
I agree. Here's the link:
subject: Struts: search page functionality
jQuery in Action, 3rd edition