TextArea with list of strings.
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 TextFieldDate, 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 CollectionTextAreaType extends TextAreaCollectionType { 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 IModelCollectionType 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 ListType lines = new ArrayListType(); 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: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: TextArea with list of strings.
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 s...@sambarrow.com 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 TextFieldDate, 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 CollectionTextAreaType extends TextAreaCollectionType { 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 IModelCollectionType 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 ListType lines = new ArrayListType(); 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: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: TextArea with list of strings.
so walk the code and see where your ConversionException is being wrapped by a RuntimeException -igor On Fri, Dec 4, 2009 at 1:08 PM, Sam Barrow s...@sambarrow.com wrote: 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 s...@sambarrow.com 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 TextFieldDate, 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 CollectionTextAreaType extends TextAreaCollectionType { 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 IModelCollectionType 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 ListType lines = new ArrayListType(); 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: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: TextArea with list of strings.
No I'm getting a ConversionException, I must have made a typo. But for the single text field I get a message in the feedback panel. On Fri, 2009-12-04 at 13:25 -0800, Igor Vaynberg wrote: so walk the code and see where your ConversionException is being wrapped by a RuntimeException -igor On Fri, Dec 4, 2009 at 1:08 PM, Sam Barrow s...@sambarrow.com wrote: 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 s...@sambarrow.com 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 TextFieldDate, 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 CollectionTextAreaType extends TextAreaCollectionType { 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 IModelCollectionType 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 ListType lines = new ArrayListType(); 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: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional
Re: TextArea with list of strings.
ok, override convertValue() instead of convertInput() and then the exception will be handled for you -igor On Fri, Dec 4, 2009 at 1:39 PM, Sam Barrow s...@sambarrow.com wrote: No I'm getting a ConversionException, I must have made a typo. But for the single text field I get a message in the feedback panel. On Fri, 2009-12-04 at 13:25 -0800, Igor Vaynberg wrote: so walk the code and see where your ConversionException is being wrapped by a RuntimeException -igor On Fri, Dec 4, 2009 at 1:08 PM, Sam Barrow s...@sambarrow.com wrote: 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 s...@sambarrow.com 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 TextFieldDate, 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 CollectionTextAreaType extends TextAreaCollectionType { 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 IModelCollectionType 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 ListType lines = new ArrayListType(); 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: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional
Re: TextArea with list of strings.
I'll try that. What about the problem with the square brackets? I can't find a function to override that allows me to format the text inside the textarea On Fri, 2009-12-04 at 14:01 -0800, Igor Vaynberg wrote: ok, override convertValue() instead of convertInput() and then the exception will be handled for you -igor On Fri, Dec 4, 2009 at 1:39 PM, Sam Barrow s...@sambarrow.com wrote: No I'm getting a ConversionException, I must have made a typo. But for the single text field I get a message in the feedback panel. On Fri, 2009-12-04 at 13:25 -0800, Igor Vaynberg wrote: so walk the code and see where your ConversionException is being wrapped by a RuntimeException -igor On Fri, Dec 4, 2009 at 1:08 PM, Sam Barrow s...@sambarrow.com wrote: 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 s...@sambarrow.com 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 TextFieldDate, 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 CollectionTextAreaType extends TextAreaCollectionType { 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 IModelCollectionType 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 ListType lines = new ArrayListType(); 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: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: TextArea with list of strings.
overrwrite getmodelvalue() and convert it to string there -igor On Fri, Dec 4, 2009 at 2:10 PM, Sam Barrow s...@sambarrow.com wrote: I'll try that. What about the problem with the square brackets? I can't find a function to override that allows me to format the text inside the textarea On Fri, 2009-12-04 at 14:01 -0800, Igor Vaynberg wrote: ok, override convertValue() instead of convertInput() and then the exception will be handled for you -igor On Fri, Dec 4, 2009 at 1:39 PM, Sam Barrow s...@sambarrow.com wrote: No I'm getting a ConversionException, I must have made a typo. But for the single text field I get a message in the feedback panel. On Fri, 2009-12-04 at 13:25 -0800, Igor Vaynberg wrote: so walk the code and see where your ConversionException is being wrapped by a RuntimeException -igor On Fri, Dec 4, 2009 at 1:08 PM, Sam Barrow s...@sambarrow.com wrote: 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 s...@sambarrow.com 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 TextFieldDate, 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 CollectionTextAreaType extends TextAreaCollectionType { 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 IModelCollectionType 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 ListType lines = new ArrayListType(); 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: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org