• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to retain search results

 
Jaffer Shareef
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
Hibernate Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vijay jamadade
Ranch Hand
Posts: 243
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sidharth Pallai
Ranch Hand
Posts: 134
Hibernate Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vijay,

What is an emusterform, is it an ActionForm instance.
 
vijay jamadade
Ranch Hand
Posts: 243
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
Hibernate Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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
Posts: 134
Hibernate Java Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,
I got it.You should have previously mentioned about it.I mistook it as inbuilt method of Struts ActionForm API.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic