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 Throwable cause) 

Source Link

Document

Construct exception with cause.

Usage

From source file:br.com.digilabs.wicket.component.meiomask.MeioMaskField.java

License:Apache License

private ConversionException newConversionException(String value, Throwable cause) {
    return new ConversionException(cause).setResourceKey("PatternValidator").setVariable("input", value)
            .setVariable("pattern", maskFormatter.getMask());
}

From source file:com.googlecode.wicket.jquery.ui.kendo.datatable.DataSourceBehavior.java

License:Apache License

/**
 * Gets a new JSON object from the bean/* w  w w .j av a2  s.  c  om*/
 * @param bean T object
 * @return a new JSON object
 */
protected String newJsonRow(T bean) {
    JSONStringer stringer = new JSONStringer();

    try {
        stringer.object();

        for (IColumn<T> column : this.columns) {
            if (column instanceof PropertyColumn<?>) {
                PropertyColumn<T> pc = (PropertyColumn<T>) column;
                stringer.key(pc.getField()).value(pc.getValue(bean));
            }
        }

        stringer.endObject();
    } catch (JSONException e) {
        throw new ConversionException(e);
    }

    return stringer.toString();
}

From source file:com.googlecode.wicket.jquery.ui.plugins.datepicker.RangeDatePickerTextField.java

License:Apache License

@SuppressWarnings("unchecked")
protected <C> IConverter<C> newConverter() {
    return (IConverter<C>) new IConverter<DateRange>() {

        private static final long serialVersionUID = 1L;

        @Override/* w  w  w . j  a va  2s .c o m*/
        public DateRange convertToObject(String value, Locale locale) {
            DateFormat dateFormat = RangeDatePickerTextField.this.newDateFormat(locale);
            String[] dates = value.split(RangeDatePickerTextField.this.getSeparator());

            try {
                return new DateRange(dateFormat.parse(dates[0]), dateFormat.parse(dates[1]));
            } catch (ParseException e) {
                throw new ConversionException(e.getMessage());
            } catch (IndexOutOfBoundsException e) {
                throw new ConversionException(e.getMessage());
            }
        }

        @Override
        public String convertToString(DateRange value, Locale locale) {
            DateFormat dateFormat = RangeDatePickerTextField.this.newDateFormat(locale);
            Date start = value.getStart();
            Date end = value.getEnd();

            return String.format("%s%s%s", start != null ? dateFormat.format(start) : getNullString(),
                    RangeDatePickerTextField.this.getSeparator(),
                    end != null ? dateFormat.format(end) : getNullString());
        }
    };
}

From source file:com.googlecode.wicket.kendo.ui.datatable.DataProviderBehavior.java

License:Apache License

/**
 * Gets a new JSON object from the bean/*from  w  w  w .j  a  v  a  2 s .c  o m*/
 *
 * @param bean T object
 * @return a new JSON object
 */
protected String newJsonRow(T bean) {
    JSONObject object = new JSONObject();

    try {
        for (IColumn column : this.columns.getObject()) {
            if (column instanceof PropertyColumn) {
                PropertyColumn pc = (PropertyColumn) column;
                object.put(pc.getField(), pc.getValue(bean));
            }
        }
    } catch (JSONException e) {
        throw new ConversionException(e);
    }

    return object.toString();
}

From source file:com.googlecode.wicket.kendo.ui.datatable.DataSourceBehavior.java

License:Apache License

/**
 * Gets a new JSON object from the bean/* w ww .j  a va 2 s. c o  m*/
 *
 * @param bean T object
 * @return a new JSON object
 */
protected String newJsonRow(T bean) {
    JSONObject object = new JSONObject();

    try {
        for (IColumn column : this.columns) {
            if (column instanceof PropertyColumn) {
                PropertyColumn pc = (PropertyColumn) column;
                object.put(pc.getField(), pc.getValue(bean));
            }
        }
    } catch (JSONException e) {
        throw new ConversionException(e);
    }

    return object.toString();
}

From source file:com.myamamoto.wicket.misc.convert.converter.BooleanConverter.java

License:Apache License

@Override
public Boolean convertToObject(String value, Locale locale) {
    if (this.trueString.equals(value)) {
        return Boolean.TRUE;
    } else if (this.falseString.equals(value)) {
        return Boolean.FALSE;
    } else {//  w w  w  .j  av  a 2s. c o m
        throw new ConversionException("can't convert: " + value);
    }
}

From source file:com.visural.wicket.component.dropdown.DropDown.java

License:Apache License

