You need to sign in to do that
Don't have an account?
SelectList size=1 prevents postback
I'm probably overlooking something simple, but in attempting to postback with a apex:selectList with a size set to 1, nothing happens. Ever.
I got frustrated and started a brand new visualforce page that exactly mimicked the one found here: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectList.htm
That worked as expected. (The rerender was correct when selecting items from the selectList.)
Then I tweaked it ever so slightly to look like this:
First, the page:
Now my controller:
You'll see that clicking the commandButton does absolutely nothing to the label, nothing changes. However, if you simply remove the size="1" attribute from the selectList everything will function perfectly. (At least that's what I'm seeing.)
Can anyone else verify, (or refute) this?
I got frustrated and started a brand new visualforce page that exactly mimicked the one found here: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_selectList.htm
That worked as expected. (The rerender was correct when selecting items from the selectList.)
Then I tweaked it ever so slightly to look like this:
First, the page:
<apex:page controller="sampleCon"> <apex:form> <apex:selectList value="{!countries}" size="1" > <apex:selectOptions value="{!items}"/> </apex:selectList><p/> <apex:commandButton id="thisButton" value="{!countLabel}" action="{!test}" rerender="thisButton"/> </apex:form> </apex:page>
Now my controller:
public class sampleCon { String[] countries = new String[]{}; public String countLabel {get; set;} private Integer iClicks {get; set;} public sampleCon() { iClicks = 1; countLabel = 'Test ' + iClicks; } public PageReference test() { iClicks++; countLabel = 'Test ' + iClicks; return null; } public List<SelectOption> getItems() { List<SelectOption> options = new List<SelectOption>(); options.add(new SelectOption('US','US')); options.add(new SelectOption('CANADA','Canada')); options.add(new SelectOption('MEXICO','Mexico')); return options; } public String[] getCountries() { return countries; } public void setCountries(String[] countries) { this.countries = countries; } }
You'll see that clicking the commandButton does absolutely nothing to the label, nothing changes. However, if you simply remove the size="1" attribute from the selectList everything will function perfectly. (At least that's what I'm seeing.)
Can anyone else verify, (or refute) this?
All Answers
- Leaving the size attribute in, as long as it is greater than 1 will result in a proper postback and update of the screen.
- The results are identical across both Chrome and Firefox.
- This is on CS40, if that matters at all.
- Altering the API version doesn't change any behavior. (Started at 36, dropped it one at a time to 32 with no difference.)
- Adding an apex:actionRegion didn't change anything either.
This isn't new territory, it's been done many times by many developers (including myself - I'm following my own template that is proven functioning in other orgs).
Which was the problem to start with. It works correctly when I bind it to the correct property, like so: