+ Start a Discussion
Sudhir_MeruSudhir_Meru 

How to store SelectList Value from Visual force to Controller

Hi,

 I want to store below visualforce code inside controller based on the selection is made .

VisualForce
<apex:pageBlockSectionItem >
   <apex:outputLabel value="Expiry Term:" for="expireterm"/>
   <apex:selectList value="{!ExpireTerms}" multiselect="false" size="1" id="expterms" readonly="true">
                <apex:selectOption itemValue="1" itemLabel="1 Year"/>
                <apex:selectOption itemValue="3" itemLabel="3 Year"/>
                <apex:selectOption itemValue="5" itemLabel="5 Year"/>
    </apex:selectList>
   </apex:pageBlockSectionItem> 

<apex:pageBlockSectionItem >
   <apex:outputLabel value="Expiry Term:" for="expireterm"/>
   <apex:selectList value="{!ExpireTerms}" multiselect="false" size="1" id="expterms" readonly="true">
                <apex:selectOption itemValue="1" itemLabel="1 Year"/>
                <apex:selectOption itemValue="3" itemLabel="3 Year"/>
                <apex:selectOption itemValue="5" itemLabel="5 Year"/>
    </apex:selectList>
   </apex:pageBlockSectionItem> 


Please suggest me.

Thanks
Sudhir

Best Answer chosen by Sudhir_Meru
Vamsi KrishnaVamsi Krishna
Sudhir,
the value selected in the list will be stored in the controller variable ExpireTerms which you have mentioned in the value attribute.
did u check in this variable using debug logs ? is it not getting assiged in here ?

also i noticed you are having readonly = true in your select list. if you want to change the options then it should not be readonly.

All Answers

kcpluspluskcplusplus
You already have the selectlist value specified to a controller variable. So once you have a value selected, and an event is triggered to the controller, you will be able to reference the selectoption value with the expireterms variable. Is that what you are looking to do?

--KC
Vamsi KrishnaVamsi Krishna
Sudhir,
the value selected in the list will be stored in the controller variable ExpireTerms which you have mentioned in the value attribute.
did u check in this variable using debug logs ? is it not getting assiged in here ?

also i noticed you are having readonly = true in your select list. if you want to change the options then it should not be readonly.
This was selected as the best answer
ouz_alpouz_alp
Hi Sudhir, 
Also , you need to be ensure that ExpireTerms variable has getter and setter methods in the related controller.If it has not setter method the selected value will not be assigned to this variable.
kcpluspluskcplusplus
Good call on the getter/setter, that's a good guess as to the culprit. 

--KC
Sudhir_MeruSudhir_Meru

Hi All, 

  Thanks for your reply I changed readonly=false still values is not getting stored inside object. What is issue in get and set method am doing here. 

  Please suggest.

Thanks

Sudhir

MagnetismMagnetism
Post your controller class  to see if you have something missing there