From the Summary of Deployments page, select the application and click Start From the Start Application Assistant, click Yes.

7 Enhancing Java Portlets 7-1 7 Enhancing Java Portlets This chapter explains how to enhance Java portlets you created with the Oracle JDeveloper Portal Add-In, and how to make a portlet out of your struts application. This chapter contains the following sections: ■ Section 7.1, Enhancing JPS Portlets ■ Section 7.2, Enhancing PDK-Java Portlets ■ Section 7.3, Building Struts Portlets with Oracle JDeveloper The source code for many of the examples referenced in this chapter is available as part of PDK-Java. You can download PDK-Java on Oracle Technology Network OTN: http:www.oracle.comtechnologyproductswebcenterindex.html When you unzip PDK-Java, you will find the examples in: ..pdkjpdkv2srcoracleportalsamplev2devguide You can find the Javadoc reference for PDK-Java in: ..pdkjpdkv2apidoc

7.1 Enhancing JPS Portlets

Once you have built your initial portlet in the Portlet Wizard as described in Section 6.3.1, Creating a JSR 168 Portlet , you will want to enhance it. Because JPS portlets adhere to the Java standards, you can find substantial information about enhancing them from many different sources, such as third party books and Web pages. One of the more important enhancements that you might wish to perform is Section 7.1.1, Adding Personalization , which is described in this section.

7.1.1 Adding Personalization

In this section, you enhance the portlet you created in Section 6.3.1, Creating a JSR 168 Portlet with some code that allows a user in Edit or Edit Defaults mode to paste HTML into a field for the portlet to render. You will also see how easily you can redeploy a portlet.

7.1.1.1 Assumptions

To perform the tasks in this section, we are making the following assumption: ■ You built a portlet using the wizard, successfully registered the producer, and added the portlet to the page. 7-2 Oracle Fusion Middleware Developers Guide for Oracle Portal

7.1.1.2 Implementing Personalization

In this section, you add some code to My Java Portlet, redeploy the portlet, and then test it in Oracle Portal. To do this, perform the following steps:

1. In Oracle JDeveloper, double-click the view.jsp file for your JPS-Standard

portlet in the Application Navigator.

2. Add the code that is indicated in bold in the following snippet:

page contentType=texthtml import=javax.portlet.,java.util.,mypackage1.Portlet1, mypackage1.resource.Portlet1Bundle taglib uri=http:java.sun.comportlet prefix=portlet portlet:defineObjects PortletPreferences prefs = renderRequest.getPreferences; = prefs.getValueportletContent, Portlet Content

3. Open edit.jsp in the visual designer and click the Design tab. Notice that the

JSP consists of a form field, a form input field, and two form button fields, as shown in Figure 7–1 . Figure 7–1 edit.jsp in the Design View 4. Add the code that is indicated in bold in the following snippet to implement a form field called Content: FORM ACTION=portlet:actionURL METHOD=POST TABLE BORDER=0 TRTD WIDTH=20 P CLASS=portlet-form-field ALIGN=right = res.getStringPortlet1Bundle.PORTLETTITLE PTDTD WIDTH=80 INPUT CLASS=portlet-form-input-field TYPE=TEXT NAME== Portlet1.PORTLETTITLE_KEY VALUE== prefs.getValuePortlet1.PORTLETTITLE_KEY, Enhancing Java Portlets 7-3 res.getStringjavax.portlet.title SIZE=20 TDTR trtd width=20 p class=portlet-form-field align=right Content p tdtd width=80 tdtr TRTD COLSPAN=2 ALIGN=CENTER INPUT CLASS=portlet-form-button TYPE=SUBMIT NAME= = Portlet1.OK_ACTION VALUE== res.getStringPortlet1Bundle.OK_LABEL INPUT CLASS=portlet-form-button TYPE=SUBMIT NAME= ==Portlet1.APPLY_ACTION VALUE== res.getStringPortlet1Bundle.APPLY_LABEL TDTR TABLE

5. Click the Design tab to see the new form field that you just added

Figure 7–2 . Figure 7–2 Modified edit.jsp in the Design View 6. Open WelcomePortlet.java in the visual editor and insert the following two lines of code indicated in bold in the processAction method: Save the preferences. PortletPreferences prefs = request.getPreferences; String param = request.getParameterPORTLETTITLE_KEY; prefs.setValuesPORTLETTITLE_KEY, buildValueArrayparam; String contentParam = request.getParameterportletContent; prefs.setValuesportletContent, buildValueArraycontentParam; prefs.store; 7. Redeploy the portlet. Notice that Oracle JDeveloper automatically saves and compiles the code before deploying the portlet. Refer to Section 6.3.3, Deploying