How to use variables in page ?
Visualforce page/component can use,- global variables
- Functions
- parameters from controller/extensions
- local variables
I haven't seen many developers using variables that often. It's created using variable tag. It could be used when you have a very lengthy variable names (or) complex Function output (or) lengthy relationship chain to access parameters in controller/extension.
What is the advantage of it ?
It has all the advantages that a variable has in a programming language.- A common place to access it's value
- No need to change it in all the place, if we ever want to change it
- We can give a meaningful variable name
- Code looks clean
- Improve maintainablity
How to use them dynamically ?
We could either assign the variable name statically like this,
<apex:variable value="{!$CurrentPage.Name}" var="current_page_name"/>
or dynamically like this which means the varname could be any value dynamically assigned from anywhere.
<apex:variable value="{!$CurrentPage.Name}" var="{!varname}"/>
Where is the code ?
This is the illustration of showing static variable assignment. 'TodaysDate' is a controller parameter. But, you can dynamically, changes its value in the component using variable assignment. you can see that in the code below,
No comments:
Post a Comment
Thanks for reading my blog !