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
PGNPGN 

actionSupport and selectList

Hi,
         I would like to invoke an action method on a controller when the user changes the value of a selectList.
So I have the following code in my page:
 

<apex:selectList value="{!sortByAttr}" multiselect="false" size="1" >

<apex:selectOptions value="{!sortByOptions}"/>

<apex:actionSupport event="onchange" action="{!sortTheListings}" rerender="listingSearchResultsPanel" immediate='false' />

</apex:selectList>

The sortTheListings function is not invoked at all.

 

So I tried actionFunction

<apex:actionFunction action="{!sortTheListings}"

name="sortAgain" rerender="listingSearchResultsPanel" status='nextStatus' immediate='false' />

<apex:selectList value="{!sortByAttr}" multiselect="false" size="1" onchange="sortAgain()" >

<apex:selectOptions value="{!sortByOptions}"/>

</apex:selectList>

This time, the sortTheListings() call is made, but the new value of sortByAttr is not propagated to the controller.

I have all of this within apex:form tag. I also tried adding actionRegion around it.

Do let me know if you need additional code/information.

Any help will be greatly appreciated.

Regards

Pratima

 

mtbclimbermtbclimber
The only thing that sticks out is your use of immediate. False is the default so try removing that though that shouldn't make a difference. Please let us know if it does.

Assuming not, please provide your page/controller (the more condensed but still exhibiting the problem the better) and use the SRC button in the toolbar.  You can also read through this example if you haven't already which highlights much of what you are trying to do from what I can tell.
PGNPGN
Controller:
public class SampleResultsPageController {

    private transient List<String> results = null; 
    
    private String sortByAttr;
    
    public SampleResultsPageController() {
     results = new List<String>();
     results.add('test');
     sortByAttr = 'Name';
    }
    
    public PageReference clickedSearch() {
        System.debug('################## SEARCHING ################');
        return null;
    }
    
    public String getSortByAttr() {
      return sortByAttr;      
    }
    
    public void setSortByAttr(String k) {
     System.debug('Calling setSortByAttr ' + k);
        sortByAttr = k;
    }
    
    
    public Boolean getHasResults() {
        return results == null — false : results.size() > 0;
    }
    
    public PageReference sortTheListings() {
     System.debug('$$$$$$$$$$$$$$$$$$$$ sortByAttr = ' + sortByAttr);
        results = new List<String>();
        results.add('test');
        System.debug('Sorted Results = ' + results);
        return null;
    }
     
    public List<SelectOption> getSortByOptions() 
    {
        List<SelectOption> options = new List<SelectOption>();
    
        options.add(new SelectOption('Popularity7Day__c DESC', 'Popularity (Last 7 Days)'));
               
        options.add(new SelectOption('Popularity30Day__c DESC', 'Popularity (Last 30 Days)'));
        
        options.add(new SelectOption('PopularityAllTime__c DESC', 'Popularity (All Time)'));
        
        options.add(new SelectOption('AverageOverallScore__c DESC', 'Rating'));
        
        options.add(new SelectOption('PublishedDate__c DESC', 'Release Date'));
        
        options.add(new SelectOption('Name', 'App Name'));
        
        options.add(new SelectOption('Publisher__r.name', 'Publisher'));
        
        return options;
    }
}
VF Page:

<apex:page controller="SampleResultsPageController" showHeader="false">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<body>

<apex:form>

<div id="page">

<div class="find2-cont">

<h2>Find Apps</h2>

</div>

<apex:outputPanel id='searchResultsPanel'>

<apex:actionFunction action="{!sortTheListings}"

name="sortAgain" rerender="listingSearchResultsPanel" status='nextStatus' immediate='false' />

<div id="search-res">

<apex:outputPanel id="searchResultsPagenationPanel" rendered="{!hasResults}">

<apex:actionStatus id="nextStatus" startText="(going to next page...)" stopText=""/>

<apex:outputPanel styleClass="sort">

<label>Sort by</label>

<apex:selectList value="{!sortByAttr}" multiselect="false" size="1" onchange="sortAgain()" >

<apex:selectOptions value="{!sortByOptions}"/>

</apex:selectList>

</apex:outputPanel>

</apex:outputPanel>

</div>

<apex:outputPanel id="listingSearchResultsPanel">

</apex:outputPanel>

</apex:outputPanel>

</div>

</apex:form>

</body>

</html>

</apex:page>


 
I realized that if I remove the "transient" keyword on the results attribute of the controller, it works.
Is this expected behavior ?
 
Regards
Pratima
PGNPGN
Andrew
           Did you get a chance to look into this ? I would like to make the results variable transient if possible.
 
Thanks
Pratima