public class CalendarRenderer extends LayoutComponentRendererBase {
@Override
public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {
final UICalendar output = (UICalendar) component;
final String id = output.getClientId(facesContext);
final Locale locale = facesContext.getViewRoot().getLocale();
final Object value = output.getValue();
final Calendar calendar;
if (value instanceof Calendar) {
calendar = (Calendar) value;
} else {
calendar = new GregorianCalendar();
if (value instanceof Date) {
calendar.setTime((Date) value);
}
}
final CalendarModel model = new CalendarModel(calendar);
// rendering
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
writer.startElement(HtmlElements.DIV, component);
writer.writeIdAttribute(id);
writer.writeClassAttribute(Classes.create(output));
HtmlRendererUtils.writeDataAttributes(facesContext, writer, component);
final Style style = new Style(facesContext, output);
writer.writeStyleAttribute(style);
final String dateInputId = (String) output.getAttributes().get(Attributes.DATE_INPUT_ID);
if (dateInputId != null) {
writer.writeAttribute(DataAttributes.DATE_INPUT_ID, dateInputId, false);
}
writer.writeAttribute(DataAttributes.DAY, Integer.toString(calendar.get(Calendar.YEAR)), false);
writer.writeAttribute(DataAttributes.MONTH, Integer.toString(1 + calendar.get(Calendar.MONTH)), false);