You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Pratibha <pr...@gmail.com> on 2013/03/01 14:19:46 UTC

org.apache.wicket.util.convert.ConversionException: Cannot parse 'abcdef' using format java.text.DecimalFormat@674dc

Hi team,

My converter is working perfectly if i enter double value but when i enter
any String value it throws me error, i am unable to catch this error in
feedbackpanel.

Here's my converter code

@Override
	public Object convertToObject(String value, java.util.Locale locale) {

		try{

			if (Strings.isEmpty(value))
			{
				return null;
			}
			else {

				if (Double.class.isAssignableFrom(value.getClass())) { 
					return value;
				}
				if (value.equals(String.class)) { 
					return convertToString((T)value, locale);
				}
			}
		}
		catch(Exception e){
			error(value,"format");
		}
		return value;

	}

	private void error(String value, String errorKey)
	{
		ConversionException e = new ConversionException("'" + value + "' is not a
valid Double");
		e.setSourceValue(value);
		e.setVariable("format", value);
		e.setResourceKey(getClass().getSimpleName() + "." + errorKey);
		throw e;
	}


	and my java code

	final TextField<Double> field = new TextField<Double>("field", new
PropertyModel<Double>(field, "fieldNumber")){
			@Override
			public IConverter getConverter(Class<?> clazz)
			{
				return new LocaleConverter<Double>();
				
			}
		};
		field.setType(Double.class);



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/org-apache-wicket-util-convert-ConversionException-Cannot-parse-abcdef-using-format-java-text-Decimac-tp4656895.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: org.apache.wicket.util.convert.ConversionException: Cannot parse 'abcdef' using format java.text.DecimalFormat@674dc

Posted by Pratibha <pr...@gmail.com>.
Thanks for the reply, i added Validator,  basically first validate the input
and then convert it.

---Pratibha



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/org-apache-wicket-util-convert-ConversionException-Cannot-parse-abcdef-using-format-java-text-Decimac-tp4656895p4656920.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: org.apache.wicket.util.convert.ConversionException: Cannot parse 'abcdef' using format java.text.DecimalFormat@674dc

Posted by "Richard W. Adams" <RW...@UP.COM>.
Clearly you're not detecting the non-numeric format before trying to parse 
it. Tracing the execution path with the debugger ought to show where you 
can capture that??




From:   Pratibha <pr...@gmail.com>
To:     users@wicket.apache.org
Date:   03/01/2013 07:20 AM
Subject:        org.apache.wicket.util.convert.ConversionException: Cannot 
parse 'abcdef' using format java.text.DecimalFormat@674dc



Hi team,

My converter is working perfectly if i enter double value but when i enter
any String value it throws me error, i am unable to catch this error in
feedbackpanel.

Here's my converter code

@Override
                 public Object convertToObject(String value, 
java.util.Locale locale) {

                                 try{

                                                 if 
(Strings.isEmpty(value))
                                                 {
                                                                 return 
null;
                                                 }
                                                 else {

                                                                 if 
(Double.class.isAssignableFrom(value.getClass())) { 
  return value;
                                                                 }
                                                                 if 
(value.equals(String.class)) { 
  return convertToString((T)value, locale);
                                                                 }
                                                 }
                                 }
                                 catch(Exception e){
                                                 error(value,"format");
                                 }
                                 return value;

                 }

                 private void error(String value, String errorKey)
                 {
                                 ConversionException e = new 
ConversionException("'" + value + "' is not a
valid Double");
                                 e.setSourceValue(value);
                                 e.setVariable("format", value);
 e.setResourceKey(getClass().getSimpleName() + "." + errorKey);
                                 throw e;
                 }


                 and my java code

                 final TextField<Double> field = new 
TextField<Double>("field", new
PropertyModel<Double>(field, "fieldNumber")){
                                                 @Override
                                                 public IConverter 
getConverter(Class<?> clazz)
                                                 {
                                                                 return 
new LocaleConverter<Double>();
 
                                                 }
                                 };
                                 field.setType(Double.class);



--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/org-apache-wicket-util-convert-ConversionException-Cannot-parse-abcdef-using-format-java-text-Decimac-tp4656895.html

Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org




**

This email and any attachments may contain information that is confidential and/or privileged for the sole use of the intended recipient.  Any use, review, disclosure, copying, distribution or reliance by others, and any forwarding of this email or its contents, without the express permission of the sender is strictly prohibited by law.  If you are not the intended recipient, please contact the sender immediately, delete the e-mail and destroy all copies.
**