wood burning stoves 2.0*
The moose likes Struts and the fly likes How to retain search results Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to retain search results" Watch "How to retain search results" New topic
Author

How to retain search results

Jaffer Shareef
Greenhorn

Joined: Jun 27, 2008
Posts: 4
I have a search page where i can select some criteria, say Name: xxx and click on search which gives multiple results.
I select one of the record from search results and go to an other page.
If I come back to search page, previous search results and sorting order is cleared. How can i retain my previous search results and sorting order?

Please advise me a best solution in Struts or Jsp...

Thanks in Advance

- Jaffer.
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

When you are navigating to a different page from current search page, does it involves an action invocation.If yes,then the request object would be cleared or else if its just a page navigation it wont.
It seems the Collection of results is set to request object, which clears itself when it moves to a different action.Try binding the collection to a session object instead.


Thanks & Regards
Sidharth Pallai
vijay jamadade
Ranch Hand

Joined: May 12, 2008
Posts: 241
Hey you need to save that parameters in session and get that url that gets created when you give some input and search results are displayed. that means you need to create same url again while coming back to the search result page again. The code can be like below. add in your action class of struts

*********************************
//added by vijay jamadade for back button

String queryStringUrl=request.getRequestURI()+"?"+request.getQueryString();

emusterForm.setQueryStringUrl(queryStringUrl);

**********************************
request.getRequestURI()--- this will give you the current url you are working on and the remaining are the search criterias input


Regards, Vijay Jamadade.
( Nothing is Impossible.)
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Hi Vijay,

What is an emusterform, is it an ActionForm instance.
vijay jamadade
Ranch Hand

Joined: May 12, 2008
Posts: 241
yes it is.
Here i have set that parameters value in form and getting it.
you can use session or whatever you want
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Hi Vijay,
I didn't get any method getQueryStringURL() in ActionForm Class.Am using struts 1.2.9. Does such method is an ActionForm or any specific subclass of it.
vijay jamadade
Ranch Hand

Joined: May 12, 2008
Posts: 241
//add in action class

String queryStringUrl=request.getRequestURI()+"?"+request.getQueryString();
emusterForm.setQueryStringUrl(queryStringUrl);

create one string 'queryStringUrl' and getter setter method for this in form

*************************


//add in jsp one javascript fun
function backToSearch(){
var queryStringUrl=emusterForm.queryStringUrl.value;
emusterForm.action=queryStringUrl;
emusterForm.method="post";
emusterForm.submit();
}

//call this fun onclick of back button this fun wil get the url created in action and display the same result page

now i have given everything it must work now.

tel me if any probs
Sidharth Pallai
Ranch Hand

Joined: Apr 21, 2008
Posts: 134

Thanks,
I got it.You should have previously mentioned about it.I mistook it as inbuilt method of Struts ActionForm API.
 
GeeCON Prague 2014
 
subject: How to retain search results