Using apex:actionSupport in VisualForce Pages
Osama | November 19, 2009//
//
Most of the times there is a requirement to call a method on different events of a webpage component. for example; ‘onchange’ event of a text box. This is done in html pages by javaScript.
In Visualforce pages, there is a requirement sometimes to call a method on some event which is placed in the controller of the page. To do it, I have been using the actionFunction apex component and the call the method through javaScript. Below is the code below what I have been doing since few days:
<apex:page controller=”TestClass”>
<apex:form>
<script>
func scr(){
acFunc();
}
</script>
<apex:actionFunction name=”acFunc” action=”{!funct}”/>
<apex:inputText id=”txt” value=”{!textBox}” onclick=”scr();”/>
</apex:form>
</apex:page>
———-Controller————
public class TestClass()
{
public String textBox; {set;get;}
public void funct()
{
textBox = ‘This text is displayed after reRendeing’;
}
}
But, today I found another apex component, actionSupport, which can do the same thign without involving javaScript.
here is the code below showing the working of actionSupport component.
<apex:page controller=”TestClass”>
<apex:form>
<apex:inputText id=”txt” value=”{!textBox}”>
<apex:actionSupport action=”{!funct}” event=”onclick” >
</apex:inputText>
</apex:form>
</apex:page>
———-Controller————
public class TestClass()
{
public String textBox; {set;get;}
public void funct()
{
textBox = ‘This text is displayed after reRendering’;
}
}
Actually, javaScript does get invoked but using actionSupport but its on server side. I find it easy to call an apex function this way. But it depends upon the requirements provided. Sometimes we cant afford too much server side interaction. That was it for actionSupport. Hope you have found it helpful as I did find it efficient for my work.
Feel free to ask questions.
.png)









