2

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:100)
 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,
Ondra

4

1 回答 1

3

EnumChoiceRenderer 不知道在哪里查找属性文件。

您可以通过将页面添加为渲染器的构造函数参数来告诉它属性文件与页面相关联:

  cz.oz.wicket.pages.form.FormPage.java
  --------------
  .add( new DropDownChoice("choice",
     Arrays.asList( Choice.values() ), new EnumChoiceRenderer(this) )
   )
于 2010-07-11T22:51:02.213 回答