I'm playing with wicket's form input components. I tried to put an enum
to a DropDownMenu
:
public enum Choice { ONE, TWO, THREE }
cz.oz.wicket.pages.form.FormPage.java
--------------
.add( new DropDownChoice("choice",
Arrays.asList( Choice.values() ), new EnumChoiceRenderer() )
)
and added a properties file:
cz.oz.wicket.pages.form.FormPage.properties
--------------
Choice.ONE = Jedna
Choice.TWO = Dvě
Choice.THREE = Tři
According to what I've read, it should work.
But I get:java.util.MissingResourceException: Unable to find property: 'Choice.ONE'
at org.apache.wicket.Localizer.getString(Localizer.java:344)
at org.apache.wicket.Localizer.getString(Localizer.java:1开发者_如何学编程00)
at org.apache.wicket.markup.html.form.EnumChoiceRenderer.getDisplayValue(EnumChoiceRenderer.java:82)
at org.apache.wicket.markup.html.form.EnumChoiceRenderer.getDisplayValue(EnumChoiceRenderer.java:39)
at org.apache.wicket.markup.html.form.AbstractChoice.appendOptionHtml(AbstractChoice.java:384)
at org.apache.wicket.markup.html.form.AbstractChoice.onComponentTagBody(AbstractChoice.java:361)
at org.apache.wicket.Component.renderComponent(Component.java:2619)
...
What's wrong?
Thanks,
OndraThe EnumChoiceRenderer doesn't know where to look for the properties file.
You can tell it that the properties file is associated with the page by adding the page as a constructor parameter for the renderer:
cz.oz.wicket.pages.form.FormPage.java
--------------
.add( new DropDownChoice("choice",
Arrays.asList( Choice.values() ), new EnumChoiceRenderer(this) )
)
精彩评论