Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

2 Answers 2

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: http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm

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
1  
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
1  
take a look at Javascript Remoting: salesforce.com/us/developer/docs/pages/Content/… –  PJC Dec 15 '12 at 13:33
    
I'll add it to my answer, as the comment helped :) –  PJC 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}";
   </script>
</apex:outputPanel>

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
2  
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

Your Answer

 
discard

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.