if (!(component instanceof UITime)) {
LOG.error("Wrong type: Need " + UITime.class.getName() + ", but was " + component.getClass().getName());
return;
}
UITime time = (UITime) component;
String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, time);
String currentValue = getCurrentValue(facesContext, time);
if (LOG.isDebugEnabled()) {
LOG.debug("currentValue = '" + currentValue + "'");
}
String converterPattern = "HH:mm";
if (time.getConverter() != null) {
Converter converter = time.getConverter();
if (converter instanceof DateTimeConverter) {
String pattern = DateFormatUtils.findPattern((DateTimeConverter) converter);
if (pattern != null && pattern.indexOf('s') > -1) {
converterPattern += ":ss";
}
}
}
boolean hasSeconds = converterPattern.indexOf('s') > -1;
Object value = time.getValue();
Date date;
if (value instanceof Date) {
date = (Date) value;
} else if (value instanceof Calendar) {
date = ((Calendar) value).getTime();
} else {
date = new Date();
}
String hour = new SimpleDateFormat("HH").format(date);
String minute = new SimpleDateFormat("mm").format(date);
String second = new SimpleDateFormat("ss").format(date);
String id = time.getClientId(facesContext);
final String idPrefix = id + ComponentUtils.SUB_SEPARATOR;
TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
writer.startElement(HtmlElements.DIV, time);
writer.writeClassAttribute(Classes.create(time));
Style style = new Style(facesContext, time);
writer.writeStyleAttribute(style);
writer.startElement(HtmlElements.DIV, time);
writer.writeAttribute(HtmlAttributes.ID, idPrefix + "borderDiv", false);
Markup markup = time.getCurrentMarkup();
if (hasSeconds) {
markup = markup.add(Markup.SECONDS);
}
writer.writeClassAttribute(Classes.create(time, "borderDiv", markup));
writeInput(writer, time, idPrefix + "hour", hour, true, title);
writeInputSeparator(writer, time, ":");
writeInput(writer, time, idPrefix + "minute", minute, false, title);
if (hasSeconds) {
writeInputSeparator(writer, time, ":");
writeInput(writer, time, idPrefix + "second", second, false, title);
}
writer.endElement(HtmlElements.DIV);
String imageId = idPrefix + "inc";
String imageSrc = "image/timeIncrement.gif";
writer.startElement(HtmlElements.IMG, null);
writer.writeIdAttribute(imageId);
writer.writeClassAttribute(Classes.create(time, "incImage", markup));
writer.writeAttribute(HtmlAttributes.SRC, ResourceManagerUtils.getImageWithPath(facesContext, imageSrc), true);
writer.writeAttribute(HtmlAttributes.ALT, "", false); // TODO: tip
if (!(ComponentUtils.getBooleanAttribute(time, Attributes.DISABLED)
|| ComponentUtils.getBooleanAttribute(time, Attributes.READONLY))) {
writer.writeAttribute(HtmlAttributes.ONCLICK, "tbgIncTime(this)", false);
}
writer.endElement(HtmlElements.IMG);
imageId = idPrefix + "dec";
imageSrc = "image/timeDecrement.gif";
writer.startElement(HtmlElements.IMG, null);
writer.writeIdAttribute(imageId);
writer.writeClassAttribute(Classes.create(time, "decImage", markup));
writer.writeAttribute(HtmlAttributes.SRC, ResourceManagerUtils.getImageWithPath(facesContext, imageSrc), true);
writer.writeAttribute(HtmlAttributes.ALT, "", false); // TODO: tip
if (!(ComponentUtils.getBooleanAttribute(time, Attributes.DISABLED)
|| ComponentUtils.getBooleanAttribute(time, Attributes.READONLY))) {
writer.writeAttribute(HtmlAttributes.ONCLICK, "tbgDecTime(this)", false);
}
writer.endElement(HtmlElements.IMG);
writer.startElement(HtmlElements.INPUT, time);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
writer.writeIdAttribute(id + ":converterPattern");
writer.writeAttribute(HtmlAttributes.VALUE, converterPattern, true);
writer.endElement(HtmlElements.INPUT);
writer.startElement(HtmlElements.INPUT, time);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.HIDDEN, false);
writer.writeIdAttribute(id);
writer.writeNameAttribute(id);
writer.writeAttribute(HtmlAttributes.VALUE, hour + ":" + minute + ":" + second, false);
writer.endElement(HtmlElements.INPUT);
String dateTextBoxId = (String) time.getAttributes().get(Attributes.DATE_INPUT_ID);
if (dateTextBoxId != null) {
String[] cmds = {"tbgInitTimeParse('" + id + "', '" + dateTextBoxId + "');"};
HtmlRendererUtils.writeScriptLoader(facesContext, null, cmds);
}