I'm trying to refresh a chart using a SelectList tag. If i understand correctly, my "chartPeriod" variable should be updated to the selected value on every change(and the chart refreshed thanks to the apex:actionSupport tag). With debug logs though, I can see the value does not even get to the controller.
Any idea why ?
I can post all the code if needed but there is a lot irrelevant since the chart without filter is working fine. I've reviewed some posts with similar issues but couldn't find a fix.
Thanks.
My controller :
public class PipeChartController {
public Date chartPeriod{
get{
if(chartPeriod==null) chartPeriod = thisYear();
return chartPeriod;
}
set;
}
// Periods available to be charted, for <apex:selectList>
public static List<SelectOption> getChartPeriodOptions() {
List<SelectOption> periods = new List<SelectOption>();
String thisYear = String.valueOf(thisYear());
periods.add(new SelectOption(thisYear,thisYear));
String thisQuarter = String.valueOf(thisQuarter());
periods.add(new SelectOption(thisQuarter,thisQuarter));
String thisWeek = String.valueOf(thisWeek());
periods.add(new SelectOption(thisWeek,thisWeek));
return periods;
}
// Return a list of data points for a chart
public List<Data> getData() {
return PipeChartController.getChartData(this.chartPeriod);
}
// Make the chart data available via JavaScript remoting
@RemoteAction
public static List<Data> getRemoteData(Date period) {
return PipeChartController.getChartData(period);
}
// The actual chart data; needs to be static to be
// called by a @RemoteAction method
public static List<Data> getChartData(Date period) {
//querying & formatting data for the chart
return data;
}
public static Date thisYear(){
Project_Budget__c[] thisYear = [Select createdDate from Project_Budget__c where createdDate=this_year Order by createdDate ASC Limit 1];
DateTime dt = (Datetime)thisYear[0].get('createdDate');
return Date.newInstance(dt.year(), dt.month(), dt.day());
}
}
VF Page :
<apex:page controller="PipeChartController" title="PipeChart">
<apex:outputText value="Pipe (k€)"/>
<apex:form id="form">
<div style="float:left">
<apex:commandButton value="Refresh"/>
</div>
<div style="float:left">
<apex:selectList value="{!chartPeriod}" size="1">
<apex:selectOptions value="{!chartPeriodOptions}"/>
<apex:actionSupport event="onchange" reRender="chartOutputPanel" status="actionStatusDisplay"/>
</apex:selectList>
</div>
<apex:actionStatus id="actionStatusDisplay" startText="loading..." stopText=""/>
<apex:outputPanel id="chartOutputPanel">
<apex:chart height="420" width="100%" data="{!data}" name="PipeChartCY" id="theChart">
...
</apex:chart>
</apex:outputPanel>
</apex:form>