为了在 Wicket 网页中正确调用 getString(String key) 函数,需要满足哪些要求?
What requirements are necessary in order to properly call getString(String key) function in a Wicket WebPage?
我有一个 Wicket (6.19) 捆绑包,包括:
- HomePage.java
- HomePage.html
- HomePage.properties.xml
在 .java
文件中我有这个代码:
public class HomePage extends BasePage {
public HomePage() {
add(new Label("message", getString("greetingMessage")));
}
}
在 .properties
文件中我有这个:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM
"http://www.oracle.com/webfolder/technetwork/jsc/dtd/properties.dtd">
<properties>
<entry key="greetingMessage">Hello</entry>
</properties>
问题是调用getString
方法returns异常:
java.util.MissingResourceException: Unable to find property:
'greetingMessage' for component: [class=com.mycompany.HomePage].
Locale: null, style: null
我做错了什么?
检查您的控制台:
WARN - PropertiesFactory - Unable to find resource file:/.../HomePage.properties.xml
java.util.InvalidPropertiesFormatException: org.xml.sax.SAXException: Invalid system identifier: http://www.oracle.com/webfolder/technetwork/jsc/dtd/properties.dtd
所以替换文档类型声明:
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
更好地使用add(new Label("message", new ResourceModel("greetingMessage")));
。
还要确保构建工具将 .properties.xml 文件复制到 HomePage.class,以便稍后在运行时可用。
尝试
new Label("message", new StringResourceModel("greetingMessage", this, null).getString());
我有一个 Wicket (6.19) 捆绑包,包括:
- HomePage.java
- HomePage.html
- HomePage.properties.xml
在 .java
文件中我有这个代码:
public class HomePage extends BasePage {
public HomePage() {
add(new Label("message", getString("greetingMessage")));
}
}
在 .properties
文件中我有这个:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM
"http://www.oracle.com/webfolder/technetwork/jsc/dtd/properties.dtd">
<properties>
<entry key="greetingMessage">Hello</entry>
</properties>
问题是调用getString
方法returns异常:
java.util.MissingResourceException: Unable to find property: 'greetingMessage' for component: [class=com.mycompany.HomePage]. Locale: null, style: null
我做错了什么?
检查您的控制台:
WARN - PropertiesFactory - Unable to find resource file:/.../HomePage.properties.xml
java.util.InvalidPropertiesFormatException: org.xml.sax.SAXException: Invalid system identifier: http://www.oracle.com/webfolder/technetwork/jsc/dtd/properties.dtd
所以替换文档类型声明:
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
更好地使用add(new Label("message", new ResourceModel("greetingMessage")));
。
还要确保构建工具将 .properties.xml 文件复制到 HomePage.class,以便稍后在运行时可用。
尝试
new Label("message", new StringResourceModel("greetingMessage", this, null).getString());