public void encodeEnd(FacesContext facesContext,
UIComponent uiComponent) throws IOException {
UIOutput component = (UIOutput) uiComponent;
BoundedRangeModel model = (BoundedRangeModel) component.getValue();
if (model == null) {
LOG.warn("'null' value found! Using dummy Model instead!");
model = new DefaultBoundedRangeModel(40, 1, 0, 100);
}
String image = ResourceManagerUtil.getImageWithPath(facesContext, "image/1x1.gif");
String value1 = Integer.toString(model.getValue());
String value2 = Integer.toString(model.getMaximum() - model.getValue());
String title = (String) component.getAttributes().get(ATTR_TIP);
if (title == null) {
title = Integer.toString(100 * model.getValue()
/ (model.getMaximum() - model.getMinimum())) + " %";
}
Integer width = LayoutUtil.getLayoutWidth(component);
String width1 = value1;
String width2 = value2;
if (width != null) {
int value = (width -1) * model.getValue()
/ (model.getMaximum() - model.getMinimum());
width1 = Integer.toString(value);
width2 = Integer.toString((width - 2) - value);
}
TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
writer.startElement(HtmlConstants.SPAN, component);
writer.writeClassAttribute();
writer.writeAttribute(HtmlAttributes.TITLE, title, true);
writer.startElement(HtmlConstants.IMG, null);
StyleClasses color1Classes = new StyleClasses();
color1Classes.addClass("progress", "color1");
color1Classes.addMarkupClass(component, "progress", "color1");
writer.writeClassAttribute(color1Classes);
writer.writeAttribute(HtmlAttributes.SRC, image, false);
writer.writeAttribute(HtmlAttributes.ALT, title, true);
writer.writeAttribute(HtmlAttributes.WIDTH, width1, false);
writer.writeAttribute(HtmlAttributes.BORDER, 0);
writer.endElement(HtmlConstants.IMG);
writer.startElement(HtmlConstants.IMG, null);
StyleClasses color2Classes = new StyleClasses();
color2Classes.addClass("progress", "color2");
color2Classes.addMarkupClass(component, "progress", "color2");
writer.writeClassAttribute(color2Classes);
writer.writeAttribute(HtmlAttributes.SRC, image, false);
writer.writeAttribute(HtmlAttributes.ALT, title, true);
writer.writeAttribute(HtmlAttributes.WIDTH, width2, false);
writer.writeAttribute(HtmlAttributes.BORDER, 0);
writer.endElement(HtmlConstants.IMG);
writer.endElement(HtmlConstants.SPAN);
UIComponent facet = component.getFacet("complete");
if (model.getValue() == model.getMaximum() && facet != null
&& facet instanceof UICommand) {
UICommand command = (UICommand) facet;
writer.writeJavascript("Tobago.submitAction('" + command.getClientId(facesContext) + "');");
}