Wicket拥有灵活的国际化系统,支持以多种方式对UI消息进行参数化.例如在StringResourceModel javadocs中有例如:
WeatherStation ws = new WeatherStation();
add(new Label("weatherMessage", new StringResourceModel(
"weather.${currentStatus}", this, new Model<String>(ws)));
Run Code Online (Sandbox Code Playgroud)
但我想要一些非常简单的东西,并且找不到一个很好的例子.
在.properties文件中考虑这种UI消息:
msg=Value is {0}
Run Code Online (Sandbox Code Playgroud)
具体来说,我不想为此目的创建一个模型对象(使用要替换的值的getter;如上例中的WeatherStation).如果我已经拥有局部变量中的值,那就太过分了,否则就不需要这样的对象了.
这是用正确的值替换{0}的一种愚蠢的"蛮力"方式:
String value = ... // contains the dynamic value to use
add(new Label("message", getString("msg").replaceAll("\\{0\\}", value)));
Run Code Online (Sandbox Code Playgroud)
是否有一个干净的,更多的Wicket-y方式来做到这一点(这不是比上面的长得多)?