public void writeSubmitFunction(FacesContext context, UICalendar calendar)
throws IOException {
ResponseWriter writer = context.getResponseWriter();
JSFunction ajaxFunction = AjaxRendererUtils.buildAjaxFunction(calendar,
context, AjaxRendererUtils.AJAX_FUNCTION_NAME);
ajaxFunction.addParameter(JSReference.NULL);
HashMap<String, Object> params = new HashMap<String, Object>();
params.put(calendar.getClientId(context) + CURRENT_DATE_PRELOAD, Boolean.TRUE);
Map<String, Object> options = AjaxRendererUtils.buildEventOptions(context, calendar, params);
options.put("calendar", JSReference.THIS);
String oncomplete = AjaxRendererUtils.getAjaxOncomplete(calendar);
JSFunctionDefinition oncompleteDefinition = new JSFunctionDefinition();
oncompleteDefinition.addParameter("request");
oncompleteDefinition.addParameter("event");
oncompleteDefinition.addParameter("data");
oncompleteDefinition.addToBody("this.calendar.load(data, true);");
if (oncomplete != null) {
oncompleteDefinition.addToBody(oncomplete);
}
options.put("oncomplete", oncompleteDefinition);
JSReference requestValue = new JSReference("requestValue");
ajaxFunction.addParameter(options);
JSFunctionDefinition definition = new JSFunctionDefinition();
definition.addParameter(requestValue);
definition.addToBody(ajaxFunction);
writer.write(definition.toScript());
}