You need to sign in to do that
Don't have an account?

SelectList setter is not working in a custom component!
I am developing a custom component that has one SelectList and one Command button.
The selectlist is in multi-select mode so an array of string is prepared to capture user selection.
When the button is clicked, an output label will show the values.
Here is the code:
<apex:component controller="zTestComponent" >
<apex:outputPanel id="thepanel">
<apex:selectList value="{!items}" multiselect="true">
<apex:selectOptions value="{!options}"> </apex:selectOptions>
</apex:selectList>
<apex:commandButton value="submit" action="{!submitMethod}" rerender="thepanel"/>
<apex:outputLabel value="{!message}"></apex:outputLabel>
</apex:outputPanel>
</apex:component>
public class zTestComponent {
public List<SelectOption> options
{
get
{
List<SelectOption> op = new List<SelectOption>();
op.add(new SelectOption('1','test 1'));
op.add(new SelectOption('2','test 2'));
return op;
}
}
public List<string> items
{
get;
set;
}
public string message { get; set; }
public PageReference submitMethod() {
message = '';
if (items != null)
for(string item : items)
{
message += item + ',';
}
return null;
}
}
When the button is clicked, the items variable is always null?! Any one knows why?
We actually very recently discovered a bug with multi selectList and apex properties. If you replace your items property with this:
public List<string> items = new List<String>(); public List<String> getItems() { return items; } public void setItems(List<String> items) { this.items = items; }
It should work. Sorry about that.
All Answers
We actually very recently discovered a bug with multi selectList and apex properties. If you replace your items property with this:
public List<string> items = new List<String>(); public List<String> getItems() { return items; } public void setItems(List<String> items) { this.items = items; }
It should work. Sorry about that.
Thanks!
Another bug is if you set the size attribute via component attribute is generates an error in the design time, but when you add the component to VP page, everything is fine.
<apex:component controller="con">
<apex:attribute name="rows" type="integer" default="5" description=""/>
<apex:selectList id="LeftValues" multiselect="true" value="{!items}" style="width:100%" size="{!rows}">
<apex:selectOptions value="{!options}"></apex:selectOptions>
</apex:selectList>
</apex:component>