Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to get Controller property using action function?

my vf controller has property as

public String contractURL {get;set;}

I want to access this latest value in my javascript.

Note - I cannot access it in this way (and thats why I am posting this question :) )-

var url  = "{!contractURL}";
share|improve this question
up vote 4 down vote accepted

try putting var url = {!contractURL} in a <apex:outputPanel> and have it rerendered by your <apex:actionFunction> I don't know for sure if it will work, but give it a try!

If you want to make calls to a controller without having to rerender and use visualforce functionality, just handle the calls and results in javascript, you should take a look at Javascript Remoting:

share|improve this answer
This will definitely work. The only thing is I don't think you'd want to redeclare the variable, although maybe you would if it was the first, and only time you were using it or were just using it local to that reRender instant. – Peter Knolle Dec 15 '12 at 0:36
is there any way I can get 'contractURL' value in java script without putting it into page and do re-render ? like directly make server call and read it from there ? – Prafulla Patil Dec 15 '12 at 1:13
take a look at Javascript Remoting:… – pjcarly Dec 15 '12 at 13:33
I'll add it to my answer, as the comment helped :) – pjcarly Dec 17 '12 at 9:59

You should be able to access the controller property in JavaScript that is directly in your page, such as:

var url = "{!contractURL}";

The Visualforce engine will substitute in all of the values when generating the page.

If you are updating that value in your controller as part of an ajax call (e.g., command button with reRender) it won't update the value of the JavaScript value since that part of the page was already generated.

In a part that you are reRendering you could set the value of the variable, or probably better, create a dedicated outputPanel to set it.

<apex:outputPanel id="reRenderedPanelToSetVariable">
   <script type="text/javascript">
      url = "{!contractURL}";

Then from your command button or whatever you just include the "reRenderedPanelToSetVariable" in the list of ids to rerender.

share|improve this answer
is there any way I can get 'contractURL' value in java script without putting it into page and do re-render ? like directly make server call and read it from there ? – Prafulla Patil Dec 15 '12 at 0:57
You'd need to use JavaScript remoting for that, I think. You tend to lose the stateful nature of the page though. – Bob Buzzard Dec 15 '12 at 8:38

I know this is an old question, and it already has an accepted answer, but I recently had to do the same thing. However, I didn't wanted to use static method via JavaScript Remoting as I wanted to have access to some controller variables. In the end I used this simple approach and it worked:


<apex:page controller="ReturnController">

    <apex:form >
        <apex:commandButton action="{!callMe}"
                oncomplete="processReturnedValue({!valueReturned}); "
                value="Click Me!"/>

        var processReturnedValue = function(valueReturned){
            alert('Returned Value: ' + valueReturned);



public class ReturnController {

    public Integer ValueReturned {get; set;}

    public ReturnController(){
        this.ValueReturned = 0;

    public void callMe(){


That's it, that worked for me. And you could use the exactly same approach with apex:actionFunction:

<apex:actionFunction action="{!callMe}" name="actionFuncName" oncomplete="processReturnedValue({!valueReturned}); "/>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.