开发者

Wicket resource - string not found?

开发者 https://www.devze.com 2023-01-07 09:02 出处:网络
I\'m playing with wicket\'s form input components. I tried to put an enum to a DropDownMenu: public enum Choice { ONE, TWO, THREE }

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,

Ondra


The 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) )
   )
0

精彩评论

暂无评论...
验证码 换一张
取 消