我需要在页面的.properties文件中为可重用面板定义Wicket验证消息。我将给出一个例子(下面的代码片段):
MyPage类包含带有片段MyFragment的MyPanel,其中有一个名为MyComponent (TextField of A BigDecimal)的组件。
我需要在MyPage上定义3个可重用的MyPage实例,并且需要为MyPage中的MyComponent定义一个验证键(因为它们在不同的上下文中使用)。
class MyPage extends WebPage {
public void onInitialize() {
super.onInitialize();
add(new MyPanel("fuelConsumption");
add(new MyPanel("populationGrowth");
add(new MyPanel("averageGrade");
}
}
class MyPanel extends Panel {
public void onInitialize() {
super.onInitialize();
Fragment fragment = new MyFragment("fragment");
add(fragment);
}
class MyFragment extends Fragment {
public void onInitialize() {
super.onInitialize();
add(new MyComponent("component");
}
}
class MyComponent extends TextField<BigDecimal> {
}
}因此,我需要为MyComponent字段的所有三种用法添加一个BigDecimal类型的验证消息到MyPage.properties中,如下所示:
fuelConsumption.fragment.component.IConverter.BigDecimal=Fuel consumption must be a decimal
populationGrowth.fragment.component.IConverter.BigDecimal=Please check the population growth format
averageGrade.fragment.component.IConverter.BigDecimal=This is not an average grade!我故意使用不同类型的验证消息,我不想使用具有可配置参数的单个验证消息
当我添加MyPanel.properties并放置如下一行时:
component.IConverter.BigDecimal=Component is not a valid BigDecimal.它工作得很好,但我真的想在可重用面板之外指定它(这样面板就可以以其他方式和含义使用)。
我该怎么做?
当我尝试添加上面的行时,它不起作用,也不以任何方式尝试,比如从属性字符串中省略“片段”或“组件”。什么都帮不上忙。
谢谢你的建议!
发布于 2014-07-16 19:04:33
你的解决方案在我看来不错。
为org.apache.wicket.resource.loader.ComponentStringResourceLoader启用调试日志记录,以查看搜索了哪些键。
https://stackoverflow.com/questions/24785469
复制相似问题