Reviewing the Generated Code The wizard creates the following code for you by

7-12 Oracle Fusion Middleware Developers Guide for Oracle Portal personalization for this instance of the portlet. Even though the code in the JSP is identical, the PDK Framework and Oracle Portal automatically handle the personalization differently depending on the Show mode Edit or Edit Defaults.

7.2.2.3 Implementing Personalization for Show Pages

To have access to the personalization data in the portlets Shared Screen mode, you need to add a few lines of code to the Show page. By adding these lines you perform the following: ■ Adding import statements. ■ Declaring the NameValuePersonalizationObject. ■ Retrieving the personalization data. To implement personalization of the Show page, perform the following steps:

1. Edit your Show page and import NameValuePersonalizationObject and

PortletRendererUtil. You can copy these from the Edit page if necessary. page contentType=texthtml; charset=windows-1252 import=oracle.portal.provider.v2.render.PortletRenderRequest import=oracle.portal.provider.v2.http.HttpCommonConstants import=oracle.portal.provider.v2.personalize. NameValuePersonalizationObject import=oracle.portal.provider.v2.render.PortletRendererUtil 2. Declare the NameValuePersonalizationObject and retrieve the edit data from the portlet render request. You can copy this from the portlets Edit page. PortletRenderRequest pReq = PortletRenderRequest request.getAttributeHttpCommonConstants.PORTLET_RENDER_REQUEST; NameValuePersonalizationObject data = NameValuePersonalizationObject PortletRendererUtil.getEditDatapReq;

3. Get the string information from the personalization framework:

String greeting = data.getStringmyportlet_greeting; 4. Add some text to the Show page that displays the greeting in the Shared Screen mode of the portlet. PHello = pReq.getUser.getName .P PThis is the bishowi,b render modeP PGreeting: = greeting P You have now completed updating the Show page of the portlet.

7.2.2.4 Preference Information Within the XML Provider Definition

The Portlet Wizard generates all of the necessary tags for accessing the PreferenceStore in the XML provider definition file provider.xml. By default, at the provider level, the wizard uses the FilePreferenceStore class to store preferences: provider class=oracle.portal.provider.v2.DefaultProviderDefinition sessionfalsesession passAllUrlParamsfalsepassAllUrlParams Enhancing Java Portlets 7-13 preferenceStore class=oracle.portal.provider.v2.preference.FilePreferenceStore nameprefStore1name useHashingtrueuseHashing preferenceStore At the portlet level, tags are added to use PrefStorePersonalizationManager as the personalizationManager class and NameValuePersonalizationObject as the data class: personalizationManager class=oracle.portal.provider.v2.personalize. PrefStorePersonalizationManager dataClassoracle.portal.provider.v2.NewValuePersonalizationObjectdataClass personalizationManager You need not make any changes or updates to the XML Provider Definition if you choose to continue to use the FilePreferenceStore class. However, if you have a global environment for Oracle Portal for example, you are running in a load balanced, multi-node cluster of Oracle Containers for Java EE instances or would prefer to store preferences in the database, you can change the class from FilePreferenceStore to DBPreferenceStore. For more information on using DBPreferenceStore, refer to the Oracle Fusion Middleware Administrators Guide for Oracle Portal. For more information on the syntax of provider.xml, refer to the provider Javadoc on OTN: http:www.oracle.comtechnologyproductsiasportalhtmljavadocxml_tag_ reference_v2.html

7.2.2.5 Viewing the Portlet

To view the personalization changes you made in the preceding sections, you need to deploy the portlet to your application server or Oracle Containers for Java EE and refresh the page containing your portlet. For more information on deploying your portlet, refer to Section 6.5.4, Deploying Your Oracle PDK-Java Portlet to an Application Server . You should now see that the portlet contains a null greeting. Click Personalize in the portlet title bar and update the greeting. When you return to the page, you should see your changes. You can also test Edit Defaults by clicking Edit on the page and then clicking the Edit Defaults icon. Since you have already modified the portlet, the changes will not appear to you in Shared Screen mode unless you view the page as a public user or a different user.

7.2.3 Passing Parameters and Submitting Events

Oracle Portal and the PDK provide page parameters, public and private portlet parameters, and events to enable portlet developers to easily write reusable, complex portlets. The Portlet Wizard in Oracle JDeveloper creates portlets that are already set up to use parameters and events. This feature enables you to focus solely on adding business logic to your portlets and does not require any changes to provider.xml. For an overview of parameters and events, refer to the following: ■ Section 2.12, Public Portlet Parameters Support ■ Section 2.13, Private Portlet Parameter Support ■ Section 2.14, Event Support