+ Start a Discussion
raju123raju123 

Calculate Fields in one page display in Next page

Hi,

 

       Can anybody help me on this Simple Requirement.Please provide me Code

 

I have 2 Visual force pages.

one page contains A,B Fields

in Second page i want sum of a+b and display it in c field.

Plese Help me in this Requirement. 

 

Best Answer chosen by Admin (Salesforce Developers) 
kiranmutturukiranmutturu

page1

 

<apex:page controller="add" >
<apex:form >

A : <apex:inputText id="a" value="{!a}"/>
B : <apex:inputText id="b" value="{!b}"/>

<apex:commandbutton value="Result" action="{!result}" />
</apex:form>


</apex:page>

 

page 2

 

<apex:page >
Sum is : {!$CurrentPage.parameters.val}
</apex:page>

 

class:

 

public class add{

public integer a {get;set;}

public integer b {get;set;}


public pagereference result(){

pagereference pf = new pagereference('/apex/second2?val='+(a+b));
pf.setredirect(true);
return pf;

}


}

All Answers

bob_buzzardbob_buzzard

If you use the same controller for both pages, you can calculate the result when page A is submitted back and store this on the controller for use in page B.

raju123raju123

could you please send me code

 

 

raju123raju123

i am unable to convert string  to integer  getting this error  "System.NullPointerException: Attempt to de-reference a null object
"

kiranmutturukiranmutturu

page1

 

<apex:page controller="add" >
<apex:form >

A : <apex:inputText id="a" value="{!a}"/>
B : <apex:inputText id="b" value="{!b}"/>

<apex:commandbutton value="Result" action="{!result}" />
</apex:form>


</apex:page>

 

page 2

 

<apex:page >
Sum is : {!$CurrentPage.parameters.val}
</apex:page>

 

class:

 

public class add{

public integer a {get;set;}

public integer b {get;set;}


public pagereference result(){

pagereference pf = new pagereference('/apex/second2?val='+(a+b));
pf.setredirect(true);
return pf;

}


}

This was selected as the best answer
raju123raju123

Thank you very much Kiran . Thank you

 

kiranmutturukiranmutturu

inputfiled is always accept the value  there u wont get the value from that object u need to use outputfield 

raju123raju123

OK.THANK YOU VERY MUCH