Salesforce 多选选项列表是否可以用于任意数据而不仅仅是 sObject?

发布于 2024-12-09 14:47:10 字数 501 浏览 3 评论 0原文

我想我可能遗漏了一些东西,但我看不到如何使用内置的多选选项列表控件来处理除 sObject 字段之外的任何内容。

我正在谈论的控件具有 2 个标记为“可用”和“选定”的列表对象,中间有箭头以在列表之间移动项目。与 selectList 控件相比,此控件是用户选择多个项目的更简单且更容易发现的方式,后者需要 Shift 和 Ctrl 来选择多个项目。

带有图片示例的页面

使用 selectList 我不需要一个特定的 sObject - 我可以将用户选择存储在我的控制器成员中,我什至可以创建一种方法来提供有效值列表 - 该方法可以是硬编码、动态计算甚至使用查询来查找某些值居住 数据。

有没有一种方法可以使用花哨的选项列表控件,而无需任何对特定 sObject 的引用,而只是字符串值列表?

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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一直在等你来 2024-12-16 14:47:10

不幸的是,使用任何标准字段类型(例如日期或多选选项列表)的唯一方法是让该字段由 SObject 支持。

对我来说,当需要在 Visualforce 页面上使用此类字段时,我将专门创建一个对象,以便为这些字段提供后端。在 Apex 控制器中,只需实例化您的对象(无需提供任何值)并在页面上引用该对象的字段。

虽然从配置方面来看这似乎有点低效,但它有许多额外的好处,例如使用默认 UI(自动接受 SFDC 所做的任何改进)和利用任何内置验证。

如果您执意不让该字段由 SObject 支持,可能有一些 jquery 多选选项可用。我见过很多,但还没有真正测试过。

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.

爱的那么颓废 2024-12-16 14:47:10

在你的班级中:

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;
} 

在你的页面中:

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

结果将以逗号分隔,如果你不想多选,只需将 multiselect 设置为 false

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文