0

I have written apex class test data and Vf page ,In Vf page there is a picklist dropdown option value None,Rice,wheat.For every option in vf page there is a different functionality in apex class.But whatever the option choosing in vf page,it have to pass to the apex class controller .But the value is not passing?

Apex class:

Public PageReference lic() {
       return null;
    }

public String details{get; set;}

    public String options { get; set; }

     public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new selectOption('None', ' None '));
        options.add(new SelectOption('Rice','Rice'));
        options.add(new SelectOption('Wheat','Wheat));
        return options;

    }
 public list<Account> lic{get{
 if(details=='Rice')
// some functionailty is here, but details from vf page to apex class it is returning null

Visual Force Page:

<apex:page controller="Testdata" >

     <apex:form >


     <apex:pageBlock >
     <apex:pageBlockSection >


     <apex:selectList value="{!details}" size="1">
            Organization:<apex:selectOptions value="{!Items}" />

        </apex:selectList><p/>  
        <apex:actionSupport event="onchange" action="{!lic}" reRender="abcd">
                                 <apex:param name="details"  assignTo="{!details}" />       
                                    </apex:actionsupport>

The Value from details in vf page not passing to apex class,for None option value it have to display empty page,whatever the option choosing from vf page,it have to pass to apex class.How to pass the value?

1 Answer 1

3

apex:actionSupport should be a child of apex:selectList. Also, There's no reason to use an apex:param here, because you've already bound the value of the list to the details variable.

<apex:selectList value="{!details}" size="1">
  <apex:selectOptions value="{!Items}" />
  <apex:actionSupport event="onchange" action="{!lic}" reRender="abcd" />
</apex:selectList>

Finally, having a variable and a method both called lic is going to cause developer confusion. Make sure they're distinct so you don't get them confused. In your case, the property lic isn't going to be accessed by Visualforce directly for an action, but would be for a value attribute. This will make debugging a bit more challenging.

2
  • The value is not passed from vf page to apex class? since for details i am getting null value in apex class @sfdcfox
    – user55489
    Sep 26, 2018 at 3:01
  • @VinothBalasubramaniyan If you're using apex:param, I would expect it to be null. apex:actionSupport doesn't need apex:param in this case. The value is assigned via the apex:selectList value attribute directly.
    – sfdcfox
    Sep 26, 2018 at 3:31

You must log in to answer this question.