Search code examples
apex-codevisualforce

Pass Apex method parameter value with Visualforce 'apex:actionSupport'


Can anyone please tell me how can I pass Apex method parameter value with Visualforce 'apex:actionSupport'.

Apex code:

public void renderField(String sampleType) { }

Visualforce code:

<apex:inputField id="sampleType" value="{!job.Sample_Type__c}">   
  <apex:actionSupport event="onchange" action="{!renderField(?)}" rerender="otherSampleType"/>       
</apex:inputField>

Solution

  • Action methods don't support passing arguments like that. Instead, you just have to bind VF components to controller properties. In your case, it looks like you may be wanting to get the value of the "sampleType" inputField. If so, you just need a controller property that holds a reference to the "Job". Assuming the type is Job__c, this declaration on the controller would work:

    public Job__c Job { get; set; }
    

    When your actionSupport fires, Job.Sample_Type__c will be populated from the inputField.