You need to sign in to do that
Don't have an account?
Jancy Mary
How to access non getter setter variables from Controller on VF Page?
Hello All,
Need some information, suppose I have 2 fields called Age & DOB in a controller, these are not a getter setter fields, I have a button on the VF page, when I click the button these fields should get loaded to the page, how to achieve this.
Thanks in advance.
Jancy
Need some information, suppose I have 2 fields called Age & DOB in a controller, these are not a getter setter fields, I have a button on the VF page, when I click the button these fields should get loaded to the page, how to achieve this.
Thanks in advance.
Jancy
Visualforce requires a "getter" and "setter" to reference a variable in the controller or extension. Without a getter or setter, even public or global variables cannot be referenced in Visualforce expressions.
"get;" is basically: public *datatype* getVarName() { return varName; }
"set;" is basically: public void setVarName(*datatype* value) { varName = value; }
There are subtle differences though. For example, the function doesn't actually exist; it's called implicitly. You can make variables read-only by not including set;, and you can make them write-only by not including get;.Inside Apex Code, you can also use these to control readability and writeability.
For example: This counter increases by 1 each time it's used, but can't be set outside of the class that contains it. Detailed information : http://www.forcetree.com/2009/07/getter-and-setter-methods-what-are-they.html
Please mark this as the best answer if this helps
All Answers
You could have
Thanks so much for helping me on this, so this is what I understood by your reply, to access the string from a controller either it has to be made public getter or the string has to be return through some public getter method.And there are no other ways to achieve this apart from these two what you mentioned, is my understanding correct?
Thanks again,
Jancy
Visualforce requires a "getter" and "setter" to reference a variable in the controller or extension. Without a getter or setter, even public or global variables cannot be referenced in Visualforce expressions.
"get;" is basically: public *datatype* getVarName() { return varName; }
"set;" is basically: public void setVarName(*datatype* value) { varName = value; }
There are subtle differences though. For example, the function doesn't actually exist; it's called implicitly. You can make variables read-only by not including set;, and you can make them write-only by not including get;.Inside Apex Code, you can also use these to control readability and writeability.
For example: This counter increases by 1 each time it's used, but can't be set outside of the class that contains it. Detailed information : http://www.forcetree.com/2009/07/getter-and-setter-methods-what-are-they.html
Please mark this as the best answer if this helps
That's a nice blog with simple explanation, well I could sense what you mentioned about referencing a variable on a VF page from the controller or extension should be of “getter” and “setter”. I got more clarity on it going through the blog you shared, and thanks for your explanation too.
Cheeeeerrrrs!!!
Jancy