I want to build a visualforce interface that allows me to display a list of available things on the left, and chosen things on the right? This one is hard to explain, so I've made an screen shot, because this is a user interface that salesforce itself uses.
Any ideas on how to go about this?
Attribution to: Kevin P
Possible Suggestion/Solution #1
https://github.com/metadaddy-sfdc/Visualforce-Multiselect-Picklist/
This is the only thing you need to add to Patt Patterson contribute to make it work great:
public MultiselectController(){
leftOptions = new SelectOption[]{};
rightOptions = new SelectOption[]{};
}
Attribution to: Solees
Possible Suggestion/Solution #2
I installed the package Pat Patterson created (located here) is really nice, and easy to get ahold of. However, the code is a little sparse. Here's an updated version of the Controller.
Revisions = adding constructors to avoid dereferencing null-objects.
/*
* MultiselectController synchronizes the values of the hidden elements to the
* SelectOption lists.
*/
public with sharing class MultiselectController {
// SelectOption lists for public consumption
public SelectOption[] cLeftOptions { get; set{
SelectOption[] tmp=value;
if(tmp==null){tmp=new SelectOption[]{};}
this.cLeftOptions=tmp;
}}
public SelectOption[] cRightOptions { get; set{
SelectOption[] tmp=value;
if(tmp==null){tmp=new SelectOption[]{};}
this.cRightOptions=tmp;
}}
public MultiselectController(){
cLeftOptions=new SelectOption[]{};
cRightOptions=new SelectOption[]{};
}//ENd init()
// Parse &-separated values and labels from value and
// put them in option
private void setOptions(SelectOption[] options, String value) {
options.clear();
String[] parts = value.split('&');
for (Integer i=0; i<parts.size()/2; i++) {
options.add(new SelectOption(EncodingUtil.urlDecode(parts[i*2], 'UTF-8'),
EncodingUtil.urlDecode(parts[(i*2)+1], 'UTF-8')));
}
}
// Backing for hidden text field containing the options from the
// left list
public String leftOptionsHidden { get; set {
leftOptionsHidden = value;
setOptions(cLeftOptions, value);
}
}
// Backing for hidden text field containing the options from the
// right list
public String rightOptionsHidden { get; set {
rightOptionsHidden = value;
setOptions(cRightOptions, value);
}
}
}
Attribution to: Scott Pelak
Possible Suggestion/Solution #3
http://pexlify.com/custom-multi-user-selection-in-visualforce/
Multi select of users, you can apply this to any Salesforce object
Attribution to: Or Weissler
Possible Suggestion/Solution #4
Have you seen this blog post by Pat Patterson?
It should give you exactly what you're looking for.
Attribution to: Mikey
Possible Suggestion/Solution #5
If your field type is Multi-Select then you can just use the apex:inputField
tag and you get the Multi-Select functionality for free. I would look at using that first.
For example, in a page that uses a standardController you would have something like:
<apex:inputField value="{!My_Object__c.My_Multi_Select_Field__c}"/>
However, if that is not enough then I'd try using/adapting the component referenced by Mikey. There's also an example in the Visualforce Developer's guide in the section on Dynamic Visualforce Components. While you might not be using Dynamic Visualforce Components, you could still use the general pattern of the multiselect in the example.
Attribution to: Peter Knolle
Possible Suggestion/Solution #6
The blog post by Pat Patterson is by far the best one around but if you have limitations (can't use Javascript, for instance) then there is an example in the Visualforce documentation that I have used a bit: Using Dynamic References for a User-Customizable Page http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#CSHID=pages_dynamic_vf_components_intro.htm|StartTopic=Content%2Fpages_dynamic_vf_components_intro.htm|SkinName=webhelp Adapt the "Select Fields to Display" PageBlock
Attribution to: DavidSchach
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1264