Show TOC

Defining and Accessing Runtime StringsLocate this document in the navigation structure

Use

Runtime strings are displayed within the user interface of your application. These strings should be externalized to a set of resource bundles.

Procedure

Defining Strings

  1. Add a reference to the resource bundle for runtime strings, by adding a property in the <component-config> section for your component in the portalapp.xml .

    Set the property name to ResourceBundleName , and the value to the name of the resource bundle file. For more information, see Components .

  2. Add a resource bundle for the administration strings in the /PORTAL-INF/private/classes folder of your PAR file.

Accessing Strings

Accessing runtime strings in a portal component is similar to accessing strings from any Java application. Retrieve the resource bundle object ( ResourceBundle ) and then call getString() for the string, as shown below:

               import com.sapportals.portal.prt.component.*;
import com.sapportals.portal.prt.resource.*;
import java.util.ResourceBundle;
 
public class HelloWorldComponent extends AbstractPortalComponent {
 
   public void doContent(
      IPortalComponentRequest request,
      IPortalComponentResponse response) {
 
      if (request != null && response != null) {
          ResourceBundle resource = request.getResourceBundle();
          response.write(resource.getString("GREETING"));
      }
   }

            

In the example above, the request object retrieves a resource bundle whose name is indicated by the ResourceBundleName property in the <component-config> element for the current component in the deployment descriptor.

You can retrieve a resource bundle for another component by creating an IPortalComponentContext object for the other component, and then getting its resource bundle, as shown in the following example:

               IPortalComponentContext myPortalComponentContext =
    request.getComponentContext("myApp.myComp");
ResourceBundle resource = 
    myPortalComponentContext.getResourceBundle(request.getLocale());