public ColorPickerBase() { setRendererType(DEFAULT_RENDERER); }
@Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { ColorPicker colorPicker = (ColorPicker) component; Converter converter = colorPicker.getConverter(); String value; if (converter != null) { value = converter.getAsString(context, component, colorPicker.getValue()); } else { value = (String) colorPicker.getValue(); } encodeMarkup(context, colorPicker, value); encodeScript(context, colorPicker, value); }
protected void encodeScript(FacesContext context, ColorPicker colorPicker, String value) throws IOException { String clientId = colorPicker.getClientId(context); WidgetBuilder wb = getWidgetBuilder(context); wb.init("ColorPicker", colorPicker.resolveWidgetVar(), clientId) .attr("mode", colorPicker.getMode()) .attr("color", value, null); encodeClientBehaviors(context, colorPicker); wb.finish(); } }
protected void encodeMarkup(FacesContext context, ColorPicker colorPicker, String value) throws IOException { ResponseWriter writer = context.getResponseWriter(); String clientId = colorPicker.getClientId(context); String inputId = clientId + "_input"; boolean isPopup = colorPicker.getMode().equals("popup"); String styleClass = colorPicker.getStyleClass(); styleClass = styleClass == null ? ColorPicker.STYLE_CLASS : ColorPicker.STYLE_CLASS + " " + styleClass; writer.writeAttribute("id", clientId, "id"); writer.writeAttribute("class", styleClass, "styleClass"); if (colorPicker.getStyle() != null) { writer.writeAttribute("style", colorPicker.getStyle(), "style"); encodeButton(context, colorPicker, clientId, value); encodeInline(context, colorPicker, clientId); writer.writeAttribute("type", "hidden", null); String onchange = colorPicker.getOnchange(); if (!isValueBlank(onchange)) { writer.writeAttribute("onchange", onchange, null); renderPassThruAttributes(context, colorPicker, null);
@Override public void decode(FacesContext context, UIComponent component) { ColorPicker colorPicker = (ColorPicker) component; if (!shouldDecode(colorPicker)) { return; } String paramName = colorPicker.getClientId(context) + "_input"; Map<String, String> params = context.getExternalContext().getRequestParameterMap(); if (params.containsKey(paramName)) { String submittedValue = params.get(paramName); if (!COLOR_HEX_PATTERN.matcher(submittedValue).matches()) { return; } Converter converter = colorPicker.getConverter(); if (converter != null) { colorPicker.setSubmittedValue( converter.getAsObject(context, component, submittedValue)); } else { colorPicker.setSubmittedValue(submittedValue); } } }
public String getWidgetVar() { return (String) getStateHelper().eval(PropertyKeys.widgetVar, null); }
@Override public String resolveWidgetVar() { return ComponentUtils.resolveWidgetVar(getFacesContext(), this); } }
protected void encodeButton(FacesContext context, ColorPicker colorPicker, String clientId, String value) throws IOException { ResponseWriter writer = context.getResponseWriter(); writer.startElement("button", null); writer.writeAttribute("id", clientId + "_button", null); writer.writeAttribute("type", "button", null); writer.writeAttribute("class", HTML.BUTTON_TEXT_ONLY_BUTTON_CLASS, null); renderAccessibilityAttributes(context, colorPicker); //text writer.startElement("span", null); writer.writeAttribute("class", HTML.BUTTON_TEXT_CLASS, null); writer.write("<span id=\"" + clientId + "_livePreview\" " + "style=\"overflow:hidden;width:1em;height:1em;display:block;border:solid 1px #000;text-indent:1em;white-space:nowrap;"); if (value != null) { writer.write("background-color:#" + value); } writer.write("\">Live Preview</span>"); writer.endElement("span"); writer.endElement("button"); }
public ColorPicker() { setRendererType(DEFAULT_RENDERER); }
protected void encodeScript(FacesContext context, ColorPicker colorPicker, String value) throws IOException { String clientId = colorPicker.getClientId(context); WidgetBuilder wb = getWidgetBuilder(context); wb.initWithDomReady("ColorPicker", colorPicker.resolveWidgetVar(), clientId) .attr("mode", colorPicker.getMode()) .attr("color", value, null); encodeClientBehaviors(context, colorPicker); wb.finish(); } }
@Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { ColorPicker colorPicker = (ColorPicker) component; Converter converter = colorPicker.getConverter(); String value; if (converter != null) { value = converter.getAsString(context, component, colorPicker.getValue()); } else { value = (String) colorPicker.getValue(); } encodeMarkup(context, colorPicker, value); encodeScript(context, colorPicker, value); }
public void setOnchange(String onchange) { getStateHelper().put(PropertyKeys.onchange, onchange); }
public void setMode(String mode) { getStateHelper().put(PropertyKeys.mode, mode); }
public String getStyleClass() { return (String) getStateHelper().eval(PropertyKeys.styleClass, null); }
public void setWidgetVar(String widgetVar) { getStateHelper().put(PropertyKeys.widgetVar, widgetVar); }
public String getStyle() { return (String) getStateHelper().eval(PropertyKeys.style, null); }
public String getOnchange() { return (String) getStateHelper().eval(PropertyKeys.onchange, null); }
public String getMode() { return (String) getStateHelper().eval(PropertyKeys.mode, "popup"); }
public void setStyle(String style) { getStateHelper().put(PropertyKeys.style, style); }
public void setStyleClass(String styleClass) { getStateHelper().put(PropertyKeys.styleClass, styleClass); }