I am currently trying to call an Apex controller function from an apex:actionFunction, but I can't seem to get the parameters to be passed to the controller function.
ActionFunction
<apex:actionFunction name="Sign_Up" action="{!SignUp}">
<apex:param id="deliveryId_signup" name="deliveryId_signup" value="" assignTo="{!deliveryId}"/>
<apex:param id="slotType_signup" name="slotType_signup" value="" assignTo="{!slotType}"/>
</apex:actionFunction>
Button
<button type="button" class="btn btn-primary btn-block" onclick="Sign_Up('{! deliveriesDateMap[date][school][delivery].delivery.Id }','Signed Off');"> Sign Up </button>
Apex Function
public String deliveryId { get; set; }
public String slotType { get; set; }
public PageReference SignUp() {
//I have tried to also get the params using the options below, but no success
String passedParam1 = Apexpages.currentPage().getParameters().get('deliveryId_signup');
System.debug(passedParam1);
String passedParam2 = System.CurrentPageReference().getParameters().get('deliveryId_signup');
System.debug(passedParam2);
try{
Contact c = [SELECT Id FROM Contact WHERE Id =:contactId];
Delivery__c d = deliveriesMap.get(deliveryId);
Attendance_Slot__c slot = new Attendance_Slot__c (
Delivery__c = deliveryId,
Type__c = slotType,
Contact__c = c.Id
);
insert slot;
successMessage = 'You have successfully signed up for the delivery';
} catch(Exception e) {
errorMessage = 'There was an error signing you up for the delivery\nError: ' + e.getMessage() + '\tLine: ' + e.getLineNumber() + '\t' + e.getCause() + '\t' + e.getStackTraceString();
}
return null;
}
Any help trying to understand why are the fields not being populated on the controller function would be great!
Best Answer
Action function is required to have
rerender
attribute set so that it posts payload back to server. So something like this should work.