Wednesday, August 27, 2014

Simple Ajax Example Using Visualforce Page.

Simple Ajax Example Using Visualforce Page.

Here i am going to give simple example of using Ajax functionality in Visualforce, In the below example when ever a user enters a key value then it will call the Controller method and fetch the accounts related to text box value.

Visualforce Page:

<apex:page controller="AjaxWildcardController">
  <apex:form >
      <apex:pageBlock >
        Type Account Name Here :<apex:inputText value="{!inputtext}" >
          <apex:actionSupport action="{!actionSupMethod}" event="onkeyup" reRender="outptText" />

    <apex:pageblock >
      <apex:pageblocktable value="{!accList}" var="acc" id="outptText">
        <apex:column value="{!}"/>
        <apex:column value="{!acc.accountnumber}"/>

Controller :

public class AjaxWildcardController {
Public string inputtext{get;set;}
    Public List<account> accList{get;set;}
    Public boolean flagshow{get;set;}
    Public AjaxWildcardController(){
    flagshow = false;
    Public void actionSupMethod(){
      accList = database.Query('select name,accountnumber from account where name like '+'\''+'%'+inputtext+'%'+'\'');


Output : 

save image


Post a Comment

| ,