How to pass a value from VF page to Apex Controller?
I need to have a hidden field with pre-populated value inside VF page.
Apex Controller must be able to read this value.
How to do that?
EDIT:
By saying "a hidden field", I did not mean the actual field on the Salesforce object but instead just some kind of value holder which could be accessed and read from the Controller. That value will be hard-coded in the VF page.
Best Answer
The easiest way I've found to do this is using
window.setTimeout()
with an abitrary lowdelay
value which calls anapex:actionFunction
that rerenders a dummyapex:outputPanel
within anapex:actionRegion
.The
apex:actionRegion
and the dummyapex:outputPanel
prevent the whole page refreshing when theapex:actionFunction
is called which will result in your JavaScript being called everytime and ending up in a refresh loop.The
apex:actionRegion
also prevents the following error occurring when this is used on a page with anapex:inputFile
component.Your controller will looks something like this:
Edit:
You don't actually need the
window.setTimeout()
call at all and can simply call yourapex:actionFunction
directly, however you must put your call to yourapex:actionFunction
after (although not necessarily directly after) it's declaration for this to work.