@Override
public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
if (!component.isRendered())
return;
AbstractSwitcher switcher = (AbstractSwitcher) component;
Locale locale = switcher.getLocale();
Rendering.registerDateTimeFormatObject(locale);
TimetableView timetableView = switcher.getTimetableView();
TimeZone timeZone = switcher.getTimeZone();
SimpleDateFormat dateFormat = CalendarUtil.getSimpleDateFormat(switcher.getDateFormat(),
DEFAULT_DATE_FORMAT, getPattern(switcher), null, locale, timeZone);
String pattern = dateFormat.toPattern();
ResponseWriter writer = context.getResponseWriter();
writer.startElement("table", switcher);
writeIdAttribute(context, switcher);
writer.writeAttribute("cellspacing", "0", null);
writer.writeAttribute("cellpadding", "0", null);
writer.writeAttribute("border", "0", null);
String styleClass = Styles.getCSSClass(context,
switcher, switcher.getStyle(), "o_timeSwitcher", switcher.getStyleClass());
writer.writeAttribute("class", styleClass, null);
writer.startElement("tbody", switcher);
writer.startElement("tr", switcher);
boolean enabled = switcher.isEnabled();
if (enabled) {
renderPreviousButton(context, switcher);
}
writer.startElement("td", switcher);
writer.writeAttribute("class", "o_timeTextContainer", null);
renderText(context, switcher, timetableView, dateFormat);
writer.endElement("td");
if (enabled) {
renderNextButton(context, switcher);
}
writer.endElement("tr");
writer.endElement("tbody");
writer.endElement("table");
JSONObject stylingParams = getStylingParamsObj(context, switcher);
Styles.renderStyleClasses(context, switcher);
Date dayInitParam = getDayInitParam(timetableView);
Object[] params = {
timetableView,
DataUtil.formatDateTimeForJs(dayInitParam, timeZone),
pattern,
locale,
stylingParams,
enabled
};
Object[] additionalParams = getAdditionalParams(context);
String switcherClassName = switcher.getClass().getName();
int i = switcherClassName.lastIndexOf(".");
switcherClassName = switcherClassName.substring(i + 1);
ScriptBuilder script = new ScriptBuilder().initScript(context, switcher, "O$." + switcherClassName + "._init",
concatenateArrays(params, additionalParams)