Why am i not getting values from visualforce page on my controller?

时间:2015-07-10 23:17:53

标签: parameters controller visualforce commandbutton

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.

  1. selectedTypeProd is null
  2. 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.

2 个答案:

答案 0 :(得分:0)

您可以将TypesProduct设为一组字符串。所以它会奏效。

答案 1 :(得分:-1)

我遇到了同样的问题,并通过添加multiselect="false"

让它发挥作用

更改您的代码
<apex:selectList value="{!selectedTypeProd}" size="1">

<apex:selectList value="{!selectedTypeProd}" size="1" multiselect="false">