0

I am facing issues with select list . I have a table of records and i am trying to fetch the selected picklist value in the controller . However seems like it is always fetching the last value .Below is the code .

<apex:selectList value="{!selectedString}" title="Abc" size="1">
    <apex:selectOptions value="{!abs.optionsList}" id="serviceType" />
    <apex:actionSupport event="onchange" action=" {!createValues} "reRender="section1">
        <apex:param name="testParam" value=" {!abs.abdata.Id}" assignTo="{!abId}"/>
    </apex:actionSupport>
</apex:selectList>

public void createValues(){
    system.debug('Value of nbId *********** ' + nbId);
    system.debug('Value of selectedString *********** ' + selectedString);
    nbIdList.add(nbId);
    selectedStringList.add(selectedString);
    system.debug('Value of selectedStringList *********** ' + selectedStringList);
}

For instance if i have two rows of data in the table and initially the value of picklist for both rows is 7 and then
if the corresponding selected value of picklist for row 1 and row 2 is changed to 33 and 34 respectively .Then selectedStringList shows values as 33 and 7 . Not sure why , Can some one please look into it

  • We would need to see more code than what you've shared here to confirm what the problem is, but it sounds like you've bound more than one input to a single variable, which is bound to cause problems. If you would like more definitive help, please edit your question to include all relevant code. – sfdcfox Feb 8 '19 at 16:00
1

Because you bind all selectList with single variable selectedString. So when you select the value it always keeps the last selected value and overrides the previous one.

As per your code abs.abdata.Id it looks like you are using wrapper list. So declare a variable in that list and then bind that variable in select list.

<apex:selectList value="{!abs.selectedString}" title="Abc" size="1">
<apex:selectOptions value="{!abs.optionsList}" id="serviceType" />
<apex:actionSupport event="onchange" action=" {!createValues}" reRender="section1">
    <apex:param name="testParam" value=" {!abs.abdata.Id}" assignTo="{!abId}"/>
</apex:actionSupport>
| improve this answer | |

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.