}
}
public void encodeEnd(final FacesContext facesContext, final UIComponent component) throws IOException {
final UITime time = (UITime) component;
final String id = time.getClientId(facesContext);
final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, time);
final String currentValue = getCurrentValue(facesContext, time);
if (LOG.isDebugEnabled()) {
LOG.debug("currentValue = '" + currentValue + "'");
}
final boolean readonly = time.isReadonly();
final boolean disabled = time.isDisabled();
final boolean required = time.isRequired();
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();
}
TobagoConfig tobagoConfig = TobagoConfig.getInstance(facesContext);
if (tobagoConfig.isClassicDateTimePicker()) {
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 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 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);
writer.writeAttribute(DataAttributes.CLASSIC_DATE_TIME_PICKER, "", false);
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, true);
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");
writer.writeNameAttribute(id);
writer.writeAttribute(HtmlAttributes.VALUE, hour + ":" + minute + ":" + second, false);
writer.endElement(HtmlElements.INPUT);
writer.endElement(HtmlElements.DIV);
} else {
// Todo: in Tobago 3.0 TimeRenderer should extend InRenderer, and this can cleaned up!
String pattern = null;
final Converter help = getConverter(facesContext, time);
if (help instanceof DateTimeConverter) {
final DateTimeConverter converter = (DateTimeConverter) help;
pattern = DateFormatUtils.findPattern(converter);
}
if (pattern == null) {
pattern = "HH-mm";
LOG.warn("Can't find the pattern for the converter! DatePicker may not work correctly. "
+ "Trying to use: '" + pattern + "'");
}
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
writer.startElement(HtmlElements.INPUT, time);
writer.writeAttribute(HtmlAttributes.TYPE, HtmlInputTypes.TEXT, false); // tbd: no "time"
writer.writeNameAttribute(id);
writer.writeIdAttribute(id);
HtmlRendererUtils.writeDataAttributes(facesContext, writer, time);
if (currentValue != null) {
writer.writeAttribute(HtmlAttributes.VALUE, currentValue, true);
}
if (title != null) {
writer.writeAttribute(HtmlAttributes.TITLE, title, true);
}
int maxLength = 0;
for (final Validator validator : time.getValidators()) {
if (validator instanceof LengthValidator) {
final LengthValidator lengthValidator = (LengthValidator) validator;
maxLength = lengthValidator.getMaximum();
}
/*if (validator instanceof RegexValidator) {
RegexValidator regexValidator = (RegexValidator) validator;
pattern = regexValidator.getPattern();
}*/
}
if (maxLength > 0) {
writer.writeAttribute(HtmlAttributes.MAXLENGTH, maxLength);
}
writer.writeAttribute(DataAttributes.PATTERN, pattern, true);
writer.writeAttribute(HtmlAttributes.READONLY, readonly);
writer.writeAttribute(HtmlAttributes.DISABLED, disabled);
final Integer tabIndex = time.getTabIndex();
if (tabIndex != null) {
writer.writeAttribute(HtmlAttributes.TABINDEX, tabIndex);
}
final Style style = new Style(facesContext, time);
writer.writeStyleAttribute(style);
final String placeholder = time.getPlaceholder();
if (!disabled && !readonly && StringUtils.isNotBlank(placeholder)) {
writer.writeAttribute(HtmlAttributes.PLACEHOLDER, placeholder, true);
}
writer.writeAttribute(HtmlAttributes.AUTOCOMPLETE, "off", false);
writer.writeClassAttribute(Classes.create(time));
/*if (component instanceof AbstractUIInput) {
String onchange = HtmlUtils.generateOnchange((AbstractUIInput) component, facesContext);
if (onchange != null) {
// TODO: create and use utility method to write attributes without quoting
// writer.writeAttribute(HtmlAttributes.ONCHANGE, onchange, null);
}
} */
writer.writeAttribute(HtmlAttributes.REQUIRED, required);
HtmlRendererUtils.renderFocus(id, time.isFocus(), ComponentUtils.isError(time), facesContext, writer);
HtmlRendererUtils.renderCommandFacet(time, facesContext, writer);
final String icon = ResourceManagerUtils.getImageWithPath(facesContext, "image/time.png");
if (icon != null) {
writer.writeAttribute(DataAttributes.DATE_TIME_ICON, icon, true);