There are two methods to send value from one Visualforce page to another visualforce. You can send using the visualforce tag or you can also send from ape controller class also
Hello Karanraj, Thanx for response! In your apex controller example you are sending a value "2" to variable "amt".my requirement is to send a value which is calculated in one controller class.here is my code.i have a common controller "sharecontroller" between two VF pages. In 1st VF page i am sending index(calculated value) to another vfpage public with sharing class sharecontroller { Mobile_Agent__c agent; Integer index=0; String msg=null; public sharecontroller(ApexPages.StandardController con) { agent=(Mobile_Agent__c)con.getRecord(); }
public Pagereference sendcode() { double y = Math.random() ;//something between 0 and 999999 y = 999999 * y; index = math.round(y);///This index value i want to send. PageReference pageRef = Page.opptystep2; pageRef.getParameters().put('index1','index'); return PageRef; } public String getmsg() { msg = System.currentPagereference().getParameters().get('index1'); return msg; } public PageReference save() { if(agent!=null) insert agent; PageReference pr=new PageReference('/apex/opptystep3'); pr.setRedirect(true); return pr; }
Visualforce tag Example Using the apex:param tag you can able to pass value to another VF page easily
Getting the value from the parameter using visualforce tag
Apex controller example
Passing parameter value using controller method Getting the visualforce page parameter value in the controller class
Thanx for response!
In your apex controller example you are sending a value "2" to variable "amt".my requirement is to send a value which is calculated in one controller class.here is my code.i have a common controller "sharecontroller" between two VF pages. In 1st VF page i am sending index(calculated value) to another vfpage
public with sharing class sharecontroller
{
Mobile_Agent__c agent;
Integer index=0;
String msg=null;
public sharecontroller(ApexPages.StandardController con)
{
agent=(Mobile_Agent__c)con.getRecord();
}
public Pagereference sendcode()
{
double y = Math.random() ;//something between 0 and 999999
y = 999999 * y;
index = math.round(y);///This index value i want to send.
PageReference pageRef = Page.opptystep2;
pageRef.getParameters().put('index1','index');
return PageRef;
}
public String getmsg()
{
msg = System.currentPagereference().getParameters().get('index1');
return msg;
}
public PageReference save()
{
if(agent!=null)
insert agent;
PageReference pr=new PageReference('/apex/opptystep3');
pr.setRedirect(true);
return pr;
}
}