You need to sign in to do that
Don't have an account?
nduch
How to get user input from Visualforce to Apex
Hi,
I have a text field in Visualforce that display email template automatically to the user.
<apex:inputTextarea value="{!templateBody}" />
The user then edits the text and clicks on a button. What I want to do is - when the user clicks on the button I want to get the user input to Apex. How can I do that?
I suppose I have to use setter method for templateBody Apex variable, but I dont know how to reference the inputTextarea field.
Many thanks for help!
HI John,
since my controller is an extension of the standard controller, I have overriden the save() method with new functionality AND the previous functionality stayed, i.e. It is saving the user input PLUS doing what I have in my save() method.
Hard to understand for me at first, sorry!
Many thanks for the help!:smileyhappy:
All Answers
Hi, you are on the right track.
You just need a setter method in the page controller.
There is an example in the VF docs here:
http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_controller_methods.htm
Hope that helps,
-cj
HI John,
I have a set method for this variable, but I dont know how can I invoke it in the button's code:
This is my setter:
public void setTemplateBody(String s) {
templateBody= s;
}
I need something like this in the button's code:
this.setTemplateBody(user input from inputTextArea field);
But I dont know how to get the String argument for the setter method.
Or do I have to call the controller.getRecord() method to get the user input?
Check out the 'Action Methods' section of that doc link.
You can specify a controller method to invoke on clicking the button, e.g. to call a 'save' method:
I need this button to do more than just save. Therefore I cannot use the controller's save method.
I want the button to save + create an email from the user input + send the email.
Thank you for your understanding.
The example in the docs was to call a save method, but you can define whatever logic you need in a controller method and call that as the action on the button click.
Hope that helps.
But how to write a controller method that would save user input + do more actions?
HI John,
since my controller is an extension of the standard controller, I have overriden the save() method with new functionality AND the previous functionality stayed, i.e. It is saving the user input PLUS doing what I have in my save() method.
Hard to understand for me at first, sorry!
Many thanks for the help!:smileyhappy: