+ Start a Discussion
prakashedlprakashedl 

Pass Values from VF page A to VF page B without using query params

Hi All, 

I am a newbie to salesforce. I would appreciate, if someone could help me with this. I have two visual force pages A and B. They both use common custom controller. VF page B should access the values set by VF page A. However, I do not want to pass values using apex:param, since I do not want the end user to see the values in query parameters. Is there any way I can access since both pages use the same custom controller?

 

VF Page A

------------

 

<apex:page controller="customcontroller">
<apex:commandButton action="{!gotoNextPage}" value="Next Page"/>
</apex:page>

 

VF Page B (/apex/pageB)

----------------------------

<apex:page controller="customcontroller">
Test Value :{!testValue}
</apex:page>

 

customcontroller

-------------------

 

public String testValue { get; set; }

public PageReference gotoNextPage() {
testValue='TestValue set in VF page A';
// set the next page to VF page B
PageReference page = new PageReference('/apex/pageB');
return page;
}


Hence, when I navigate to pageB, I would like to see Test Value:TestValue set in VF page A. Again, I don't want the URL to be /apex/pageB?testValue='TestValue set in VF page A'. Is it possible to do using VF or apex? I might be missing something simple as well. Thanks for your time to help me.

 

 

http://www.edlconsulting.com

 

 

 

 

 

Message Edited by prakashedl on 11-13-2009 02:32 PM
Best Answer chosen by Admin (Salesforce Developers) 
XactiumBenXactiumBen

Just a shot in the dark here but is

 

PageReference page = Page.pageB;

any different to:

PageReference page = new PageReference('/apex/pageB');

?

 

Whenever I'm linking pages in this way I use the first method to generate a page reference.  I'm wondering if the second way (your way) forces the page to create a new instance of your controller instead of reusing the same one.

Message Edited by XactiumBen on 08-28-2009 04:12 PM

All Answers

srisomsrisom

Hi,

 

If your two pages use the same controller then all you have to do is set a class variable as you have done.  This won't go via the URL.

 

Is your code not working ?

prakashedlprakashedl

Hi,

I am not getting any value in the VF page B at all. It is just a blank string ' '.

 

Thanks

srisomsrisom

Can you try this:

 

get rid of  'testValue =' line in custom controller

replace {!testValue} with <apex:outputText value="{!testValue}"/> in second page

above the command button put

<apex:inputText value="{!testValue}"/> in first page


Run it.  Then fill in the box on the first page and click the button.  You should get the value in the second ?

aballardaballard

As long as the controller is the same for both pages it should work. 

 

I just tried using the code from your message (with addition of <apex:form> which is needed for pageA to save)

and it worked as expected.   

 

You must be doing something different in your actual test case.

XactiumBenXactiumBen

Just a shot in the dark here but is

 

PageReference page = Page.pageB;

any different to:

PageReference page = new PageReference('/apex/pageB');

?

 

Whenever I'm linking pages in this way I use the first method to generate a page reference.  I'm wondering if the second way (your way) forces the page to create a new instance of your controller instead of reusing the same one.

Message Edited by XactiumBen on 08-28-2009 04:12 PM
This was selected as the best answer