@Override
public IConverter getConverter(Class<?> type) {
    if (requireListValue && source.getValues().size() > 0
            && type.equals(source.getValues().get(0).getClass())) {
        return new IConverter() {
            public Object convertToObject(String listnum, Locale locale) {
                T converted = null;/*from   w  w w  . j  av a2 s  . c om*/
                if (StringUtil.isNotBlankStr(listnum)) {
                    try {
                        converted = (T) source.getValues().get(Integer.parseInt(listnum));
                    } catch (Throwable t) {
                        throw new ConversionException("Could not convert '" + listnum + "' to list index.");
                    }
                }
                return converted;
            }

            public String convertToString(Object o, Locale locale) {
                int idx = source.getValues().indexOf(o);
                return (idx == -1 ? null : Integer.toString(idx));
            }
        };
    } else {
        return super.getConverter(type);
    }
}

From source file:com.visural.wicket.component.dropdown.DropDown.java

License:Apache License

@Override
protected T convertValue(String[] value) throws ConversionException {
    if (!requireListValue) {
        return super.convertValue(value);
    } else {/*  w w w.  j  ava  2s  .c  o m*/
        String listnum = (value != null && value.length > 0 && value[0] != null ? trim(value[0]) : null);
        T converted = null;
        if (StringUtil.isNotBlankStr(listnum)) {
            try {
                converted = (T) this.source.getValues().get(Integer.parseInt(listnum));
            } catch (Throwable t) {
                throw new ConversionException("Could not convert '" + listnum + "' to list index.");
            }
        }
        return converted;
    }
}

From source file:cz.zcu.kiv.eegdatabase.wui.components.table.TimestampConverter.java

License:Apache License

@Override
public Timestamp convertToObject(String value, Locale locale) {
    try {//w w w . j ava2 s .  c  o  m

        long time = new SimpleDateFormat(getParsePattern()).parse(value).getTime();
        return new Timestamp(time);

    } catch (ParseException e) {
        log.info(e.getMessage(), e);
        throw new ConversionException("Wrong Date Format: " + parsePattern);
    }
}

From source file:gr.abiss.calipso.wicket.yui.YuiCalendar.java

License:Open Source License

public YuiCalendar(String id, IModel model, boolean required) {

    super(id, null);

    add(new Behavior() {
        public void renderHead(Component component, IHeaderResponse response) {
            response.renderJavaScriptReference("resources/yui/yahoo/yahoo-min.js", "yui-yahoo");
            response.renderJavaScriptReference("resources/yui/event/event-min.js", "yui-event");
            response.renderJavaScriptReference("resources/yui/dom/dom-min.js", "yui-dom");
            response.renderJavaScriptReference("resources/yui/calendar/calendar-min.js", "yui-calendar");
            response.renderJavaScriptReference("resources/yui/calendar/calendar-utils.js",
                    "yui-calendar-utils");
            response.renderCSSReference("resources/yui/container/assets/calendar.css");
        }/*from   w  w  w.  j ava  2  s  .c  o m*/
    });

    dateField = new TextField("field", model, Date.class) {
        @Override
        public IConverter getConverter(Class clazz) {
            return new AbstractConverter() {
                //                    private DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
                private DateFormat df = new SimpleDateFormat("dd/MM/yyyy");

                public Object convertToObject(String s, Locale locale) {
                    if (s == null || s.trim().length() == 0) {
                        value = null;
                        dateValue = null;
                        return null;
                    }
                    try {
                        value = s;
                        dateValue = df.parse(s);
                        return dateValue;
                    } catch (Exception e) {
                        value = null;
                        throw new ConversionException(e);
                    }
                }

                protected Class getTargetType() {
                    return Date.class;
                }

                @Override
                public String convertToString(Object o, Locale locale) {
                    Date d = (Date) o;
                    return df.format(d);
                }
            };
        }

        @Override
        public IModel getLabel() {
            return YuiCalendar.this.getLabel();
        }
    };
    dateField.setOutputMarkupId(true);
    dateField.setRequired(required);
    dateField.add(new ErrorHighlighter());
    add(dateField);

    final WebMarkupContainer button = new WebMarkupContainer("button");
    button.setOutputMarkupId(true);
    button.add(new AttributeModifier("onclick", true, new AbstractReadOnlyModel() {
        public Object getObject() {
            String js = "showCalendar(" + getCalendarId() + ", '" + getInputId() + "');";
            logger.info("YuiCalendar button onclick js: " + js);

            return js;
        }
    }));
    add(button);

    container = new WebMarkupContainer("container");
    container.setOutputMarkupId(true);
    add(container);
}