private static final Logger LOG = LoggerFactory.getLogger(TimeRenderer.class);
public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {
final UITime time = (UITime) component;
final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, time);
final String currentValue = getCurrentValue(facesContext, time);
if (LOG.isDebugEnabled()) {
LOG.debug("currentValue = '" + currentValue + "'");
}
String pattern = "HH:mm";
if (time.getConverter() != null) {
final Converter converter = time.getConverter();
if (converter instanceof DateTimeConverter) {
final String string = DateFormatUtils.findPattern((DateTimeConverter) converter);
if (string != null && string.indexOf('s') > -1) {
pattern += ":ss";
}
}
}
final boolean hasSeconds = pattern.indexOf('s') > -1;
final Object value = time.getValue();
final Date date;
if (value instanceof Date) {
date = (Date) value;
} else if (value instanceof Calendar) {
date = ((Calendar) value).getTime();
} else {
date = new Date();
}
final String hour = new SimpleDateFormat("HH").format(date);
final String minute = new SimpleDateFormat("mm").format(date);
final String second = new SimpleDateFormat("ss").format(date);
final String id = time.getClientId(facesContext);
final String idPrefix = id + ComponentUtils.SUB_SEPARATOR;
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
writer.startElement(HtmlElements.DIV, time);
writer.writeIdAttribute(id);
writer.writeClassAttribute(Classes.create(time));
HtmlRendererUtils.writeDataAttributes(facesContext, writer, time);
final Style style = new Style(facesContext, time);
writer.writeStyleAttribute(style);
final String dateInputId = (String) time.getAttributes().get(Attributes.DATE_INPUT_ID);
if (dateInputId != null) {
writer.writeAttribute(DataAttributes.DATE_INPUT_ID, dateInputId, false);
}
writer.writeAttribute(DataAttributes.PATTERN, pattern, false);
writer.startElement(HtmlElements.DIV, time);
writer.writeIdAttribute(idPrefix + "borderDiv");
Markup markup = time.getCurrentMarkup();
if (hasSeconds) {
markup = markup.add(Markup.SECONDS);
}
writer.writeClassAttribute(Classes.create(time, "borderDiv", markup));
writeInput(writer, time, idPrefix, "hour", hour, title, 24);
writeInputSeparator(writer, time, ":");
writeInput(writer, time, idPrefix, "minute", minute, title, 60);
if (hasSeconds) {
writeInputSeparator(writer, time, ":");
writeInput(writer, time, idPrefix, "second", second, title, 60);
}
writer.endElement(HtmlElements.DIV);
writer.startElement(HtmlElements.IMG, null);
writer.writeIdAttribute(idPrefix + "inc");
writer.writeClassAttribute(Classes.create(time, "incImage", markup));
writer.writeAttribute(HtmlAttributes.SRC,
ResourceManagerUtils.getImageWithPath(facesContext, "image/timeIncrement.gif"), true);
writer.writeAttribute(HtmlAttributes.ALT, "", false); // TODO: tip
writer.writeAttribute(HtmlAttributes.READONLY, time.isReadonly());
writer.writeAttribute(HtmlAttributes.DISABLED, time.isDisabled());
writer.endElement(HtmlElements.IMG);
writer.startElement(HtmlElements.IMG, null);
writer.writeIdAttribute(idPrefix + "dec");
writer.writeClassAttribute(Classes.create(time, "decImage", markup));
writer.writeAttribute(HtmlAttributes.SRC,
ResourceManagerUtils.getImageWithPath(facesContext, "image/timeDecrement.gif"), true);
writer.writeAttribute(HtmlAttributes.ALT, "", false); // TODO: tip
writer.writeAttribute(HtmlAttributes.READONLY, time.isReadonly());
writer.writeAttribute(HtmlAttributes.DISABLED, time.isDisabled());
writer.endElement(HtmlElements.IMG);
writer.startElement(HtmlElements.INPUT, time);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
writer.writeIdAttribute(idPrefix + "field");