Localizing a Portlet Title

6-6 Oracle Fusion Middleware Extending the Administration Console for Oracle WebLogic Server netuix:titlebar netuix:minimize netuix:maximize netuix:titlebar netuix:content netuix:strutsContent module=medrecMBean action=RetrieveCustomMBeansAction refreshAction=RetrieveCustomMBeansAction netuix:content netuix:portlet portal:root

6.1.4.1 Localizing a Portlet Title

By default, the portlet displays the literal value that you enter in the netuix:portlet elements title attribute. To enable this title to be localized: 1. Create a Java class that retrieves the value of the title attribute, scans a property file for a key that matches the title attribute value, and returns the value of the property key. For example, if you specify title=myPortlet.title, the Java class looks through your message bundle for myPortlet.title=MyCompanys Portlet and returns MyCompanys Portlet as the text to be displayed. See Section 6.1.4.1.1, Create a Backing Class for Localizing Portlet Titles. 2. In the .portlet file, include the following attributes in the netuix:portlet element: ■ title . Specify the key for a property that you have defined in your message bundle. ■ backingFile . Specify the fully-qualified name of a Java class that you created in the previous step. For example: netuix:portlet definitionLabel=myPortlet title=myPortlet.title backingFile=com.mycompany.extension.utils.MyPortletBacking

6.1.4.1.1 Create a Backing Class for Localizing Portlet Titles A backing class is a Java class

that interacts directly with the portal framework APIs. To create a backing class that retrieves localized portlet titles: 1. Extend com.bea.netuix.servlets.controls.content.backing.AbstractJspB acking . 2. Implement the AbstractJspBacking.preRenderHttpServletRequest request, HttpServletResponse response method. See AbstractJspBacking.preRender in the Java API Reference for Oracle WebLogic Portal. In your implementation of this method: a. Get the locale from the HttpServletRequest object. Use the following API: javax.servlet.http.HttpServletRequest.getSession.getAttribute org.apache.struts.action.LOCALE Adding Portlets and Navigation Controls 6-7 b. Get the message bundle. Use the following API: org.apache.struts.util.MessageResources.getMessageResources myBundle; where myBundle is the name of your message bundle. See Section 4, Creating a Message Bundle. c. Get the value of the portlets title property. Use the following APIs: PortletBackingContext bctx = PortletBackingContext.getPortletBackingContext HttpServletRequest req; MessageResources.getMessagelocale, bctx.getTitle; where locale is the locale that you retrieved from the HttpServletRequest object. d. Reset the value of the portlets title property to the localized value that you retrieved in the previous step. Use the following API: PortletBackingContext.getTitleString title where title is the value that you retrieved from the message bundle. Example 6–5 Example: Backing Class for Localizing a Portlet Title package com.bea.medrec.extension.utils; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.util.MessageResources; import com.bea.netuix.servlets.controls.content.backing.AbstractJspBacking; import com.bea.netuix.servlets.controls.portlet.backing.PortletBackingContext; public class DesktopViewBacking extends AbstractJspBacking { public boolean preRenderHttpServletRequest req, HttpServletResponse res { Get the PortletBackingContext for current portlet. The PortletBackingContext contains properties and methods for the current portlet. PortletBackingContext bctx = PortletBackingContext.getPortletBackingContextreq; if bctx = null { If title does not contain a period, assume its preLocalized or follow the format for a key if bctx.getTitle.indexOf.=-1{ Get the locale from the HTTPServletRequest Locale locale = Locale req.getSession.getAttribute org.apache.struts.action.LOCALE; Find the message bundle named medrecMBean MessageResources messages = MessageResources.getMessageResourcesmedrecMBean; Get the value of the portlets title property String msg = messages.getMessagelocale, bctx.getTitle; Reset the value of the title property with the localized value. bctx.setTitlemsg; 6-8 Oracle Fusion Middleware Extending the Administration Console for Oracle WebLogic Server } } return true; } }

6.2 Define UI Controls Optional