开发者

Can the Salesforce multi-select picklist be used for arbitrary data and not just sObjects?

I think I might be missing something, but I can't see how to use the built in multi-select picklist control for anything but sObject fields.

I'm talking about the control开发者_Python百科 which features 2 list objects marked "Available" and "Selected" with arrows inbetween to moving items between the lists. This control is an easier and more discoverable way for a user to select several items then the selectList control, which needs Shift and Ctrl to select multiple items.

Page with pictured example

With a selectList I don't need a specific sObject - I can store the users selection in one off my controllers members, and I can even create a method to provide a list of valid values - this method could be hard coded, dynamically calculated or even use a query to lookup some live data.

Is there a way to use the fancy picklist control, only without any reference to a specific sObject, just a list of string values?


Unfortunately, the only way to use any of the standard field types, e.g., dates or multi-select picklists, is to have the field be backed by an SObject.

For me, when it becomes necessary to use these kinds of fields on a Visualforce page, I will create an Object specifically for the purpose of providing a back-end for the fields. In the Apex Controller, simply instantiate your Object (no need to supply any values) and reference that object's fields on the page.

While this may seem a little inefficient from the configuration side, it has a number of added benefits such as using the default UI (automatically subject to any improvements made by SFDC) and utilizing any built in validation.

If you are dead-set on not having the field be backed by an SObject, there might be some jquery multi-select options available. I've seen a lot around but haven't really tested any.


in your class:

public List<SelectOption> getStoryItems()
{
    List<SelectOption> options = new List<SelectOption>();
    options.add(new SelectOption('SAM','Sam I Am'));
    options.add(new SelectOption('GEORGE','George of the Jungle'));
    options.add(new SelectOption('DORA','Dora the Explorer'));
    return options;
}
String[] stories= new String[]{};
public String[] getStories() 
{
    return stories;
}

public void setStories(String[] stories) 
{
    this.stories= stories;
} 

in your page:

<apex:selectList value="{!stories}" multiselect="true">
     <apex:selectOptions value="{!getStoryItems}"/>            
</apex:selectList>

The results will be comma delimited, if you don't want multiple select, just set multiselect to false

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