Search code examples
javawicketresourcebundlegetstring

What requirements are necessary in order to properly call getString(String key) function in a Wicket WebPage?


I have one Wicket (6.19) bundle including:

  • HomePage.java
  • HomePage.html
  • HomePage.properties.xml

In the .java file I have this code :

public class HomePage extends BasePage {
    public HomePage() {
        add(new Label("message", getString("greetingMessage")));
    }
}

and in the .properties file I have this:

<?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>

The problem is that calling the getString method returns an exception :

java.util.MissingResourceException: Unable to find property: 'greetingMessage' for component: [class=com.mycompany.HomePage]. Locale: null, style: null

What am i doing wrong ?


Solution

  • Check your console:

    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
    

    So replace the doctype declaration:

    <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">