Example usage for org.apache.wicket.util.convert ConversionException ConversionException

List of usage examples for org.apache.wicket.util.convert ConversionException ConversionException

Introduction

In this page you can find the example usage for org.apache.wicket.util.convert ConversionException ConversionException.

Prototype

public ConversionException(final String message, final Throwable cause) 

Source Link

Document

Construct exception with message and cause.

Usage

From source file:abid.password.wicket.converters.ExtendedPasswordConverter.java

License:Apache License

private void error(String value, String errorKey, Exception e) {
    ConversionException exception = new ConversionException(
            "Could not convert password into '" + ExtendedPassword.class.getName() + "'", e);
    exception.setSourceValue(value);//  w  w w  . ja  v  a  2s  . c om
    exception.setResourceKey(getClass().getSimpleName() + "." + errorKey);
    throw exception;
}

From source file:com.genericconf.bbbgateway.services.DateConverter.java

License:Apache License

@Override
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
    final String val = reader.getValue();
    if (StringUtils.isEmpty(val) || "null".equals(val.toLowerCase())) {
        return null;
    }/*  w  ww  .  ja  v a 2 s .c  o  m*/
    synchronized (dateFormat) {
        try {
            return dateFormat.parse(val);
        } catch (ParseException e) {
            throw new ConversionException("error unmarshalling date: " + val, e);
        }
    }
}

From source file:com.googlecode.wicket.kendo.ui.form.datetime.local.AjaxDateTimePicker.java

License:Apache License

/**
 * Gets a new {@link LocalDateTime} {@link IConverter}.
 * //from  w w w.  j a  va2  s  .c om
 * @param format the time format
 * @return the converter
 */
private static IConverter<LocalDateTime> newConverter(final String pattern) {
    return new IConverter<LocalDateTime>() {

        private static final long serialVersionUID = 1L;

        @Override
        public LocalDateTime convertToObject(String value, Locale locale) throws ConversionException {
            try {
                return LocalDateTime.parse(value, DateTimeFormatter.ofPattern(pattern, locale));
            } catch (DateTimeParseException e) {
                throw new ConversionException(e.getMessage(), e);
            }
        }

        @Override
        public String convertToString(LocalDateTime datetime, Locale locale) {
            return datetime != null ? datetime.format(DateTimeFormatter.ofPattern(pattern, locale)) : null;
        }
    };
}

From source file:com.googlecode.wicket.kendo.ui.form.datetime.local.DatePicker.java

License:Apache License

/**
 * Gets a new date {@link IConverter}./*  w w w. j a  va 2s. co  m*/
 * 
 * @param format the date format
 * @return the converter
 */
private static IConverter<LocalDate> newConverter(final String pattern) {
    return new IConverter<LocalDate>() {

        private static final long serialVersionUID = 1L;

        @Override
        public LocalDate convertToObject(String value, Locale locale) throws ConversionException {
            try {
                return LocalDate.parse(value, DateTimeFormatter.ofPattern(pattern, locale));
            } catch (DateTimeParseException e) {
                throw new ConversionException(e.getMessage(), e);
            }
        }

        @Override
        public String convertToString(LocalDate date, Locale locale) {
            return date != null ? date.format(DateTimeFormatter.ofPattern(pattern, locale)) : null;
        }
    };
}

From source file:com.googlecode.wicket.kendo.ui.form.datetime.local.TimePicker.java

License:Apache License

/**
 * Gets a new time {@link IConverter}./*from   w ww.j  a  v a2  s . c o  m*/
 * 
 * @param format the time format
 * @return the converter
 */
private static IConverter<LocalTime> newConverter(final String pattern) {
    return new IConverter<LocalTime>() {

        private static final long serialVersionUID = 1L;

        @Override
        public LocalTime convertToObject(String value, Locale locale) throws ConversionException {
            try {
                return LocalTime.parse(value, DateTimeFormatter.ofPattern(pattern, locale));
            } catch (DateTimeParseException e) {
                throw new ConversionException(e.getMessage(), e);
            }
        }

        @Override
        public String convertToString(LocalTime time, Locale locale) {
            return time != null ? time.format(DateTimeFormatter.ofPattern(pattern, locale)) : null;
        }
    };
}

From source file:com.servoy.j2db.server.headlessclient.dataui.FormatConverter.java

License:Open Source License

/**
 * @see wicket.util.convert.IConverter#convertToObject(java.lang.String, java.util.Locale)
 *//* ww  w . j  ava  2  s . co  m*/
