Hi all,

If I have an enum 'SexTypes' in the class Person like this:

====
  public static enum SexTypes {
    SEX_UNKNOWN(0),
    SEX_MALE(1),
    SEX_FEMALE(2),
    SEX_NOT_APPLICABLE(9);
/* Values for sex are taken from ISO 5218:1977 Representation of Human Sexes  */
    private final int intValue;

    SexTypes(int intValue) {
      this.intValue = intValue;
    }

    public int getIntValue() {
      return this.intValue;
    }

    public String getName() {
      return this.name();
    }
  }
====

...And I want to display them, localized, in a Form like this:

====
 ChoiceRenderer renderer = new ChoiceRenderer("name", "intValue")
      {
        @Override
        public String getDisplayValue(Object object) {
          return getString((String)super.getDisplayValue(object));
        }
      };
      form.add(new RadioChoice("sex", Arrays.asList(Person.SexTypes.values()), 
renderer));
    }
====

...then, when the form is submitted, I get an IllegalArgumentException:

Caused by: java.lang.IllegalArgumentException: Cannot format given Object as a 
Number
        at java.text.DecimalFormat.format(DecimalFormat.java:504)
        at java.text.Format.format(Format.java:157)
        at 
org.apache.wicket.util.convert.converters.AbstractNumberConverter.convertToString(AbstractNumberConverter.java:109)
        at 
org.apache.wicket.util.lang.PropertyResolverConverter.convert(PropertyResolverConverter.java:84)
        at 
org.apache.wicket.util.lang.PropertyResolver$MethodGetAndSet.setValue(PropertyResolver.java:1094)
        at 
org.apache.wicket.util.lang.PropertyResolver$ObjectAndGetSetter.setValue(PropertyResolver.java:589)
        at 
org.apache.wicket.util.lang.PropertyResolver.setValue(PropertyResolver.java:137)
        at 
org.apache.wicket.model.AbstractPropertyModel.setObject(AbstractPropertyModel.java:164)
        at org.apache.wicket.Component.setModelObject(Component.java:2934)
        at 
org.apache.wicket.markup.html.form.FormComponent.updateModel(FormComponent.java:1069)
        at org.apache.wicket.markup.html.form.Form$21.validate(Form.java:1866)
        at 
org.apache.wicket.markup.html.form.Form$ValidationVisitor.formComponent(Form.java:166)
        at 
org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPostOrderHelper(FormComponent.java:421)
        at 
org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPostOrderHelper(FormComponent.java:408)
        at 
org.apache.wicket.markup.html.form.FormComponent.visitFormComponentsPostOrder(FormComponent.java:385)
        at 
org.apache.wicket.markup.html.form.Form.visitFormComponentsPostOrder(Form.java:1089)
        at 
org.apache.wicket.markup.html.form.Form.internalUpdateFormComponentModels(Form.java:1858)
        at 
org.apache.wicket.markup.html.form.Form.updateFormComponentModels(Form.java:1825)
        at org.apache.wicket.markup.html.form.Form.process(Form.java:871)
        at 
org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:808)
        ... 30 moremberFormatException:
====

I believe this is caused because the DecimalFormat.format() method is
being passed a SexType instead of a Number object. My question is, how
can I solve this elegantly so that the radiochoice value will be
resolved to a number?

regards,

-- 
Reinout van Schouwen


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to