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
shephalishephali 

sending data

hello friends,
I need to send an calculated integer number of VF1 page to VF2 page on button click.how to achieve this??
KaranrajKaranraj
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

Visualforce tag Example
<apex:page > 
<apex:outputlink value="/apex/VF2"> Click Here 
<apex:param name="amt" value="2"/> 
</apex:outputlink> 
</apex:page>
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:outputField value="{!$CurrentPage.parameters.amt}"/>

Apex controller example

Passing parameter value using controller method
public Pagereference gotonewpage()
{     
     PageReference pageRef = Page.VF2;
     pageRef.getParameters().put('amt','2');
     return PageRef
}
Getting the visualforce page parameter value in the controller class
String message = System.currentPagereference().getParameters().get('amt');


 
shephalishephali
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;
}

}