Search code examples
javapropertiesresourceswicketresourcebundle

How can I access an central ResourceBundle in Wicket


The Internationalization of Wicket is realized with many little Properties-Files in the same folders like there html-Files.

My architekture ist one Properties-File in the webapp-Folder or an other unique Folder.

My favorite Example: src/java/main/net/kog/WicketApplikation.java:

getResourceSettings().getResourceFinders().add(
       new WebApplicationPath(getServletContext(), "resource"));
BundleStringResourceLoader bundle = new BundleStringResourceLoader("text.properties");
getResourceSettings().getStringResourceLoaders().add(bundle);
// Test
String str = bundle.loadStringResource(net.kog.resource.Text.class, "login.noscript", Locale.getDefault(), null, null);
System.out.println(str);

Markup:

<div wicket:id="login.noscript" id="js"/>

But whereever I locate the File text.properties the ResourceBundle not found, no String was returned. tried Locations:

  • src/main/webapp
  • src/main/webapp/resource
  • src/main/webapp/WEB-INF/resource
  • src/main/webapp/WEB-INF/classes/resource
  • src/main/resources
  • src/main/resources/resource
  • src/main/resources/net/kog/resource

Solution

  • Solution:

    1. First, the answer of martin-g has given the right direktion. The properties-File have to be the same name like the Application-class ("WicketApplication.properties").
    2. Second, very useful was to change the debuglevel in Wicket (src\main\resources\log4j2.xml) from LEVEL.INFO to LEVEL.DEBUG. There was a many Information about the URL (Path) which Wicket has tried to loaded.
    3. Third, I make the way to access my properties-File shorter, because I delete IsoPropertiesFilePropertiesLoader (ISO-8859 formated Properties-Files) and XmlFilePropertiesLoader in net.kog.WicketApplication.init(). Code:

      List<IPropertiesLoader> propertiesLoader = 
              ((PropertiesFactory)getResourceSettings().getPropertiesFactory()).getPropertiesLoaders();
      getResourceSettings().getPropertiesFactory().clearCache();
      propertiesLoader.clear();
      propertiesLoader.add(new UtfPropertiesFilePropertiesLoader("properties", "utf-8"));
      

    The full path of my UTF-8 properties-File is src/main/webapp/net/kog/WicketApplication.properties