function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dharmendra KushwahDharmendra Kushwah 

apex:actionSupport onchange event, not passing latest values to controller using apex:param

Hi All,

I am using on <apex:actionSupport> on an InputField, and on change of field value, i am passing InputField value to controller using <apex:param>. However the issue is, in controller, iam not getting latest InputField value. Please see below simpler code snippet:

VF page:
<apex:page controller="testcontroller">
     <apex:form >
             <apex:inputField value="{!acct.name}" >
                 <apex:actionSupport event="onchange" action="{!setvar}" reRender="">
                     <apex:param name="setvar" value="{!acct.name}" assignTo="{!var}"/>
                 </apex:actionSupport>
             </apex:inputField>
      </apex:form>
</apex:page>

Controller:
public class testcontroller{

    public String Account { get; set; }

public Account acct{get;set;}
public string var{get;set;}

    public testcontroller(){
        acct = new Account();
    
    }
    
     public void setvar(){
     
        system.debug('var#####'+var);
    
    }
}

Please help me out, if there is any other way to pass this latest field value on change to Controller.

Thanks
 

Naveen Kumar B H(bhns)Naveen Kumar B H(bhns)
Hi Dharmendra,

As you are using "acct" get set variable already, you don't have to use one more variable. you can directly use acct.Name in the method. Modify your code as mentioned below. 
VF page:

<apex:page controller="testcontroller">
     <apex:form >
             <apex:inputField value="{!acct.name}" >
                 <apex:actionSupport event="onchange" action="{!setvar}" reRender="">
                 </apex:actionSupport>
             </apex:inputField>
      </apex:form>
</apex:page>

Controller:

public class testcontroller{

    public String Account { get; set; }
    public Account acct{get;set;}
    //public string var{get;set;}

    public testcontroller(){
        acct = new Account();    
    }
    
    public void setvar(){     
        system.debug('var#####'+acct.Name);   
    }
}

 Try this and let me know if you need more help.

Regards
Naveen
Admin PEDAdmin PED
if i set reRender="" in apex:actionSupport the value is never fetched. don't work