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")); } }
private void addConversionErrorMessage(FacesContext context, ConverterException ce) { FacesMessage message; String converterMessageString = getConverterMessage(); if (null != converterMessageString) { message = new FacesMessage(FacesMessage.SEVERITY_ERROR, converterMessageString, converterMessageString); } else { message = ce.getFacesMessage(); if (message == null) { message = MessageFactory.getMessage(context, CONVERSION_MESSAGE_ID); if (message.getDetail() == null) { message.setDetail(ce.getMessage()); } } } context.addMessage(getClientId(context), message); }
Class<?> modelType = valueExpression.getType(context.getELContext()); Object value = valueExpression.getValue(context.getELContext()); if (value != null) { convertedValue = convertSelectManyValuesForModel(context, uiSelectMany, value.getClass(), newValues); Object[] params = { (newValues == null) ? "" : stream(newValues).collect(joining("")), valueExpression.getExpressionString() }; throw new ConverterException( getExceptionMessage(CONVERSION_ERROR_MESSAGE_ID, params));
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); throw new ConverterException(message);
@Override public String getAsString(FacesContext context, UIComponent component, Object value) { for (int i = 0; i < list.size(); i++) { if (list.get(i).equals(value)) { return Integer.toString(i); } } throw new ConverterException( createError(ERROR_VALUE_NOT_IN_LIST, value == null ? "null" : value.toString(), component.getClientId(context)) ); }
@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); } }
ExternalContext externalContext = context.getExternalContext(); File file = new File(externalContext.getRealPath("") + imagePath); inputStream = new FileInputStream(file); throw new ConverterException(e);
public Object getAsObject(FacesContext context, UIComponent component, String value) { Converter delegate = getDelegate(context); if (delegate != null) { return delegate.getAsObject(context, component, value); } else { throw new ConverterException( MessageUtils.getExceptionMessage( MessageUtils.CANNOT_CONVERT_ID, converterId != null ? converterId.getExpressionString() : "", binding != null ? binding.getExpressionString() : "")); } }
public String getAsString(FacesContext context, UIComponent component, Object value) { Converter delegate = getDelegate(context); if (delegate != null) { return delegate.getAsString(context, component, value); } else { throw new ConverterException( MessageUtils.getExceptionMessage( MessageUtils.CANNOT_CONVERT_ID, converterId != null ? converterId.getExpressionString() : "", binding != null ? binding.getExpressionString() : "")); } }
public String getAsString(final FacesContext fc, final UIComponent component, final Object value) { if (value == null) { final Locale defaultLocale = fc.getApplication().getDefaultLocale(); if (defaultLocale == null) { return null; } return getLocaleString(defaultLocale, separator); } if (value instanceof String) { return (String) value; } else if (value instanceof Locale) { return getLocaleString((Locale) value, separator); } else { throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Wrong type: '" + value.getClass().getSimpleName() + "' is not 'Locale'.", Constants.EMPTY_STRING)); } }
private static void addConverterMessage(FacesContext context, UIComponent component, String label, String submittedValue, ConverterException ce, String converterMessage) { FacesMessage message; if (!isEmpty(converterMessage)) { message = createError(converterMessage, submittedValue, label); } else { message = ce.getFacesMessage(); if (message == null) { // If the converter didn't add a FacesMessage, set a generic one. message = createError("Conversion failed for {0} because: {1}", submittedValue, ce.getMessage()); } } context.addMessage(component.getClientId(context), message); }
/** {@inheritDoc} */ @Override public Object getAsObject(final FacesContext context, final UIComponent component, final String value) { final KeyedEntityDescriptor<Object, Serializable> descriptor = this.getDescriptor(context); DictionaryConverter.LOGGER.debug("Getting object value of {}, for descriptor {}.", value, descriptor); final Class<?> targetIdClazz = descriptor.getKeyProperty().getPropertyType(); Converter converter = null; if (!String.class.equals(targetIdClazz)) { converter = context.getApplication().createConverter(targetIdClazz); } Object result = null; if (!StringUtil.isEmptyString(value)) { final Serializable identifier; if (CheckUtil.isNull(converter)) { identifier = String.class.cast(value); } else { identifier = (Serializable) converter.getAsObject(context, component, value); } try { final Dictionary dictionary = this.getModel(context).getExtension(Dictionary.class); result = dictionary.lookup(descriptor, identifier); } catch (final DictionaryException e) { throw new ConverterException(e); } } return result; }
@Override public Object getAsObject(FacesContext facesContext, UIComponent component, String submittedValue) { if (submittedValue.trim().equals("")) { return null; }else if (locs==null || locs.isEmpty()) { throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid player")); } else { try { int number = Integer.parseInt(submittedValue); for (Location location : locs) { if (location.getId() == number) { return location; } } } catch (NumberFormatException exception) { throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Conversion Error", "Not a valid player")); } return null; } }
date = userData.parse(); } catch (ParseException e) { Object[] args = {uiComponent.getId()}; throw new ConverterException(MessageUtils.getMessage(Constants.TOMAHAWK_DEFAULT_BUNDLE, FacesMessage.SEVERITY_ERROR, DATE_MESSAGE_ID, args, context)); return inputDate.getConverter().getAsObject(context, inputDate, (String) submittedValue);
protected void handleConverterException(FacesContext context, ConverterException e) { setValid(false); FacesMessage facesMessage = e.getFacesMessage(); if (facesMessage != null) { context.addMessage(getClientId(context), facesMessage); } else { Object[] args = new Object[] { UIComponentUtil.getLabel(this) }; FacesMessageUtil.addErrorComponentMessage(context, this, CONVERSION_MESSAGE_ID, args); } }
public Object _getAsObject(FacesContext facesContext, UIComponent uiComponent, String value) { if (facesContext == null) throw new NullPointerException("facesContext"); if (uiComponent == null) throw new NullPointerException("uiComponent"); if (value != null) { value = value.trim(); if (value.length() > 0) { NumberFormat format = getNumberFormat(facesContext); format.setParseIntegerOnly(_integerOnly); try { return format.parse(value); } catch (ParseException e) { throw new ConverterException(MessageUtils.getMessage(facesContext, CONVERSION_MESSAGE_ID, new Object[]{uiComponent.getId(),value}), e); } } } return null; }
public String convertDeclarativeKeyToString(FacesContext context, DeclarativeModelKey declarativeKey) throws ConverterException { try { UIComponent component = findDeclarativeModel(declarativeKey.getModelId()); TreeModelAdaptor adaptor = (TreeModelAdaptor) component; Converter rowKeyConverter = adaptor.getRowKeyConverter(); if (rowKeyConverter == null) { throw new ConverterException(MessageFormat.format(CONVERTER_FOR_MODEL_UNAVAILABLE, declarativeKey.getModelId())); } return rowKeyConverter.getAsString(context, (UIComponent) adaptor, declarativeKey.getModelKey()); } catch (ConverterException e) { throw e; } catch (Exception e) { throw new ConverterException(e.getMessage(), e); } }
public Object getAsObject(final FacesContext context, final UIComponent comp, final String value) { throw new ConverterException("Does not yet support converting String to Date"); }
/** * @deprecated */ public static ConverterException wrappedByConverterException( Converter converter, FacesContext context, Object[] args, Throwable t) { FacesMessage facesMessage = null; for (Class c = converter.getClass(); c != null && c != Object.class; c = c .getSuperclass()) { String conversionMessage = createConversionMessage(c); facesMessage = FacesMessageUtil.getMessage(context, conversionMessage, args); if (facesMessage.getSummary() != null || facesMessage.getDetail() != null) { break; } } return new ConverterException(facesMessage, t); }
private void addConversionErrorMessage(FacesContext context, ConverterException ce) { FacesMessage message; String converterMessageString = getConverterMessage(); if (null != converterMessageString) { message = new FacesMessage(FacesMessage.SEVERITY_ERROR, converterMessageString, converterMessageString); } else { message = ce.getFacesMessage(); if (message == null) { message = MessageFactory.getMessage(context, CONVERSION_MESSAGE_ID); if (message.getDetail() == null) { message.setDetail(ce.getMessage()); } } } context.addMessage(getClientId(context), message); }