public Object convertToObject(String value, Locale locale) {
    if (format == null || value == null)
        return null;

    try {
        if (!eventExecutor.getValidationEnabled())
            return value;
        if (editFormatter != null) {
            try {
                return convertString(value, editFormatter);
            } catch (ParseException pe) {
                return convertString(value, displayFormatter);
            }
        } else {
            return convertString(value, displayFormatter);
        }
    } catch (Exception ex) {
        String extraMsg = ""; //$NON-NLS-1$
        if (formComponent instanceof IComponent && ((IComponent) formComponent).getName() != null) {
            extraMsg = " on component " + ((IComponent) formComponent).getName(); //$NON-NLS-1$
        }
        if (formComponent instanceof IDisplayData) {
            extraMsg += " with dataprovider: " + ((IDisplayData) formComponent).getDataProviderID(); //$NON-NLS-1$
        }
        throw new ConversionException("Can't convert from string '" + value + "' to object with format: " //$NON-NLS-1$//$NON-NLS-2$
                + format.getEditFormat() + extraMsg, ex).setConverter(this);
    }
}

From source file:com.servoy.j2db.server.headlessclient.dataui.WebDataField.java

License:Open Source License

public static IConverter getTextConverter(final ParsedFormat fp, final Locale l, final String name,
        final String dataProviderID) {
    if (fp.isAllUpperCase()) {
        return new IConverter() {
            public String convertToString(Object value, Locale locale) {
                if (value == null)
                    return "";
                return value.toString().toUpperCase(l);
            }//from   w  ww. j av a  2  s.c o m

            public Object convertToObject(String value, Locale locale) {
                if (value == null)
                    return null;
                return value.toUpperCase(l);
            }
        };
    }
    if (fp.isAllLowerCase()) {
        return new IConverter() {
            public String convertToString(Object value, Locale locale) {
                if (value == null)
                    return "";
                return value.toString().toLowerCase(l);
            }

            public Object convertToObject(String value, Locale locale) {
                if (value == null)
                    return null;
                return value.toLowerCase(l);
            }
        };
    }
    if (fp.getDisplayFormat() != null) {
        try {
            final FixedMaskFormatter displayFormatter = new FixedMaskFormatter(fp.getDisplayFormat());
            displayFormatter.setValueContainsLiteralCharacters(!fp.isRaw());
            if (fp.getPlaceHolderString() != null)
                displayFormatter.setPlaceholder(fp.getPlaceHolderString());
            else if (fp.getPlaceHolderCharacter() != 0)
                displayFormatter.setPlaceholderCharacter(fp.getPlaceHolderCharacter());

            return new IConverter() {
                public String convertToString(Object value, Locale locale) {
                    if (value == null)
                        return ""; //$NON-NLS-1$
                    try {
                        return displayFormatter.valueToString(value);
                    } catch (ParseException e) {
                        Debug.log(e);
                        return value.toString();
                    }
                }

                public Object convertToObject(String value, Locale locale) {
                    if (value == null || "".equals(value.trim())) //$NON-NLS-1$
                        return null;
                    try {
                        return displayFormatter.parse(value);
                    } catch (Exception e) {
                        String extraMsg = ""; //$NON-NLS-1$
                        if (name != null) {
                            extraMsg = " on component " + name; //$NON-NLS-1$
                        }
                        extraMsg += " with dataprovider: " + dataProviderID; //$NON-NLS-1$
                        throw new ConversionException(
                                "Can't convert from string '" + value + "' to object with format: " //$NON-NLS-1$//$NON-NLS-2$
                                        + fp.getEditFormat() + extraMsg, e).setConverter(this);
                    }
                }
            };
        } catch (ParseException e) {
            Debug.error("format problem: " + fp.getDisplayFormat(), e); //$NON-NLS-1$
            return null;
        }
    }
    return null;
}

From source file:com.userweave.components.authorization.AuthOnlyCheckBox.java

License:Open Source License

/**
 * @see org.apache.wicket.markup.html.form.FormComponent#convertValue(String[])
 *//*from  w  ww.j  a va2s .com*/
@Override
protected Object convertValue(String[] value) {
    String tmp = value != null && value.length > 0 ? value[0] : null;
    try {
        return Strings.toBoolean(tmp);
    } catch (StringValueConversionException e) {
        throw new ConversionException("Invalid boolean input value posted \"" + getInput() + "\"", e)
                .setTargetType(Boolean.class);
    }
}

From source file:fi.ilmoeuro.membertrack.plumbing.WicketDateConverter.java

License:Open Source License

@Override
public LocalDate convertToObject(String val, Locale loc) throws ConversionException {
    try {//from w  ww.j a  v a  2 s .  c om
        return FINNISH_FORMATTER.parse(val, LocalDate::from);
    } catch (RuntimeException e) {
        String message = String.format("Couldn't convert \"%s\" to date", val);
        if (e.getMessage() != null) {
            message = e.getMessage();
        }
        throw new ConversionException(message, e);
    }
}

From source file:guru.mmp.application.web.converters.ISO8601Converter.java

License:Apache License

@Override
public LocalDateTime convertToObject(String value, Locale locale) throws ConversionException {
    try {//from   ww w .ja  va2s .c  o  m
        return ISO8601.toLocalDateTime(value);
    } catch (Throwable e) {
        throw new ConversionException(
                String.format("Failed to convert the ISO8601 timestamp (%s) to a Date", value), e);
    }
}