You need to sign in to do that
Don't have an account?
Mia P
Need help on my First VF Page and Class!
Hi All,
I am trying to create my first VF page and Controller class. I need help for further enhancements please.
I need help with the following:
VF Page:
<apex:page controller="firstcls">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:commandButton value="Add" action="{!Addnumbers}"/>
<apex:commandButton value="Subtract" action="{!SubtractNumbers}"/>
<apex:commandButton value="Multiply" action="{!Multiplynumbers}"/>
<apex:commandButton value="Divide" action="{!Dividenumbers}"/>
<apex:commandButton value="Back" action="{!getBack}"/> //Not sure if, its right or wrong?
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:outputLabel value="Enter First Number"/>
<apex:inputtext value="{!firstNumber}"/>
<apex:outputLabel value="Enter Second Number"/>
<apex:inputtext value="{!secondNumber}"/>
<apex:outputLabel value="Result"/>
<apex:inputText value="{!result}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
CLASS:
public class firstcls {
public string firstNumber {get;set;}
public string secondNumber {get;set;}
public string temp;
public string result {get;set;}
public firstcls ()
{
//firstNumber = '0';
//secondNumber = '0';
result = '0';
}
public void Addnumbers()
{
result = string.valueof(Integer.valueof(firstNumber) + Integer.valueof(secondNumber));
}
public void SubtractNumbers()
{
result = string.valueof(Integer.valueof(firstNumber) - Integer.valueof(secondNumber));
}
public void Multiplynumbers()
{
result = string.valueof(Integer.valueof(firstNumber) * Integer.valueof(secondNumber));
}
public void Dividenumbers()
{
result = string.valueof(Integer.valueof(firstNumber) / Integer.valueof(secondNumber));
}
public PageReference getBack()
{
PageReference ref= new PageReference('/'+00B61000002AkLf);
ref.setredirect(true);
return ref;
}
}
When I am trying to save the above class, I am getting this error-
Error: firstcls Compile Error: expecting a right parentheses, found 'B61000002AkLf' at line 39 column 47
I need guidance on this. Look forward for your helpful replies.
Thanks.
I am trying to create my first VF page and Controller class. I need help for further enhancements please.
I need help with the following:
- When I hit that "Back" command button - it should redirect to a custom object page, lets say - "Employee__c".
- Also, a custom page message should come up if any of the numbers/ text not filled (please see screenshot).
- where and how to add the following:
if(firstNumber == '' || firstNumber == null || secondNumber == '' || secondNumber == '')
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter First and Second numbers'));
VF Page:
<apex:page controller="firstcls">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:commandButton value="Add" action="{!Addnumbers}"/>
<apex:commandButton value="Subtract" action="{!SubtractNumbers}"/>
<apex:commandButton value="Multiply" action="{!Multiplynumbers}"/>
<apex:commandButton value="Divide" action="{!Dividenumbers}"/>
<apex:commandButton value="Back" action="{!getBack}"/> //Not sure if, its right or wrong?
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:outputLabel value="Enter First Number"/>
<apex:inputtext value="{!firstNumber}"/>
<apex:outputLabel value="Enter Second Number"/>
<apex:inputtext value="{!secondNumber}"/>
<apex:outputLabel value="Result"/>
<apex:inputText value="{!result}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
CLASS:
public class firstcls {
public string firstNumber {get;set;}
public string secondNumber {get;set;}
public string temp;
public string result {get;set;}
public firstcls ()
{
//firstNumber = '0';
//secondNumber = '0';
result = '0';
}
public void Addnumbers()
{
result = string.valueof(Integer.valueof(firstNumber) + Integer.valueof(secondNumber));
}
public void SubtractNumbers()
{
result = string.valueof(Integer.valueof(firstNumber) - Integer.valueof(secondNumber));
}
public void Multiplynumbers()
{
result = string.valueof(Integer.valueof(firstNumber) * Integer.valueof(secondNumber));
}
public void Dividenumbers()
{
result = string.valueof(Integer.valueof(firstNumber) / Integer.valueof(secondNumber));
}
public PageReference getBack()
{
PageReference ref= new PageReference('/'+00B61000002AkLf);
ref.setredirect(true);
return ref;
}
}
When I am trying to save the above class, I am getting this error-
Error: firstcls Compile Error: expecting a right parentheses, found 'B61000002AkLf' at line 39 column 47
I need guidance on this. Look forward for your helpful replies.
Thanks.
Here you need to make your number as sting and then you can successfully pass it
Use the below code
And you are done!!!!!!!!!!
Mark it as best answer if it solves your problem
All Answers
Here you need to make your number as sting and then you can successfully pass it
Use the below code
And you are done!!!!!!!!!!
Mark it as best answer if it solves your problem
How about the 2nd requirement about the page message?
2)a custom page message should come up if any of the numbers/ text not filled (please see screenshot in the main question).
where and how to add the following?
if(firstNumber == '' || firstNumber == null || secondNumber == '' || secondNumber == '')
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter First and Second numbers'));
Insert the below tag inside the visualforce page within page block