Extending the resource bundle and properties files

In this lesson, you add an extended properties file that contains the text for your new widget. The properties file is a resource bundle that contains translatable text, which displays in Management Center for your widget.

Add the text for your widget within a properties file to ensure that the Management Center properties and list views for your widget display text. Include all of the text for your widget within a properties file with resource keys, instead of hardcoding the text in JSP and JSPF files.

Procedure

  1. Copy the generated resource bundle and properties files into your default workspace directory structure.
    1. In a File Manager, go to the com directory within your new widget project directory.
      For example, if your new widget project is at the top-level in your workspace the filepath to the com directory, can be workspace_dir\NewWidgetProject\LOBTools\src\com.
    2. Copy the mycompany directory.
    3. Go to the workspace_dir\LOBTools\Java Resources\src directory.
    4. Paste your copied mycompany directory within the LOBTools\Java Resources\src directory.
    5. Open WebSphere Commerce Developer. Switch to the Enterprise Explorer view.
    6. Right-click the LOBTools directory within your default workspace directory structure. Click Refresh.
    7. In the LOBTools\Java Resources\src directory, ensure that the com.mycompany.commerce.pagelayout.client.lobtools.properties package exists. Within the package, ensure that the PageLayoutLOB.properties and PageLayoutLOB_en_US.properties files exist.
  2. Define the translatable text for your new widget.
    1. In the Enterprise Explorer view, go to the LOBTools\Java Resources\src directory. Expand the com.mycompany.commerce.pagelayout.client.lobtools.properties package. Open the PageLayoutLOB.properties and PageLayoutLOB_en_US.properties files for editing.
      The following generated code is included within the files:
      # Widget properties view
      widgetNamePrompt=Widget Name
      widgetPropertiesPrompt=Widget Properties
      widgetContentPrompt=Widget Content
      ShoppingCartDetailPageWidgetContent=This widget displays the orders you add into your shopping cart
    2. Define any additional translatable text for your widget by adding code into both files.
    3. Save any changes and close the files.
  3. Register your properties file within a custom resource bundle extension file.
    1. In your new project directory, go to the xml directory.
      For example, the filepath to the xml directory, can be NewWidgetProject\LOBTools\WebContent\WEB-INF\src\xml.
    2. Copy the mycompany directory.
    3. Go to the LOBTools\WebContent\WEB-INF\src\xml directory.
    4. Paste your copied mycompany directory within the LOBTools\WebContent\WEB-INF\src\xml directory.
    5. In the LOBTools\WebContent\WEB-INF\src\xml\mycompany\pagelayout directory, open the extPageLayoutResourceBundle.xml file to review the source code.
      Update the generated code to match the following code:
      
      <?xml version="1.0" encoding="UTF-8"?>
      
      <Definitions>
        <ResourceBundle baseName="com.mycompany.commerce.pagelayout.client.lobtools.properties.PageLayoutLOB" 
        definitionName="cmc/pagelayout/ExtPageLayoutResources" singletonDefinition="true"/>
      </Definitions>
      The code defines that the resource bundle is an extended resource bundle. The code sets the name for the text properties to register the text within the resource bundle. Management Center uses the resource bundles to identify the text that is translatable. The translatable text must be retrieved from the properties file for the language that a user is working within.
    6. Close the file.