+ Start a Discussion
shinerajbshinerajb 

Issue in value passing

Hai,


I have 2 VF pages and 1 controller, from first page I want to pass 3 values from javascript to my controller class,from there I want to display the result in a new page

 

 

*******First VF page******

 

<script type="text/javascript">

function callActionMethod()
{
var txtVal0 = include;
var txtVal1 = include1;
var txtVal2 = include2;
echo(txtVal0,txtVal1,txtVal2);
}
</script>

 

<b> <span onclick="callActionMethod()" style="color:red;cursor:pointer"> Generate>>> </span></b>
<apex:actionFunction name="echo" action="{!echoVal}" reRender="resultPanel" status="myStatus">
<apex:param name="firstParam" value="" />
<apex:param name="secondParam" value="" />
<apex:param name="thirdParam" value="" />
</apex:actionFunction>

 

*********controller page************

 

 

public void echoVal()
{
val = Apexpages.currentPage().getParameters().get('firstParam');
val1= Apexpages.currentPage().getParameters().get('secondParam');
val2 = Apexpages.currentPage().getParameters().get('thirdParam');

}

 

I want to display these values in a ne VF page.I tried it by using page redirect method,but I got the values as null.But if I am displaying these 3 values in my first page,its comming correctly.What is the issue with my code

So please suggest me a solution

 

 

 

Shine

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

In your controller method, you'd have something like:

 

public void echoVal()
{
   val = Apexpages.currentPage().getParameters().get('firstParam');
   val1= Apexpages.currentPage().getParameters().get('secondParam');
   val2 = Apexpages.currentPage().getParameters().get('thirdParam');

   PageReference pr=Page.myPage;

   myPage.getParameters().put('val', val);
   myPage.getParameters().put('val1', val1);
   myPage.getParameters().put('val2', val2);

myPage.setRedirect(true)
return myPage; }

 

 

 

All Answers

bob_buzzardbob_buzzard

Once you have the values server side in the action method, if you want to pass them to the new page you need to store them in the controller or add them to the URL and use the setRedirect on the returned pagereference.

shinerajbshinerajb

Hi bob,

 

Actually I am using these 3 values for checking some conditions in the controller,and I want to display the corresponding result in the new page.

And another issue is that,when I am removing the rerender in actionFunction function,I am getting the value in controller as null.

Can u please suggest me a solution,

 

Shine

bob_buzzardbob_buzzard

The same principal applies - you have submitted those values to the controller, and if you want the result available to the new page you can either save it in the controller or pass it on the URL if redirecting.

 

Removing rerender does break parameter passing - I've never seen any explanation of this, I've always assumed it changes it from an ajax request to a straightforward postback and somehow loses them.

shinerajbshinerajb

Hai,

 

How can we pass these javascript values in url

bob_buzzardbob_buzzard

In your controller method, you'd have something like:

 

public void echoVal()
{
   val = Apexpages.currentPage().getParameters().get('firstParam');
   val1= Apexpages.currentPage().getParameters().get('secondParam');
   val2 = Apexpages.currentPage().getParameters().get('thirdParam');

   PageReference pr=Page.myPage;

   myPage.getParameters().put('val', val);
   myPage.getParameters().put('val1', val1);
   myPage.getParameters().put('val2', val2);

myPage.setRedirect(true)
return myPage; }

 

 

 

This was selected as the best answer
shinerajbshinerajb

Hai,

 

I am still getting the value as null.What change I have to do in my code?

Please help me in this issue,its  very urgent one for me

 

 

*******First VF page******

 

<script type="text/javascript">

function callActionMethod()
{
var txtVal0 = include;
var txtVal1 = include1;
var txtVal2 = include2;
echo(txtVal0,txtVal1,txtVal2);
}
</script>

 

<b> <span onclick="callActionMethod()" style="color:red;cursor:pointer"> Generate>>> </span></b>
<apex:actionFunction name="echo" action="{!echoVal}" >
<apex:param name="firstParam" value="" />
<apex:param name="secondParam" value="" />
<apex:param name="thirdParam" value="" />
</apex:actionFunction>

 

******controller*****

public PageReference echoVal()
{
val = Apexpages.currentPage().getParameters().get('firstParam');
val1= Apexpages.currentPage().getParameters().get('secondParam');
val2 = Apexpages.currentPage().getParameters().get('thirdParam');

PageReference pr=Page.generate;

pr.getParameters().put('val', val);
pr.getParameters().put('val1', val1);
pr.getParameters().put('val2', val2);
pr.setRedirect(true);
return pr;
}

 

*********second page*****

 

<apex:form >
<apex:outputPanel id="resultPanel">
<br />
<b><apex:outputLabel value="{!val}" /></b>
</apex:outputPanel>
</apex:form>

shinerajbshinerajb

Thanks Bob_buzzard I got the solution