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
Matt ThomasMatt Thomas 

apex:selectList in a Wrapper Class pageBlockTable

Hi,

 

I'm using a pageBlockTable on my page which displays a List of a wrapper class that I created. Each "item" in the wrapper class has its own selectList component corresponding to that item's "Type", a String variable on the wrapper class with a default getter and setter. It looks like this:

 

<apex:pageBlockTable value="{!itemList}" var="item"  headerClass="displayTableHeader" >  
    <apex:column headerValue="Name">
         <apex:outputText value="{!item.Name}" id="itemName" />
    </apex:column>
    <apex:column headerValue="Type">
         <apex:selectList size="1" value="{!item.Type}">
              <apex:selectOptions value="{!typeList}"/>
         </apex:selectList> 
    </apex:column>
    <apex:column headerValue="Action">
         <apex:image value="{!$Resource.addIcon}" width="25" height="25" onclick="doScript('{!item.Name}','{!item.Type}');" />
    </apex:column>
</apex:pageBlockTable>

 When an option is selected from the selectList and the image's onclick javaScript is invoked calling the "doScript" function, the value of "Type" (String) is never set to the option which was selected. However, if the image is then clicked again, it is properly set. Immediately after a change to the selectList option "item.Type" is always the prior value. Does anyone know why item.Type is not being immediately changed to the selected value in the onchange event? I also tried invoking JS onchange from the selectList, but with the same results.

 

Thanks!

Matt ThomasMatt Thomas

I'd like to add one additional note to the above: after playing around with it, in the onchange JS for the selectList I tried invoking an actionFunction which did nothing but return a null PageReference, since I saw something about the value property of selectList not setting until the form was submitted. Obviously, though, the behaviour of this is undesirable due to the fact that null PageReferences onchange of a picklist is a really bad UX....any thoughts would be much appreciated on a different solution.