public Object getAsObject(final FacesContext context, final UIComponent comp, final String value) { throw new ConverterException("Does not yet support converting String to Date"); }
@Override public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException { Editor editor = (Editor) component; String value = (String) submittedValue; Converter converter = ComponentUtils.getConverter(context, component); if (converter != null) { return converter.getAsObject(context, editor, value); } return value; } }
protected String getOptionAsString(FacesContext context, UIComponent component, Converter converter, Object value) throws ConverterException { if (!(component instanceof ValueHolder)) { return value == null ? null : value.toString(); } if (converter == null) { if (value == null) { return ""; } else if (value instanceof String) { return (String) value; } else { Converter implicitConverter = findImplicitConverter(context, component); return implicitConverter == null ? value.toString() : implicitConverter.getAsString(context, component, value); } } else { return converter.getAsString(context, component, value); } }
@Override @SuppressWarnings("unchecked") public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException { try { OrderList ol = (OrderList) component; List orderedList = new ArrayList(); Converter converter = ol.getConverter(); String[] values = (String[]) submittedValue; for (String item : values) { if (isValueBlank(item)) { continue; } Object convertedValue = converter != null ? converter.getAsObject(context, ol, item) : item; if (convertedValue != null) { orderedList.add(convertedValue); } } return orderedList; } catch (Exception exception) { throw new ConverterException(exception); } }
private Object convertValue(FacesContext context, String submittedItemValue) { Converter converter = ComponentUtils.getConverter(context, this); if (converter == null) { return submittedItemValue; } else { return converter.getAsObject(context, this, submittedItemValue); } }
@Override public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException { if (submittedValue == null) { submittedValue = 0; } try { return ((submittedValue instanceof Integer) ? submittedValue : Integer.parseInt(submittedValue.toString())); } catch (NumberFormatException e) { throw new ConverterException(e); } }
@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); }
@Override public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException { TextEditor editor = (TextEditor) component; String value = (String) submittedValue; Converter converter = ComponentUtils.getConverter(context, component); if (converter != null) { return converter.getAsObject(context, editor, value); } return value; } }
private int getStyle(String style) { if ("default".equals(style)) { return (DateFormat.DEFAULT); } else if ("short".equals(style)) { return (DateFormat.SHORT); } else if ("medium".equals(style)) { return (DateFormat.MEDIUM); } else if ("long".equals(style)) { return (DateFormat.LONG); } else if ("full".equals(style)) { return (DateFormat.FULL); } else { throw new ConverterException("Invalid style '" + style + '\''); } } }
protected void encodeListItems(FacesContext context, MultiSelectListbox listbox, SelectItem[] selectItems) throws IOException { if (selectItems != null && selectItems.length > 0) { ResponseWriter writer = context.getResponseWriter(); Converter converter = ComponentUtils.getConverter(context, listbox); String itemValue = null; for (int i = 0; i < selectItems.length; i++) { SelectItem selectItem = selectItems[i]; itemValue = converter != null ? converter.getAsString(context, listbox, selectItem.getValue()) : String.valueOf(selectItem.getValue()); writer.startElement("li", null); writer.writeAttribute("class", MultiSelectListbox.ITEM_CLASS, null); writer.writeAttribute("data-value", itemValue, null); writer.startElement("span", listbox); writer.writeText(selectItem.getLabel(), null); writer.endElement("span"); if (selectItem instanceof SelectItemGroup) { SelectItemGroup group = (SelectItemGroup) selectItem; SelectItem[] groupItems = group.getSelectItems(); if (groupItems != null && groupItems.length > 0) { encodeGroupItems(context, listbox, group.getSelectItems()); } } writer.endElement("li"); } } }
private Object convertValue(FacesContext context, String submittedItemValue) { Converter converter = ComponentUtils.getConverter(context, this); if (converter == null) { return submittedItemValue; } else { return converter.getAsObject(context, this, submittedItemValue); } } }
public String getAsString(final FacesContext context, final UIComponent comp, final Object value) { if (value instanceof Date) { PrettyTime prettyTime; // Use locale of current viewer. Locale locale = context.getViewRoot().getLocale(); synchronized (PRETTY_TIME_LOCALE_MAP) { prettyTime = PRETTY_TIME_LOCALE_MAP.get(locale); if (prettyTime == null) { prettyTime = new PrettyTime(locale); PRETTY_TIME_LOCALE_MAP.put(locale, prettyTime); } } return prettyTime.format((Date) value); } throw new ConverterException("May only be used to convert java.util.Date objects. Got: " + (value != null ? value.getClass() : "null")); } }
@Override public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException { Converter converter = ComponentUtils.getConverter(context, component); if (converter != null) { String convertableValue = submittedValue == null ? null : submittedValue.toString(); return converter.getAsObject(context, component, convertableValue); } else { return submittedValue; } }
@Override @SuppressWarnings("unchecked") public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException { try { PickList pickList = (PickList) component; String[][] value = (String[][]) submittedValue; String[] sourceValue = value[0]; String[] targetValue = value[1]; DualListModel model = new DualListModel(); pickList.populateModel(context, sourceValue, model.getSource()); pickList.populateModel(context, targetValue, model.getTarget()); return model; } catch (Exception exception) { throw new ConverterException(exception); } }
@Override public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException { String submittedValueString = (String) submittedValue; if (LangUtils.isValueBlank(submittedValueString)) { return null; } Converter converter = ComponentUtils.getConverter(context, component); if (converter != null) { return converter.getAsObject(context, component, submittedValueString); } return submittedValue; }
@SuppressWarnings("unchecked") public void populateModel(FacesContext context, String[] values, List model) { Converter converter = getConverter(); if (values != null) { for (String item : values) { if (LangUtils.isValueBlank(item)) { continue; } Object convertedValue = converter != null ? converter.getAsObject(context, this, item) : item; if (convertedValue != null) { model.add(convertedValue); } } } } }
compareValue = converter.getAsObject(context, component, (String) compareValue);
@Override public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException { Chips chips = (Chips) component; if (submittedValue == null || submittedValue.equals("")) { return null; } Converter converter = ComponentUtils.getConverter(context, component); String[] values = (String[]) submittedValue; List list = new ArrayList(); for (String value : values) { if (isValueBlank(value)) { continue; } Object convertedValue = converter != null ? converter.getAsObject(context, chips, value) : value; if (convertedValue != null) { list.add(convertedValue); } } return list; } }
@Override public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue) throws ConverterException { AutoComplete ac = (AutoComplete) component; if (submittedValue == null || submittedValue.equals("") || ac.isMoreTextRequest(context)) { return null; } Converter converter = ComponentUtils.getConverter(context, component); if (ac.isMultiple()) { String[] values = (String[]) submittedValue; List list = new ArrayList(); for (String value : values) { if (isValueBlank(value)) { continue; } Object convertedValue = converter != null ? converter.getAsObject(context, ac, value) : value; if (convertedValue != null) { list.add(convertedValue); } } return list; } else { if (converter != null) { return converter.getAsObject(context, component, (String) submittedValue); } else { return submittedValue; } } }
@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); } } }