UIPage page = ComponentUtil.findPage(component);
for (String script : SCRIPTS) {
page.getScriptFiles().add(script);
}
UIInput input = (UIInput) component;
Iterator messages = facesContext.getMessages(
input.getClientId(facesContext));
StringBuilder stringBuffer = new StringBuilder();
while (messages.hasNext()) {
FacesMessage message = (FacesMessage) messages.next();
stringBuffer.append(message.getDetail());
}
String title = null;
if (stringBuffer.length() > 0) {
title = stringBuffer.toString();
}
// TODO title??
title =
HtmlRendererUtil.addTip(title, (String) input.getAttributes().get(ATTR_TIP));
String currentValue = getCurrentValue(facesContext, input);
if (LOG.isDebugEnabled()) {
LOG.debug("currentValue = '" + currentValue + "'");
}
String converterPattern = "HH:mm";
if (input.getConverter() != null) {
Converter converter = input.getConverter();
if (converter instanceof DateTimeConverter) {
String pattern = DateFormatUtils.findPattern((DateTimeConverter) converter);
if (pattern != null && pattern.indexOf('s') > -1) {
converterPattern += ":ss";
}
}
} else if (ComponentUtil.getBooleanAttribute(input, ATTR_POPUP_CALENDAR_FORCE_TIME)) {
converterPattern += ":ss";
}
boolean hasSeconds = converterPattern.indexOf('s') > -1;
Object value = input.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 = input.getClientId(facesContext);
final String idPrefix = id + SUBCOMPONENT_SEP;
TobagoResponseWriter writer
= (TobagoResponseWriter) facesContext.getResponseWriter();
writer.startElement(HtmlConstants.DIV, input);
writer.writeComponentClass();
writer.startElement(HtmlConstants.DIV, input);
writer.writeAttribute(HtmlAttributes.ID, idPrefix + "borderDiv", null);
writer.writeClassAttribute("tobago-time-borderDiv"
+ (hasSeconds ? " tobago-time-borderDiv-seconds" : ""));
writeInput(writer, idPrefix + "hour", hour, true);
writeInputSeparator(writer, ":");
writeInput(writer, idPrefix + "minute", minute, false);
if (hasSeconds) {
writeInputSeparator(writer, ":");
writeInput(writer, idPrefix + "second", second, false);
}
writer.endElement(HtmlConstants.DIV);
String imageId = idPrefix + "inc";
String imageSrc = "image/timeIncrement.gif";
HtmlRendererUtil.addImageSources(facesContext, writer, imageSrc, imageId);
writer.startElement(HtmlConstants.IMG);
writer.writeIdAttribute(imageId);
writer.writeAttribute(HtmlAttributes.ONCLICK, "tbgIncTime(this)", false);
writer.writeClassAttribute("tobago-time-inc-image"
+ (hasSeconds ? " tobago-time-image-seconds" : ""));
writer.writeAttribute(HtmlAttributes.SRC, ResourceManagerUtil.getImageWithPath(facesContext, imageSrc), true);
writer.writeAttribute(HtmlAttributes.ALT, "", false); // TODO: tip
if (!ComponentUtil.getBooleanAttribute(input, ATTR_DISABLED)) {
writer.writeAttribute(HtmlAttributes.ONMOUSEOVER,
"Tobago.imageMouseover('" + imageId + "')", null);
writer.writeAttribute(HtmlAttributes.ONMOUSEOUT,
"Tobago.imageMouseout('" + imageId + "')", null);
}
writer.endElement(HtmlConstants.IMG);
imageId = idPrefix + "dec";
imageSrc = "image/timeDecrement.gif";
HtmlRendererUtil.addImageSources(facesContext, writer, imageSrc, imageId);
writer.startElement(HtmlConstants.IMG);
writer.writeIdAttribute(imageId);
writer.writeAttribute(HtmlAttributes.ONCLICK, "tbgDecTime(this)", false);
writer.writeClassAttribute("tobago-time-dec-image"
+ (hasSeconds ? " tobago-time-image-seconds" : ""));
writer.writeAttribute(HtmlAttributes.SRC, ResourceManagerUtil.getImageWithPath(facesContext, imageSrc), true);
writer.writeAttribute(HtmlAttributes.ALT, "", false); // TODO: tip
if (!ComponentUtil.getBooleanAttribute(input, ATTR_DISABLED)) {
writer.writeAttribute(HtmlAttributes.ONMOUSEOVER,
"Tobago.imageMouseover('" + imageId + "')", null);
writer.writeAttribute(HtmlAttributes.ONMOUSEOUT,
"Tobago.imageMouseout('" + imageId + "')", null);
}
writer.endElement(HtmlConstants.IMG);
writer.startElement(HtmlConstants.INPUT, input);
writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
writer.writeIdAttribute(id + ":converterPattern");
writer.writeAttribute(HtmlAttributes.VALUE, converterPattern, null);
writer.endElement(HtmlConstants.INPUT);
writer.startElement(HtmlConstants.INPUT, input);
writer.writeAttribute(HtmlAttributes.TYPE, "hidden", false);
writer.writeIdAttribute(id);
writer.writeNameAttribute(id);
writer.writeAttribute(HtmlAttributes.VALUE, hour + ":" + minute + ":" + second, false);
writer.endElement(HtmlConstants.INPUT);
String dateTextBoxId = (String) input.getAttributes().get(ATTR_CALENDAR_DATE_INPUT_ID);
if (dateTextBoxId != null) {
String[] cmds = {"tbgInitTimeParse('" + id + "', '" + dateTextBoxId + "');"};
HtmlRendererUtil.writeScriptLoader(facesContext, SCRIPTS, cmds);
}