Creating and using resource bundles in the tools framework

You can create and use resource bundles within the tools framework. For example, you create a resource bundle when you create a language selection list. A list selection determines the language, encoding, and cultural formatting preference of the user.

Note: All WebSphere Commerce tools must be encoded in UTF-8. All tools pages (JSP files) include the common.jsp file to set the servlet response parameters, which includes:
response.setContentType("text/html;charset=UTF-8");

Procedure

  1. Create a properties file and save it in the following directory:
    • WC_eardir/properties/com/ibm/commerce/tools/utf/properties
    • WebSphere Commerce Developer workspace_dir\installedApps\ cell_name\ WC_instance_name.ear\properties\com\ibm\commerce\tools\utf\properties
  2. Open the resources.xml file from:
    • WC_installdir/xml/tools/ tools_component_name/
    • WebSphere Commerce Developer workspace_dir\wc\xml\tools\tools_component_name\

    and add the following line:

    
    <resourceBundle name="name"
    bundle="com.ibm.commerce.tools.properties.
    filename_with_no_extension" />
    

    Where name is the name you want to use to refer to the bundle throughout your code and filename_with_no_extension is the filename for your properties file without the.properties extension.

  3. To use a resource string (from a resource bundle) in your code:
    1. Retrieve your properties file using the following command:
      
      Hashtable myResource = (Hashtable)
      com.ibm.commerce.tools.util.ResourceDirectory.lookup(String
      resourceName,
      Locale locale)
      

      Where resourceName is namespace.resource_name.

    2. Use the following command to retrieve the required information from the hash table:

      
      String resource = (String)myResource.get("<resource key>");
      
    The following example shows retrieving a resource string to use in your JSP file:
    
    <%@include file="../common/common.jsp" %>
    <%
    CommandContext commandContext =
    (CommandContext)request.getAttribute(ECConstants.EC_COMMANDCONTEXT);
    Locale locale = commandContext.getLocale();
    Hashtable resourceBundle = (Hashtable)
    ResourceDirectory.lookup("common.mccNLS", locale);
    %>
    .....
    .....
    .....
    <table CELLPADDING="0" CELLSPACING="0" BORDER="0" HEIGHT="100%"
    WIDTH="100%">
    <tr>
    <td><table CELLPADDING="0" CELLSPACING="0" BORDER="0"
    WIDTH="100%"
    HEIGHT="1%">
    <tr>
    <td
    class="entry_space">&nbsp;&nbsp;&nbsp;</td>
    <td class="entry_text"><%=
    resourceBundle.get("paragraph1") %></td>
    </tr>
    <tr><td>&nbsp;</td></tr>
    <tr>
    <td
    class="entry_space">&nbsp;&nbsp;&nbsp;</td>
    <td class="entry_text"><%=
    resourceBundle.get("paragraph2") %></td>
    </tr>
    <tr><td>&nbsp;</td></tr>
    <tr>
    <td
    class="entry_space">&nbsp;&nbsp;&nbsp;</td>
    <td class="entry_text"><%=
    resourceBundle.get("paragraph3") %></td>
    </tr>
    </table>