2

I'm trying to get the value of selected list and passing it to the controller but my code does not work ! I have tried to do this.

<apex:selectList value="{!facility}" size="1">
                   <apex:selectOptions value="{!FacilityOptions}" />
                   <apex:actionSupport event="onchange">
                       <apex:param name="selectedVal" value="{!facility.Name__c}" assignTo="{!facilityName}"/>
                   </apex:actionSupport>
 </apex:selectList> 

Controller:

public List<Facility__c> facilities {set; get;}
public Facility__c facility {get;set;}

 public List<SelectOption> getFacilityOptions() {

    List<SelectOption> options = new List<SelectOption>();
    for (Facility__c record : getfacilities())
    {
        options.add(new SelectOption(record.Name,record.Name__c));
    }
    return options;
    }


public List<Facility__c> getfacilities(){
   facilities = [SELECT Name,Name__c FROM Facility__c];

   return facilities;
}
  • The value is passed to the property specified by the merge field in the value parameter when the page is submitted. Can you post your controller code? At least the portions dealing with facility and FacilityOptions. Without that I can't provide a more precise answer. Also, are you simply trying to pass this value back when the form is submitted, or do you need invoke a controller behavior each time the selectList changes? – Jason Clark Jan 26 '14 at 15:04
  • I added some code of controller, I want to get value on submit the whole form, but I'm using onChange to assign the value when I change it. – user3003810 Jan 27 '14 at 8:18
1

I guess you are missing the action parameter of the actionSupport tag of visualforce. Try calling a method in action parameter of actionsupport and take a look at the value of variable in debug logs. Also you can perform operations in that method you wish to do on change event.

  • I tried to call action, but I think the problem in my code is in the logic ! I'm new in VF, VF logic still unknown for me. – user3003810 Jan 27 '14 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.