You need to sign in to do that
Don't have an account?
SDFC FirstLeveler
I want to show result on same Visual force page on a button click
Controller Class : public Class a { public integer userinput{get; set;} public void getclickMe(){ string n; if (userinput> 0){ n= 'No is Positive'; } else if (userinput< 0){ n= 'No is Negative'; } else{ n='Number is zero'; } } } VFPage: <apex:page controller="a"> <apex:form > <apex:pageBlock title=" Take Input"> <apex:pageBlockSection > <apex:outputLabel value="Enter Number" /> <apex:inputText value="{!userinput}" /> </apex:pageBlockSection> <apex:pageBlockSection > <apex:commandButton value="Find" action="{!getclickMe}"/> <apex:outputPanel > <apex:outputText value="{!clickMe}"> </apex:outputText> </apex:outputPanel> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
There were a couple of mistakes in your code -
If we want to display something in Visualforce page, we need to create properties ( get set variables ) and use them with the help of merge fields in the Visualforce markup. In your case, the result is being stored into a private variable and it is not a property.
Hence to display this result in the Visualforce page -
Here is how the Apex and the Visualforce code will look like -
VisualforceApex Controller
Feel free to ask if you have any more doubts.
Now I want to run this code with same VFPage and iam geting error "Formula Expression is required on the action attributes.". Please guide