4

I'm trying to set a controller property, using apex:param in an actionFunction but the properties aren't being set. This is my actionFunction:

<apex:actionFunction action="{!setStartEndDates}" name="setStartEndDates" rerender="empty_panel">
    <apex:param name="startDate" assignTo="{!StartDateTime}" value=""/>
    <apex:param name="endDate" assignTo="{!EndDateTime}" value=""/>
</apex:actionFunction>

Javascript - start and end are both js moments:

select: function(start, end, jsEvent, view) {
    setStartEndDates(start._d, end._d);
},

And controller:

public String StartDateTime {get; set;}

public String EndDateTime {get; set;}

public PageReference setStartEndDates() {
    CommonLog.debug('start: ' + StartDateTime);
    CommonLog.debug('end: ' + EndDateTime);
    return null;
}

When I log out the date properties, they're both null. I have another actionFunction set up in exactly the same way which is working fine and I can't figure out why this one isn't working. I've tried making the properties DateTime, and passing the full moment object as the param.

1
  • Parameters aren't loaded until after the controller finishes initializing, this could be playing a role in your problem. Aug 5, 2014 at 15:04

2 Answers 2

5

Found out what the problem was and thought I'd post it here in case anyone else has the same issue. Because the start and end were objects (moment), they weren't casting properly to the controller properties. My solution was:

Javascript:

select: function(start, end, jsEvent, view) {
    setStartEndDatesAF(start.format('YYYY-MM-DD HH:mm:ss'), end.format('YYYY-MM-DD HH:mm:ss'));
},

Controller:

public String StartDateTime {get; set;}
public DateTime startDt {get; set;}

public String EndDateTime {get; set;}
public DateTime endDt {get; set;}

public PageReference setStartEndDates() {
    startDt = DateTime.valueOf(StartDateTime);
    endDt = DateTime.valueOf(EndDateTime);
    //FullCalendar selected end is exclusive - deduct 1 second to get inclusive end
    endDt = endDt.addSeconds(-1);
    return null;
}
2

Try to change Salesforce API version of the page and controller to 30.0 instead of 31.0. I ran into the same issue recently and this helped me. Let me know if it works for you.

You must log in to answer this question.

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