function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mauricio.ramosmauricio.ramos 

Select List not working properly with selectoption items

Hello I have been trying to get a Select List to populate the options into the dropdown and have been able to retrieve the list and load it into the picklist, BUT, it does not seem to pass the value for the currently selected option back to the controller. The idea is to get the list of pricebooks for the org and let the user select one, then a variable String in the controller should be updated with the selection the user made. below is the code and vf mark up, if anyone knows what is going on??

 

<apex:form >
<apex:actionRegion id="detail">
<apex:pageBlock tabStyle="SCRB_SalesOrder__c" title="Create Sales Document" >
<apex:pageblockButtons >
       <apex:commandButton action="{!saveSO}" value="Save Sales Order" />
</apex:pageblockButtons>

<apex:pageblockSection collapsible="true" id="docInfo" showHeader="true" title="Document Information"  columns="2"  >
    <apex:pageBlockSectionItem >          
               <!--Load Pricebooks for the Org-->             
                <apex:pageblocksectionItem >
              
                <apex:selectList id="pb" value="{!priceBook}"  multiselect="false" >
                    <apex:selectOptions value="{!PriceBookItems}"/>
                </apex:selectList>
                <a>Currently selected priceBook: {!pricebook}</a>            
                </apex:pageblocksectionItem>

 and the controller code

 

Public String mPricebook;

//load/create list of Pricebooks for the ORG Then load into select list
     public List<SelectOption> getPriceBookItems() {
        List<SelectOption> options = new List<SelectOption>();
        Map<id,PriceBook2> pbs = som.queryPriceBooks(); //this get the list from another class, this is working.
         system.debug('###PriceBooks for Org; ' + pbs);
        for(String pbKey: pbs.keyset()) {
             options.add(new SelectOption(String.valueOf(pbKey),String.valueOf(pbs.get(pbkey).name)));
          }
         }
         return options;
    }
    public String getPriceBook() {
        return mPricebook;
    }
 
    public void setPriceBook(String pPricebook) {
        this.mPricebook = pPriceBook;
    }

 

Best Answer chosen by Admin (Salesforce Developers) 
SRKSRK

 <apex:pageBlockSectionItem id="IntrestedProductpbsi">
                <apex:outputLabel >Interested Product</apex:outputLabel>
                 <apex:actionRegion >
                 <apex:selectList value="{!selectedObject}" size="1" id="IntrestedProductInput">
                 <apex:actionSupport event="onchange" action="{!PricePerUnit}" reRender="f1"/>
                    <apex:selectOptions value="{!objectNames}"/>
                 </apex:selectList>
                  </apex:actionRegion>
            </apex:pageBlockSectionItem>

 

User apex:actionRegion so whole page will not sumbit & validation won't run

 <apex:pageBlockSectionItem id="IntrestedProductpbsi">
                <apex:outputLabel >Interested Product</apex:outputLabel> 
                 <apex:actionRegion >
                 <apex:selectList value="{!selectedObject}" size="1" id="IntrestedProductInput">
                 <apex:actionSupport event="onchange" action="{!PricePerUnit}" reRender="f1"/>
                    <apex:selectOptions value="{!objectNames}"/>
                 </apex:selectList>
                  </apex:actionRegion>
            </apex:pageBlockSectionItem>

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

You have to call the any action on the change of the picklist value on the vf page by using the apex:actionFunction or apex:actionSupport .

 

Follow the below link as reference:

 

http://boards.developerforce.com/t5/Visualforce-Development/lt-apex-inputCheckbox-gt-issue-after-assigning-value/m-p/444771#M50816

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

SRKSRK

 <apex:pageBlockSectionItem id="IntrestedProductpbsi">
                <apex:outputLabel >Interested Product</apex:outputLabel>
                 <apex:actionRegion >
                 <apex:selectList value="{!selectedObject}" size="1" id="IntrestedProductInput">
                 <apex:actionSupport event="onchange" action="{!PricePerUnit}" reRender="f1"/>
                    <apex:selectOptions value="{!objectNames}"/>
                 </apex:selectList>
                  </apex:actionRegion>
            </apex:pageBlockSectionItem>

 

User apex:actionRegion so whole page will not sumbit & validation won't run

 <apex:pageBlockSectionItem id="IntrestedProductpbsi">
                <apex:outputLabel >Interested Product</apex:outputLabel> 
                 <apex:actionRegion >
                 <apex:selectList value="{!selectedObject}" size="1" id="IntrestedProductInput">
                 <apex:actionSupport event="onchange" action="{!PricePerUnit}" reRender="f1"/>
                    <apex:selectOptions value="{!objectNames}"/>
                 </apex:selectList>
                  </apex:actionRegion>
            </apex:pageBlockSectionItem>
This was selected as the best answer
mauricio.ramosmauricio.ramos

My requirements now changed (facts of life!!) but this had solved my issue. Thanks!