0

when I try to get the selected values from picklist and the inputText value by clicking the command button, it's not really passing them to my controller.

VF:

<apex:page controller="FieldsAndTypesPicklists" >
<apex:form >

    <apex:inputText value="{!newDatasetName}" />
    <apex:outputlabel value="Product type: "/>   

    <apex:selectList value="{!selectedTypeProd}" size="1">
        <apex:selectOptions value="{!TypesProduct}"/>
    </apex:selectList>

    <apex:commandButton value="Add new values" action="{!SaveValues}"  />
</apex:form>
</apex:page>

Controller:

public with sharing class FieldsAndTypesPicklists {

    public String selectedTypeProd {get; set;}

    public String newDatasetName { get; set; }

    public void SaveValues() {
        System.debug('>>> InputText value: '+newDatasetName);
    }

     public Set<SelectOption> getTypesProduct(){

        System.debug('>>> Select Type value: '+selectedTypeProd);
        Set<SelectOption> typesProd = new Set<SelectOption>();
        List<Schema.PicklistEntry> picklistEntryList = OpportunityLineItem.TypeProduct__c.getDescribe().getPicklistValues();

        for(Schema.PicklistEntry plEntry : picklistEntryList){
            String typeProduct = string.ValueOf(plEntry.getValue());
            typesProd.add(new SelectOption(typeProduct, typeProduct));
        }

        return typesProd;
    }  

 }

I've made the corresponding debugs to see the inputText and the picklist selected value.

selectedTypeProd is null it is not executing the method SaveValues() If I take out the piece of code where is the selected list (on the VF) and the getTypesProduct() method in the controller it works fine for the inputText value. It seems like the other part is affecting the execution.

1
  • add a rerender to your command button.
    – Eric
    Jul 13, 2015 at 16:34

1 Answer 1

0

VF Page:- Add id to the form and reRender it on button.

    <apex:inputText value="{!newDatasetName}" />
    <apex:outputlabel value="Product type: "/>   

    <apex:selectList value="{!selectedTypeProd}" size="1">
        <apex:selectOptions value="{!TypesProduct}"/>
    </apex:selectList>

    <apex:commandButton value="Add new values" action="{!SaveValues}"  reRender="form"/>
</apex:form>
</apex:page>

Controller:- Use List instead of Set.It is working with List not with Set, I have tested the same.

public List<SelectOption> getTypesProduct(){

        System.debug('>>> Select Type value: '+selectedTypeProd);
        List<SelectOption> typesProd = new List<SelectOption>();
        List<Schema.PicklistEntry> picklistEntryList = OpportunityLineItem.TypeProduct__c.getDescribe().getPicklistValues();

        for(Schema.PicklistEntry plEntry : picklistEntryList){
            String typeProduct = string.ValueOf(plEntry.getValue());
            typesProd.add(new SelectOption(typeProduct, typeProduct));
        }

        return typesProd;
    }  
1
  • thanks, it was the List instead of Set thing, now i've got it working; but without the attribute reRendered set up
    – Martin
    Jul 14, 2015 at 1:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .