As we have already discussed,one of the main concerns of the struts framework is to separate the string resources from the view. For this purpose,we have already defined a message-resources property n struts-config.xml. Most of the struts components will expect a property key where a string literal will be needed. To be consistent with the struts framework,we will try to separate the string resources from our normal java classes where we are not using struts components. To do this,we can use java.util.ResourceBundle class to pick the values from properties file against the specified keys. To ease the manipulation of string resources where we are not using the struts components,we’ll write a separate class.
package com.visualbuilder.struts;
import java.util.ResourceBundle;
public class ResourceManager { private static ResourceBundle bundle=ResourceBundle.getBundle("com.visualbuilder.struts.ApplicationResources");
public static String getString(String key){ return bundle.getString(key) }
} |