function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nisar AhmedNisar Ahmed 

Passing a string parameters in URL and using it in a VF page.

Hi All,

 

I have 2 VF pages :

'Locator' and 'TimeAvail'.

 

'Locator' page contains a text box and search button, where we enter a value in text box and click on 'Search' button resulting in a list of results. Upon clicking one of the search result, it directs us to the 'TimeAvail' page.

 

Now the 'TimeAvail' page contains a 'Go Back' button. On clicking this 'Go Back' button, it redirects us back to 'Locator' page.

 

Problem:

'Go Back' button just redirects to the 'Locator' page. But, I want the 'Go Back' button to redirect to 'Locator' page and should also retain the search results that we got earlier in the 'TimeAvail' page upon entering a value in text box and clicking on 'Search' button. 

 

I have stuck here. Please let me know if you have any idea or information to solve this.

 

 

Thanks and Regards,

Nisar Ahmed

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

So assuming you have passed the search string on the URL as 'MySearchString', you should be able to add the following code just before the return statement to add the parameter to the goback request:

 

 

String searchStr=ApexPages.currentPage().getParameters().get('MySearchString');

pageRef.getParameters().put('MySearchString', searchStr);

 

 

All Answers

bob_buzzardbob_buzzard

Are you using the same controller to back the two pages? If so, you could retain the information inside the controller as long as you redirect the user server side rather than allowing them to click straight through on links.

 

If you aren't (which is more likely), you'll need to pass the information to the TimeAvail page on the URL and make sure its added to the URL for the go back button.  You'll also need to change you controller on the Locator page so that if the text value is present on the URL, the search gets run from the constructor or page action, so that the results are displayed as soon as the user hits the page.

Nisar AhmedNisar Ahmed

Hi Bob,

 

Yes, I am using separate controllers for both the pages.

 

Here is the snippet which redirects to the Locator page : 


/* Snippet to redirect present on the TimeAvail page controller */

 

public PageReference onGoBack(){
    PageReference pageRef = new  PageReference('/apex/Locator');
    pageRef.setRedirect(True);
    return pageRef;
}

/* Snippet ends */   

 

  

I want to do modification on this piece of code. Please provide me a solution to reference the URL.

 

Thanks and Regards,

Nisar Ahmed

 

bob_buzzardbob_buzzard

So assuming you have passed the search string on the URL as 'MySearchString', you should be able to add the following code just before the return statement to add the parameter to the goback request:

 

 

String searchStr=ApexPages.currentPage().getParameters().get('MySearchString');

pageRef.getParameters().put('MySearchString', searchStr);

 

 

This was selected as the best answer
Nisar AhmedNisar Ahmed

Hi Bob,

 

Could please let me know or give an example for what is to be done in the Locator page controller.

 

 

Thanks & Regards,

Nisar Ahmed

bob_buzzardbob_buzzard

In your constructor, you'd retrieve the search term in the same way as earlier, and then execute the search server side, populating the results as though the user had clicked the search button.

 

I can't really give you much more information than that, as it all depends on how you are currently executing the search etc.

Nisar AhmedNisar Ahmed

 

Thanks Bob.

 

bob_buzzardbob_buzzard

For anyone who hits this thread with a similar requirement, I posted an article explaining how to achieve this on my blog at:

 

http://bobbuzzard.blogspot.com/2011/06/execute-custom-search-when-opening-page.html