That's what I'm doing, but i still get the conversion exception
public final class EmailAddressConverter implements IConverter {
private static final long serialVersionUID = -4264887925119691218L;
@Override
public Object convertToObject(final String value, final Locale locale)
{
if (StringUtils.isNotBlank(value)) {
if (Valid.emailAddress(value)) {
return new EmailAddress(value);
}
else {
throw new ConversionException("Invalid email
address.");
}
}
else {
return null;
}
}
@Override
public String convertToString(final Object value, final Locale locale)
{
return value.toString();
}
}
On Fri, 2009-12-04 at 12:16 -0800, Igor Vaynberg wrote:
> you should do convertToObject() call in a try block, catch any
> exception and throw a conversionexception
>
> -igor
>
> On Fri, Dec 4, 2009 at 11:32 AM, Sam Barrow <[email protected]> wrote:
> >
> > I am trying to make a TextArea that allows you to input a list of
> > strings (separated by a newline) and turns that list into a Collection.
> > I had it working but it was kind of hacked together, I'm trying to do it
> > the clean way now.
> > I have it working except for two things:
> >
> > If I give it an empty collection for the model object then it display
> > square brackets [] inside the text area.
> > I don't have the conversion 100% working. Like when you have a
> > TextField<Date>, I'm trying to make it do the same thing to each line.
> > It works, but when it is an invalid value, instead of a nice error
> > message "X is not a valid Y" I get a runtime exception from whatever
> > IConverter I am using.
> >
> > Source:
> >
> > public final class CollectionTextArea<Type> extends
> > TextArea<Collection<Type>> {
> >
> > private static final long serialVersionUID = 7147538499297387635L;
> >
> > private Class<?> elementType;
> >
> > public CollectionTextArea(final String id, final Class<?>
> > elementType)
> > {
> > super(id);
> > setElementType(elementType);
> > }
> > public CollectionTextArea(final String id, final Class<?>
> > elementType,
> > final IModel<Collection<Type>> model) {
> > super(id, model);
> > setElementType(elementType);
> > }
> >
> > public Class<?> getElementType() {
> > return elementType;
> > }
> > public void setElementType(Class<?> elementType) {
> > this.elementType = elementType;
> > }
> >
> > @Override
> > protected void onBeforeRender() {
> > super.onBeforeRender();
> > }
> > @Override
> > @SuppressWarnings("unchecked")
> > protected void convertInput() {
> > final String text = getRawInput();
> > final List<Type> lines = new ArrayList<Type>();
> > if (text != null) {
> > for (final String line: text.split("\\r\\n")) {
> > if (StringUtils.isNotBlank(line)) {
> > Type value = (Type)
> > getApplication().getConverterLocator().getConverter(getElementType()).convertToObject(line,
> > getLocale());
> > lines.add(value);
> > }
> > }
> > }
> > setConvertedInput(lines);
> > }
> >
> > }
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [email protected]
> > For additional commands, e-mail: [email protected]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]