Thanks Andrea !! Yes, I could store the value on the Panel which holds the form - but then I couldn't use it as stateless. Or in WebSession, but it's not adequate... Also. I could use a String and make the conversion hardcoded..
But I searched the converters, and I tried this (maybe a little complicated) and it worked allright ! public class MyWebApplication extends WebApplication { @Override protected IConverterLocator newConverterLocator() { ConverterLocator locator = (ConverterLocator) super.newConverterLocator(); locator.set(MyEnum.class, new MyEnumConverter()); return locator; } } public class MyEnumConverter implements IConverter<MyEnum> { @Override public MyEnumconvertToObject(String s, Locale locale) { try { return MyEnum.valueOf(s); } catch (Exception e) { log_error("MyEnum.valueOf(s) " + s, e); return null; } } @Override public String convertToString(MyEnum myEnum, Locale locale) { return myEnum.name(); } } > > > Oscar Besga Arcauz < < < -----Andrea Del Bene <an.delb...@gmail.com> escribió: ----- Para: users@wicket.apache.org De: Andrea Del Bene <an.delb...@gmail.com> Fecha: 01/03/2013 17:55 Asunto: Re: Error with Hidden Field and its enum value The error occurs because Wicket convert your enum to a string when the form is rendered, then it tries to do the opposite converting the string to your enum. And here we have the problem. Wicket doesn't fin a valid converter (see JAvaDoc of FormComponent.convertInput) to obtain your enum from its string value. But the real question is: do you really need to have such hidden field in your form? Why can't you simply get rid of it? > Hi wickers !! > > I've a problem with a form and a hidden field. > The form has a CompoundPropertyModel of a data class. This class has an enum > propertiy, which I want to store into a HiddenField and later retrieve (with > the whole data class and the rest of the data). > > When the panel is rendered, the hidden field gets the correct value - the > enum name() (or toString()? ) value. > But when I retrieve the form, with the AjaxSubmitLink, I get this error in > the feedback messagges > > DEBUG - FeedbackMessages - Adding feedback message > '[FeedbackMessage message = "The value of 'myType' is not a valid MyType.", > reporter = myType, level = ERROR]' > > > Any ideas ? > > Thanks a lot > > > > > > > Oscar Besga Arcauz < < < > > > EXAMPLE CODE > > > //Enumerated > public enum MyType { myTypeOne, myTypeTwo, andSoOn } > > // Data class > public class MyData implements Serializable { > MyType myType; > } > > //Panel with form > public class MyPanel extends Panel { > > public MyPanel(String id) { > super(id); > MyData data = new MyData(); > data.myType = MyType.myTypeTwo; > Form<MyData> form = new Form<MyData>("form",new > CompoundPropertyModel<MyData>(data)); > form.add(new HiddenField("myType"); //data > AjaxSubmitLink submit = new AjaxSubmitLink("Submit"){ > > @Override > protected void onError(AjaxRequestTarget target, Form<?> form) { > //ALWAYS GETS ME AN ERROR !!! > super.onError(target,form); > } > > @Override > protected void onSubmit(AjaxRequestTarget target, Form<?> form) { > super.onSubmit(target, form); > } > }; > } > > } > > > > > > Oscar Besga Arcauz < < < > --------------------------------------------------------------------- > 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