Converter converter = uicalendar.getConverter(); if (converter != null) { return converter.getAsObject(context, uicalendar, submittedValue); ValueExpression ve = uicalendar.getValueExpression("value"); if (ve != null) { Class type = ve.getType(context.getELContext()); if (type != null && type != Object.class && type != Date.class) { Converter converter = context.getApplication().createConverter(type); if (converter != null) { return converter.getAsObject(context, uicalendar, submittedValue);
public static final String getValue(FacesContext context, UICalendar calendar, Object value, String pattern) { //first ask the converter if (calendar.getConverter() != null) { return calendar.getConverter().getAsString(context, calendar, value); } else if (value instanceof String) { return (String) value; } //Use built-in converter else if (value instanceof Date) { SimpleDateFormat format = new SimpleDateFormat(pattern, calendar.calculateLocale(context)); format.setTimeZone(calculateTimeZone(calendar.getTimeZone())); return format.format((Date) value); } else { //Delegate to global defined converter (e.g. joda or java8) ValueExpression ve = calendar.getValueExpression("value"); if (ve != null) { Class type = ve.getType(context.getELContext()); if (type != null && type != Object.class && type != Date.class) { Converter converter = context.getApplication().createConverter(type); if (converter != null) { return converter.getAsString(context, calendar, value); } } } throw new FacesException("Value could be either String or java.util.Date"); } }
public void applyAttachedObject(FacesContext context, UIComponent parent) { FaceletContext ctx = (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY); // cast to a ValueHolder ValueHolder vh = (ValueHolder) parent; ValueExpression ve = null; Converter c = null; if (owner.getBinding() != null) { ve = owner.getBinding().getValueExpression(ctx, Converter.class); c = (Converter) ve.getValue(ctx); } if (c == null) { c = this.createConverter(ctx); if (ve != null) { ve.setValue(ctx, c); } } if (c == null) { throw new TagException(owner.getTag(), "No Converter was created"); } owner.setAttributes(ctx, c); vh.setConverter(c); Object lv = vh.getLocalValue(); FacesContext faces = ctx.getFacesContext(); if (lv instanceof String) { vh.setValue(c.getAsObject(faces, parent, (String) lv)); } }
protected void encodeSuggestionsAsList(FacesContext context, AutoComplete ac, List items, Converter converter) throws IOException { ResponseWriter writer = context.getResponseWriter(); String var = ac.getVar(); Map<String, Object> requestMap = context.getExternalContext().getRequestMap(); boolean pojo = var != null; UIComponent itemtip = ac.getFacet("itemtip"); String value = converter == null ? String.valueOf(ac.getItemValue()) : converter.getAsString(context, ac, ac.getItemValue()); writer.writeAttribute("data-item-value", value, null); writer.writeAttribute("data-item-label", ac.getItemLabel(), null); if (itemtip != null && itemtip.isRendered()) { writer.startElement("li", null); writer.writeAttribute("class", AutoComplete.ITEMTIP_CONTENT_CLASS, null); itemtip.encodeAll(context); writer.endElement("li");
Converter converter = valueHolder.getConverter(); if(converter != null) { return converter.getAsString(facesContext, component, value); ValueExpression expr = component.getValueExpression("value"); if(expr != null) { Class<?> valueType = expr.getType(facesContext.getELContext()); Converter converterForType = facesContext.getApplication().createConverter(valueType); return converterForType.getAsString(facesContext, component, value);
private static String stringValue(UIComponent component, Long toConvert, FacesContext context) { Converter converter = context.getApplication().createConverter("javax.faces.Number"); return converter.getAsString(context, component, toConvert); }
public void processAction(ActionEvent actionEvent) throws AbortProcessingException { FacesContext context = getFacesContext(); ELContext elContext = context.getELContext(); ValueExpression updateBinding = getAssignToExpression(); if (updateBinding != null && (!updateBinding.isReadOnly(elContext))) { String requestValue = context.getExternalContext().getRequestParameterMap().get(getName()); Object convertedValue = requestValue; if (requestValue != null) { Class<?> type = updateBinding.getType(elContext); Converter converter = createConverter(context, type); if (null != converter) { convertedValue = converter.getAsObject(context, this, requestValue); } } if (null != convertedValue) { updateBinding.setValue(elContext, convertedValue); } } }
/** * Convert an object of type targetClass to text by delegating to a converter obtained from the * Faces application. */ public String convertToString(Class<?> targetClass, Object value) { UIComponent component = getComponent(); Converter converter = app.createConverter(targetClass); if (null == converter) { // PENDING(edburns): I18N throw new FacesException("Cannot create Converter to convert " + targetClass.getName() + " value " + value + " to string."); } FacesContext currentInstance = FacesContext.getCurrentInstance(); try { return converter.getAsString(currentInstance, component, value); } catch (ConverterException ce) { addConversionErrorMessage(currentInstance, component, ce); return null; } }
Object value = valueHolder.getValue(); if (value == null) { return ""; Converter converter = valueHolder.getConverter(); if (converter == null) { Class valueType = value.getClass(); converter = context.getApplication().createConverter(valueType); throw new FacesException("Value of " + component.getClientId(context) + " must be a List or an Array."); for (int i = 0; i < collectionSize; i++) { Object object = collection.get(i); builder.append(converter.getAsString(context, component, object)); return converter.getAsString(context, component, value); return (String) component.getAttributes().get("alt");
/** * Convert the <code>textValue</code> to an object of type targetClass by delegating to a * converter. */ public Object convertToObject(Class<?> targetClass, String textValue) { UIComponent component = getComponent(); Converter converter = app.createConverter(targetClass); if (null == converter) { // PENDING(edburns): I18N FacesException e = new FacesException( "Cannot create Converter to convert value " + textValue + " to instance of target class " + targetClass.getName() + '.'); throw e; } FacesContext currentInstance = FacesContext.getCurrentInstance(); try { return converter.getAsObject(currentInstance, component, textValue); } catch (ConverterException ce) { addConversionErrorMessage(currentInstance, component, ce); return null; } }
StringBuffer str = new StringBuffer(); if (uic instanceof CommandSortHeader) { if (uic.getChildCount() > 0) { Iterator iter = uic.getChildren().iterator(); while (iter.hasNext()) { UIComponent child = (UIComponent) iter.next(); Object value = uic.getAttributes().get("value"); if (value == null) { ValueBinding vb = uic.getValueBinding("value"); converter = ((ValueHolder)uic).getConverter(); converter = FacesContext.getCurrentInstance().getApplication().createConverter(value.getClass()); str.append(converter.getAsString(FacesContext.getCurrentInstance(), uic, value)); } else { str.append(value);
public static Locale getAsLocale(FacesContext facesContext, AbstractCalendar calendar, Object locale) { if (calendar == null || facesContext == null) { return null; } Locale localeValue = null; if (locale instanceof Locale) { localeValue = (Locale) locale; } else if (locale instanceof String) { localeValue = parseLocale((String) locale); } else if (locale != null) { Application application = facesContext.getApplication(); Converter converter = application.createConverter(locale.getClass()); if (null != converter) { localeValue = parseLocale(converter.getAsString(facesContext, calendar, locale)); } else { throw new FacesException("Wrong locale attibute type or there is no converter for custom attibute type"); } } return localeValue; }
ValueExpression valueExpression = component.getValueExpression("value"); Method getter = ExpressionInspector.getMethodReference(context.getELContext(), valueExpression).getMethod(); Class<?> returnType = getter.getReturnType(); throw new IllegalArgumentException(valueExpression.getExpressionString() + " does not resolve to Collection."); converter = context.getApplication().createConverter(forClass); collection.add(converter == null ? trimmed : converter.getAsString(context, component, trimmed));
Object obj = calendar.getConverter().getAsObject(context, calendar, value.toString()); if (obj instanceof Date) { return (Date) obj; Converter converter = context.getApplication().createConverter(value.getClass()); if (converter != null) { Object obj = converter.getAsObject(context, calendar, value.toString()); if (obj instanceof Date) { return (Date) obj; throw new FacesException("Value could be either String or java.util.Date");
Converter converter = ((ValueHolder) component).getConverter(); if (converter == null) { final ValueExpression expression = component.getValueExpression("value"); if (expression != null) { final Class valueType = expression.getType(facesContext.getELContext()); if (valueType != null) { converter = facesContext.getApplication().createConverter(valueType); converter.getAsObject(facesContext, component, stringValue);
public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException { // get the converter (if any) registered with this component Converter converter = null; if (uiComponent instanceof ValueHolder) { converter = ((ValueHolder) uiComponent).getConverter(); } // if we didn't find a converter specifically registered with the component // then get the default converter for the type of the value binding, // if it exists ValueBinding valueBinding = uiComponent.getValueBinding("value"); if (converter == null && valueBinding != null) { Class valueBindingClass = valueBinding.getType(facesContext); if (valueBindingClass != null) { converter = facesContext.getApplication() .createConverter(valueBindingClass); } } if (converter != null) { return converter.getAsObject(facesContext, uiComponent, (String) submittedValue); } else if (submittedValue != null) { return (String) submittedValue; } else { return null; } }
&& submittedValue == null && !input.isLocalValueSet() && context.isValidationFailed() && !input.isValid()) { return null; value = valueHolder.getValue(); Converter converter = valueHolder.getConverter(); if (converter == null) { Class valueType = value.getClass(); converter = context.getApplication().createConverter(valueType); return converter.getAsString(context, component, value);
protected void encodeMultipleMarkup(FacesContext context, AutoComplete ac) throws IOException { ResponseWriter writer = context.getResponseWriter(); String clientId = ac.getClientId(context); String inputId = clientId + "_input"; context.getExternalContext().getRequestMap().put(var, value); itemValue = ac.getItemValue(); itemLabel = ac.getItemLabel(); String tokenValue = converter != null ? converter.getAsString(context, ac, itemValue) : String.valueOf(itemValue); String itemStyleClass = AutoComplete.TOKEN_DISPLAY_CLASS; if (ac.getItemStyleClass() != 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 void invokeContextCallback(FacesContext context, UIComponent target) { component = target; Converter rowKeyConverter = (Converter) target.getAttributes().get("rowKeyConverter"); Collection<?> keys = (Collection<?>) context.getApplication().evaluateExpressionGet(context, "#{" + image + "}", Object.class); if (keys == null) { return; } for (Object key : keys) { String convertedKey; if (rowKeyConverter != null) { convertedKey = rowKeyConverter.getAsString(context, target, key); } else { convertedKey = key.toString(); } convertedKeys.add(convertedKey); } }