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
ForceDevForceDev 

StandardSetController and Controller Extensions

Hello,
 
I am trying to take advantage of the new StandardSetController functionality with a custom data set (not driven through a predefined listview filter).  I am having difficulty finding the right syntax within the controller to enable this.
 
I have the following page:
Code:
<apex:page standardController="Account" extensions="ListPOC_Controller" tabStyle="Account" recordSetVar="Accts">  <apex:form id="theForm">
   <apex:sectionHeader title="Page: {!pageNumber}" subtitle="Total Results: {!resultSize}">
    <apex:pageBlock >
     <apex:pageBlockTable value="{!Accts}" var="acct">
      <apex:column value="{!acct.id}" />
       <apex:column value="{!acct.name}" />
     </apex:pageBlockTable>
    </apex:pageBlock>
   </apex:sectionHeader>
  </apex:form>
 </apex:page>
 
And my most recent cut of the controller extension is as follows:

Code:
public class ListPOC_Controller {
  public ListPOC_Controller(ApexPages.StandardSetController stdSetController) {
        // what static var do I need to bind— 
 }
   public List <Account> getAccts() {   return [select id, name from Account limit 25];   
}

Is this even possible?  Can anyone help me fill in the gaps on the controller extension?
 
Thanks in advance.


Message Edited by mtbclimber on 10-04-2008 12:10 PM
mtbclimbermtbclimber
My edit to your post was to put wrap your code in a pre tag by using the SRC button in the editor toolbar (not available in all browsers).

What you need to do is construct a new StandardSetController object in your Apex controller using the querylocator based constructor.  The one you get from the extension is going to be based on the predefined listview filter.

Check out the section titled "Building a Custom List Controller" on page 64 of the Winter '09 Visualforce Developer Guide.

ForceDevForceDev

Thanks Andrew, however when I copy the example from the developer's guide straight into a Winter 09 sandbox, I receive an error when I attempt to save the page indicating: 'Unknown Property: Sobject.Name'.

Has anyone else been able to get the sample from the book to work?



Message Edited by ForceDev on 10-06-2008 06:52 AM

Message Edited by ForceDev on 10-06-2008 06:54 AM
mtbclimbermtbclimber
Sorry about that. The documentation needs to be updated. The reason you are getting the error is that setCon.getRecords() returns a collection of SObjects and not a collection of Opportunities. When the controller is bound to the page directly we do the casting for you but when you use a custom controller and construct your own you need to do the casting.  Add a method like this to the controller and then change your value binding to {!opportunities} and you should be back in business:

Code:
public List<Opportunity> getOpportunities() {
   return (List<Opportunity>) setCon.getRecords();
}

 

ForceDevForceDev

Thanks for the quick response Andrew, I will try that and respond to the thread what I find.  Before I do that, in looking at your suggestion I am trying to understand if I would be able to take advantage of any of the available StandardListController functionality if what I return to the page is simply a list of Opportunities.  What I am trying to do is essentially present a custom data set within the enhanced list view user interface module, where users can select 0 or more records then click on a custom button to perform an action against the selected records.

Am I barking up the wrong tree?

mtbclimbermtbclimber
I don't think what you are looking to do is possible today.  You can't utilize the enhanced list functionality with your own dataset today.  You can build a list with your own dataset - the tree you are currently barking up. 

In order to present a selection column you'll actually want to return a collection of wrapper objects instead of sobjects (casted) directly, something like this:

Code:
public class selectOppty {
   public Opportunity opp { get; set; }
   public Boolean selected { get; set; }

   public SelectOppty(Opportunity o) {
     selected = false;
     opp = o;
   }
}

Then you can bind the selection column inputCheckbox to the boolean property and subsequent postbacks will set the value on each respective row accordingly.




ForceDevForceDev

Ok, thanks - was afraid of this.  Since you allow folks to present this interface along with the filter selection dropdown....I was hoping that you could simply not present the drop down and dictate to the enhanced list view controller what the dataset should be within the controller...would be a nice feature (to take advantage of pagination, robust UI controls, etc.)

I understand the direction I need to go in.

Thanks again for your attention and responses.

mtbclimbermtbclimber
No problem. Just in case it helps you can utilize the apex:enhancedList component and remove the customization links. It also supports pegging the dataset to that of an identified filter definition, e.g.:

Code:
<apex:page>
    <apex:enhancedList listId="00BD00000059WQD" height="600" customizable="false"/>
</apex:page>

 
The limitation is that the filter definition UI is not expressive enough to leverage all the power of SOQL and your button has to appear on all lists - not just the one in the Visualforce page.
davehilarydavehilary

Hi,

 

Is it possible to use this approach to display the output of a dynamic SOQL query on a custom object in an enhanced list. I can't find anything in the documentation that explicitly says this is not possible, but I've had a number of my developers say it can't be done...but it's only enhanced lists that have this problem.

 

Has anyone ever managed to do this?

 

Thanks.