function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Abhishek KedariAbhishek Kedari 

Calling generic methods for different object of same type.

Hi,

   I wanted something like this in my code

User-added image

I got this using single controller with few methods and and one visualforce page.

Now what I want is :

User-added image

But I want to use single controller which will operate on different lists.
So planning to have somethink like this

1) 1 Visual force 
2)  controller A has got different objects like multiselect1, multiselect2 and multiselect3   (These 3 objects are of type multiselect)
3) one generic controller/class 'multiselect' which will store information related to data in left panel, right panel, selected and unselected and some functions to move data from one panel to another. I can call these methods from controller A by calling methods using specific objects (like we do in Java).

How I can make this work?
So basically, what I want is visualforce page calls methods on particular object which will get pass to controller A and controller A will again call method from multiselect class on the same object passed by visualforcepage.

Current visualforcepage code :

<apex:panelGrid columns="3" id="abcd">
            <apex:selectList id="sel1" value="{!leftselected}" multiselect="true" style="width:100px" size="5">
                <apex:selectOptions value="{!unselectedvalues}" />
            </apex:selectList>
                <apex:panelGroup >
                    <br/>
                    <apex:image value="{!$Resource.moveRight}">
                        <apex:actionSupport event="onclick" action="{!selectclick}" reRender="abcd"/>
                    </apex:image>
                    <br/><br/>
                    <apex:image value="{!$Resource.moveLeft}">
                        <apex:actionSupport event="onclick" action="{!unselectclick}" reRender="abcd"/>
                    </apex:image>
                </apex:panelGroup>
            <apex:selectList id="sel2" value="{!rightselected}" multiselect="true" style="width:100px" size="5">
                <apex:selectOptions value="{!SelectedValues}" />
            </apex:selectList>
        </apex:panelGrid>



Please let me know if my question is confusing.



Best Regards,
Abhishek








Best Answer chosen by Abhishek Kedari
Jim JamJim Jam
You should consider making your multiselect list a Visualforce component which can be dropped onto any page as required, as many times as needed. In fact, this has already been done! ...   see ... https://developer.salesforce.com/blogs/developer-relations/2012/06/a-multiselect-picklist-visualforce-component.html 

All Answers

Jim JamJim Jam
You should consider making your multiselect list a Visualforce component which can be dropped onto any page as required, as many times as needed. In fact, this has already been done! ...   see ... https://developer.salesforce.com/blogs/developer-relations/2012/06/a-multiselect-picklist-visualforce-component.html 
This was selected as the best answer
Keshab AcharyaKeshab Acharya
I got your point. Basically you are trying to create the multi select functionality manually with you code. Here is what you can do to achieve your requirement. You should try this only if you are planning to have your own style for the multiselect else as Frank said, please leverage salesforce out of the box multiselect.

1. In the left side show the options using select list.
2. In the right hand side, show the options using select list.
3. Keep a hidden input below this mark up.
4. Using javascript, on click of the either arrow store the values of right select list (in semi colon separated) in the hidden input. Like (A;E;F).
5. Map that hidden input to a controller variable. 
 
This way you can do this. I have done it recently. It works like charm. Le me know if you need any clarification. 
 
Mark this as answer, if it helped you.
 
Cheers,
Keshab
AshwaniAshwani
Well you should use interface and implement that interface with objects which require generic method functionality. By this each object will have a fixed set of defined methods which you can use with visualforce pages. 

For multi-select picklist there no need to use such type of complx approach is required. This functionlity can be acheived by <apex:selectlist> and two <apex:commandbutton>. Bind an action function with commandbuttons and rerender the list.