0

I'm trying to filter a page based on two dates, this is my current actionFunction:

<apex:actionFunction action="{!modifySoQLBasedOnNewDataRange}" name="passDateValues" status="loadingDiv">
<apex:param name="fromParam" value="" ></apex:param>
<apex:param name="toParam" value="" ></apex:param>

Here is my javascript:

   $(function () {

   $('#from').datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1,
        onClose: function(selectedDate){
            $('#to').datepicker("option", "minDate", selectedDate);
        }
   });

   $('#to').datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1,
        onClose: function(selectedDate){
            $('#from').datepicker("option", "maxDate", selectedDate);
        }
   });
   console.log('Datepicker configuration loaded successfully');

   /*setting Default jQuery Dates*/
   $('#from').datepicker('setDate', '0');
   $('#to').datepicker('setDate', '+90d');
   console.log('Datepicker default dates loaded successfully');


   /*jQuery to handle filter Click*/
   $("#filterButton").click(function(){
        passDateValues($('#from').val(), $('#to').val());
        console.log('Filter Button click event got fired');
        console.log('Parameters Passed: ' + 'From: ' + $('#from').val() + '  To: ' + $('#to').val());
   }); 

On the console, the values in the from and to fields are being passed when the filter button is clicked, however when the page reloads, the debug console is showing the two values reverting to their default values and being used in the query instead of the new values. Code from my controller constructor below:

public date fromParam {get;set;}
public date toParam {get;set;}
public Controller(){
fromParam = System.today();
toParam = System.today() + 90; }

Lastly, the method which is called in the action function:

public PageReference modifySoQLBasedOnNewDataRange(){

system.debug('Date values before logic: ' + Apexpages.CurrentPage().getParameters().get('fromParam') + ' : ' + String.valueOf(fromParam));

if(Apexpages.CurrentPage().getParameters().get('fromParam') != '') {
  Apexpages.CurrentPage().getParameters().put('fromParam', String.valueOf(fromParam));
}else{
  fromParam = System.today();
  Apexpages.CurrentPage().getParameters().put('fromParam', String.valueOf(fromParam));
}

if(Apexpages.CurrentPage().getParameters().get('toParam') != ''){
  Apexpages.CurrentPage().getParameters().put('toParam', String.valueOf(toParam));     
}else{
  toParam = System.today() + 90;
  Apexpages.CurrentPage().getParameters().put('toParam', String.valueOf(toParam));     
}

The query then begins being built after this to grab the list of opportunities. Any thoughts or help?

3
  • where are you verifying vales. any rerender section?
    – Himanshu
    May 19, 2016 at 20:03
  • There is no rerendering on the page. I am verifying values through debug logs.
    – Alex
    May 19, 2016 at 20:25
  • where is your debug statement in above code ?
    – Himanshu
    May 20, 2016 at 5:19

1 Answer 1

0

I think you might have an easier time if you actually use bindings to assign those values instead of passing them through the page parameters. Change your apex:params to say <apex:param name="fromParam" value="" assignTo="{!fromParam}" />, add a rerender to the apex:actionFunction, and change the references in your Ctrl to actually use its fromParam and toParam properties instead of pulling them from pageref.

5
  • What would I be rerendering here? The values are passed to a highchart. Without the rerender, debug logs are still giving me the default date (today's date) with the assignTo.
    – Alex
    May 19, 2016 at 20:31
  • it doesn't really matter what you rerender, you could even put rerender="", but I'd recommend rerendering the form. The reason it's important is that without a rerender specified, any page action (like your actionFunction, or a commandButton) will cause the entire page to refresh instead of using Ajax, and this can lead to various misbehaviors in your page state May 19, 2016 at 20:39
  • This worked, the values are saving. However, the only thing is rerendering is not refreshing my chart when I included the pageblock in the rerender, which is a separate issue.
    – Alex
    May 19, 2016 at 20:55
  • This is outside the scope of the question but thought I would ask. Is it possible to rerender the entire page? Also rerendering seems to break the javascript/jquery on the page.
    – Alex
    May 19, 2016 at 21:16
  • Yes, if you include an id on the apex:page tag, you can specify that in your rerender. And if a rerender is breaking your javascript, you should double-check the way in which the JS is taking its values from the page, making sure that it is being fed the updated variables from the toParam and fromParam bindings May 20, 2016 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .