简体   繁体   中英

In wicket is there a way to read localized properties directly?

Among others I have these two properties with differing values in all my localized .properties files:

...
StateShow=true
StateLabel=State
...

When the user picks a country protected void onUpdate(AjaxRequestTarget target) is called and the following lines among others in that method work:

...
getSession().setLocale(locale);
...
stateLabel.setDefaultModel(new StringResourceModel("StateLabel",target.getPage(),null));
...

That is to say that in US it says State, in Canada it says Province, in Japan it says Prefecture, etc. But the following line does not work:

...
showState       = Boolean.getBoolean(new StringResourceModel("StateShow",       target.getPage(),null).getString());
...

That is to say when the correct .properties file says StateShow=true showState is always false.

Is there anyway to accurately access localized properties that aren't being used as Models?

Your problem is probably not be related to Wicket but to your usage of Boolean.getBoolean(String) which tries to find a system property with the given name (check the javadoc).

So I would assume that your StringResourceModel correctly returns the value "true". Then Boolean.getBoolean(String) tries to find a the system property named "true" which probably doesn't exist and thus returns false.

You probably want to use Boolean.parseBoolean(String) instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM