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
sharmassharmas 

Page parameters lost after url refresh

Hi

 

I am working on a vf page where, if a user does some operation without selecting list of records, we need to return the same page with apex pageMessages. but, when error message is displayed after url refresh, parameters from page are lost. i.e. apex/page_name?id=xyz is returned as apex/page_name.

 

if i use setredirect(true) in controller class, then error message is not displayed.

 

Please provide a solution.

 

Thanks 

bob_buzzardbob_buzzard

This is probably because the information from the form is submitted as a post, which doesn't place any parameters on the URL.  The parameters aren't lost - the id in question will still be in the view state.

 

You should be able add the parameters that you wish to see to the PageReference that your controller is returning.

 

E.g.

 

PageReference pr=Page.page_name; 

pr.addParameter('id', theId'); 

 

 

 

sharmassharmas

Hi BobThanks for the reply. Following is the piece of code from controller class:

public PageReference methodName()

{

if(conditional)

            {

                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Error Message.');

                ApexPages.addMessage(myMsg);

                return null;

            }

}

 

Before return null, the Id is preserved. but after it, all parameters are lost. Also, if i try to use set redirect or return same page along with parameters, then Page messages are not displayed on page.

 

Let me know if there is any work around for it.

 

Thanks 

bob_buzzardbob_buzzard
Let me answer your question with a question - why do you need to retain the id on the URL?  You can store it in a property on the controller that will be preserved across page requests.
TomSnyderTomSnyder

...parameters from page are lost.

 

lost?  not completely... yes you will not see them in the url if you are using XHR (rerender=... when calling your method)  so if you are parsing the url in javascript that wont work.

 

however they should still be avail in VF using {!$CurrentPage.parameters.[nameOfparam]}

 

or in APEX using getParameters() ...

 

BTW, saving them to a variable as Bob suggested is good practice.

recio14recio14

I think the main purpose of that url parameters is for bookmarks.

The parameters helps identify the details of the page being bookmarked by the user.

 

If the user tries to acces the bookmarked page we need that parameters to identify the page contents.

tggagnetggagne

This is the problem we're having--parameters from the URL are being lost.

 

In our current case, there are two parameters, id=9393939&stepId=84848484, and the second one, stepid, is regularly trimmed off but the first is not.

 

We also want the URL unmolested so users may be able to bookmark the page.  Without the extra parameter apex will return a null reference.

 

Which is a separate question--how can I get rid of those without sites?  But I'll research that separately.