Find your content:

Search form

You are here

Calling a Apex controller method using JavaScript in VF page

 
Share

Hi can anybody guide me how to call a method in controller from a VF page.


Attribution to: AnuRaj

Possible Suggestion/Solution #1

Apex method:

public PageReference getMyMethod(){
    ....
    return null;
}

Visualforce page action function:

<apex:actionFunction action="{!MyMethod}" name="myFunction" />

actionFunction works like a javascript function, so you can call it from anywhere at your page like this:

<apex:inputField value="{!something}" onchange="myFunction()" />

Attribution to: Sergej Utko

Possible Suggestion/Solution #2

There are two methods to do this :

1)Use @Remote Action Call to call the method

2)Use ACtion Function and call on the event

Here are the documentations for the same

http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionFunction.htm

Video of demo sessions

https://www.youtube.com/watch?v=ckkChgcM9VQ

Summary :Use actionfunction if you need to maintain state between postbacks, remoteaction for stateless invocations


Attribution to: Mohith Shrivastava
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4910

My Block Status

My Block Content