function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BrianWXBrianWX 

Setter not passing user-specified value to customer Controller

Hi,

 

This should be a basic for getting values from a Visualforce page to a custom Controller,  but for some reason I can't get this to work.  I have a very basic form with one inputTextArea.  Once a user type something in and hit Submit, a customer Controller get this value and compose a singleEmailMessage to an email address.

 

Here is my Visualforce page codes:

 

 

<apex:page Controller="ApprovalController">
<apex:sectionHeader title="Request Approval" />

<apex:form >
<apex:message />
<apex:pageBlock >
<apex:pageBlockSection columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Lead Name: " for="Name" />
<apex:outputText id="Name" value="{!Name}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Description" for="approvalDescription" />
<apex:inputTextarea id="approvalDescription" value="{!approvalDescription}" required="true" />
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
<apex:actionStatus id="status" startText="please wait..."/>
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Submit" immediate="true" action="{!submit}" status="status" />
<apex:commandButton value="Cancel" immediate="true" action="{!cancel}" status="status" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Here is my custom controller codes:

 

public with sharing class ApprovalController {

String approvalDescription;


public String getApprovalDescription() {
return approvalDescription;
}

public void setApprovalDescription(String descr) {
this.approvalDescription = descr;
}

public void sendEmail() {
Messaging.Singleemailmessage mail = new Messaging.Singleemailmessage();
String[] toAddresses = new String[] {'mailqueue@email.com'};
String strSubject = 'Approval Request';

String strBody = '<p>Approver Team:</p>';
strBody = strBody + '<p>Please review and approve</p>';

strBody = strBody + 'Request Notes: ' + approvalDescription;

mail.setToAddresses(toAddresses);
mail.setReplyTo('no-reply@email.com');
mail.setSenderDisplayName('Request User');
mail.setSubject(strSubject);
mail.setUseSignature(false);
mail.setHtmlBody(strBody);

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

} //sendEmail()

public PageReference cancel() {
PageReference pageRef = new PageReference('site.mycompany.com');
pageRef.setRedirect(true);
return pageRef;
}

public PageReference submit() {

sendEmail();

PageReference pageRef = new PageReference('site.mycompany.com');
pageRef.setRedirect(true);
return pageRef;


} //submit()
} //class

 

In my codes the setter is not able to pickup the value from the inputTextarea.  The approvalDescription is always null.  What did I do wrong?

 

Thank you for taking time and provide feedback.

 

Brian

BrianWXBrianWX

To be more specific, this line of codes should display the value from the inputTextarea, but Not:

 

strBody = strBody + 'Request Notes: ' + approvalDescription;

 

approvalDescription is always null.

Shailesh DeshpandeShailesh Deshpande

HI Brian,

 

You will need to declare the variable as below:

 

public String approvalDescription {get;set;}

 

Only then you will be able to bind the value in your page with the variable in the conroller.

 

Thanks,

Shailesh.

BrianWXBrianWX

Thank you.  I should have know this.