You need to sign in to do that
Don't have an account?

hope to keep a random number
hi all
i have a question.
now i develop a calculating application by using visualforce.
in a page, i get two random numbers, click "add" button and then add them in a next page.
but i can't keep random numbers in a next page.
how can i keep random numbers in a next page?
now this is code.
「add page(visualforce)」
<apex:page Controller="MathController">
{!RandomNumber1} + {!RandomNumber2} = <br/>
<apex:form >
<apex:commandButton value="answer" action="{!Answer}" />
</apex:form>
</apex:page>
「MathController」
public class MathController {
public double getRandomNumber1() {
double ran1 = Math.round(Math.random()*100);
return ran1;
}
public double getRandomNumber2() {
double ran2 = Math.round(Math.random()*100);
return ran2;
}
public PageReference Answer() {
PageReference secondPage = Page.answer;
secondPage.setRedirect(true);
return secondPage;
}
public double getAddNumber() {
//this AddNumber method has not been completed.
double ans = ran1 + ran2;
return ans;
}
}
「answer page(visualforce)」
<apex:page Controller="MathController">
The answer is {!AddNumber}.<br/>
</apex:page>
Change the statement secondPage.setRedirect(true); to secondPage.setRedirect(false); within your Answer method.
This will maintain view state between pages.
All Answers
Change the statement secondPage.setRedirect(true); to secondPage.setRedirect(false); within your Answer method.
This will maintain view state between pages.
hi John
Thank you for your reply.
Your idea has solved my question.
Thank you very much!