Oracle Portal and the Apache Struts Framework

Enhancing Java Portlets 7-87 JSPs to render the application content in a Web browser. This model differs from JSP Model 1, where the JSPs managed the browser request and data access. The Struts framework provides its own HTTP Servlet as a controller component. The Struts framework is driven by an XML configuration file that contains the page flow of the application. Struts does not provide the Model, but allows developers to integrate it to any data access mechanism, for example EJBs, TopLink, or JDBC. The most common technology for writing View components is JSP and Struts provides various tag libraries to help in writing these, although some of these tags have now been superseded by the Java Standard Tag Library JSTL, which may also be used.

7.3.1.3 Oracle Portal Integration with Struts

The Oracle Portal Developer Kit contains numerous examples and documents regarding the usage of the Oracle Portal APIs, such as personalization and caching. The integration of the application flow and business logic is not part of the portlet APIs. By using the Struts framework, however, you can leverage the MVC architecture to create and publish applications within your enterprise portal. Oracle Struts Portlet To create a portlet using the Struts framework, or to generate a portlet from an existing Struts application, you must deploy all the components in the J2EE container. In the context of Oracle Portal, the Struts application is called by the PPE, and not by the browser as compared to a standalone Struts application. When a portlet show call is made, the page engine sends a request to the Struts portlet renderer, which then forwards the request to the Apache Struts Controller servlet, as shown in Figure 7–15 . Figure 7–15 Integrating Struts Applications with Oracle Portal The following code shows a portion of the provider definition file provider.xml: ... Note: For more information about JSTL and JSF, see the FAQ on the Apache Software Foundation Web site http:struts.apache.orgkickstart.html . 7-88 Oracle Fusion Middleware Developers Guide for Oracle Portal renderContainertruerenderContainer renderCustomizetruerenderCustomize autoRedirecttrueautoRedirect contentTypetexthtmlcontentType showPage class=oracle.portal.provider.v2.render.http.StrutsRenderer defaultActionshowCustomer.dodefaultAction showPage renderer ... For more information on the syntax of provider.xml, refer to the provider Javadoc on OTN: http:www.oracle.comtechnologyproductsiasportalhtmljavadocxml_ tag_reference_v2.html The showPage tag defines the business logic that will be executed in the Show mode of the portlet. The showPage of the Struts portlet contains two important components, which are as follows: 1. The renderer class oracle.portal.provider.v2.render.http.StrutsRenderer, which receives the portlet request from the PPE and acts as a proxy to forward the request to the Struts Action Servlet. 2. The defaultAction tag, which defines the Struts action that will be used by default when the portlet is called for the first time. The PDK-Java enables you to easily develop a view Portal View of your Struts application. This view enforces a consistent look and feel of your Struts portlet using portal styles, and allows the end user to use the application within the portal. To create a Struts portlet, you must use the Oracle Portal JSP tags, which are extensions of the default Struts JSP tags. This development process is similar to that of creating a standalone Struts application. To learn how to build a Struts portlet, refer to Section 7.3.2.1, Creating a Struts Portlet . Also, since the portlet and struts application must also be in the same Servlet Context, you must create a single Web application that contains both elements. To learn how to easily create this Web application in Oracle JDeveloper, refer to the next section, Section 7.3.2.1, Creating a Struts Portlet .

7.3.1.4 Summary

Apache Struts has become the de facto standard for developing MVC-based J2EE applications, because it offers a clean and simple implementation of the MVC design paradigm. This framework enables you, as the portlet developer, to separate the different components of an application, and to leverage the Struts controller to easily publish an existing Struts application to Oracle Portal without completely changing the existing business logic.

7.3.2 Creating a Struts Portlet

Oracle PDK contains new extensions to integrate Apache Struts applications. This section explains how to build a portlet from an existing struts application. You can also Note: For more information on the Oracle Portal Developer Kit, see Portal Center http:www.oracle.comtechnologyproductsiasporta lpdk.html Enhancing Java Portlets 7-89 follow these steps to create a portlet that uses the Model View Controller paradigm. To learn more about the Apache Struts framework, refer to Section 7.3.1, Oracle Portal and the Apache Struts Framework . The PDK-Java extensions described in this section rely on Apache Struts 1.1. This section contains the following steps: ■ Section 7.3.2.1, Creating a Struts Portlet ■ Section 7.3.2.2, Registering the Provider ■ Section 7.3.2.3, Summary

7.3.2.1 Creating a Struts Portlet

To publish a part of an existing Struts application as portlet, we recommend that you first create a new view to serve as the Portal View of your application. This view uses existing objects Actions, ActionForm, and so on with a new mapping and new JSPs. In this example, you will create a portlet that enables you to add a new entry to a Web Logger Blog. Figure 7–16 and Figure 7–17 show how you submit a blog and save a blog entry. Figure 7–16 Submitting a Blog Note: Although we recommend that you create a Portal View of your application, you could alternatively replace your applications struts tags with PDK-Java struts tags. This approach enables your application to run both as a standalone struts application and a portlet. 7-90 Oracle Fusion Middleware Developers Guide for Oracle Portal Figure 7–17 Saving a Blog Entry prepareNewBlog is a simple empty action that redirects the request to the enterNewBlog.jsp page. This page shows a form for submitting a new blog. The corresponding entry in the struts-config.xml is: action path=prepareNewBlog scope=request type=view.PrepareNewBlogAction forward name=success path=viewenterNewBlog.jsp action action path=saveNewBlog name=blogForm scope=request type=view.SaveNewBlogAction inputviewenterNewBlog.jsp forward name=success path=viewnewBlogConfirmation.jsp action

7.3.2.1.1 Create a new flow and view to host the portlet actions To create a new view, first

create a new set of ActionMappings page flow that will redirect the various actions and requests to Portal-specific JSPs. action path=portalprepareNewBlog scope=request type=view.PrepareNewBlogAction forward name=success path=viewportalenterNewBlog.jsp action action path=portalsaveNewBlog name=blogForm scope=request type=view.SaveNewBlogAction input=viewenterNewBlog.jsp forward name=success path=viewportalnewBlogConfirmation.jsp action As you can see, only the path attributes are modified. The FormBean Action responsible for the application business logic remains unchanged.

7.3.2.1.2 Creating the new JSPs As specified in the previous step, the actions forward

the request to new JSPs, which are responsible for rendering the portlet content. Your new portlet view JSPs can share the HTML with the standalone view, but be sure that the portlet meets the following criteria: ■ Uses Portal styles that enforce a consistent look and feel with the rest of the portal page. ■ Contains HTML code that is allowed in HTML table cells that is, no html, body, and frame tags. ■ Renders portal-aware links and forms. This is necessary to ensure that your Struts portlet renders its content inline, thus keeping your users within the context of the portal page by rendering the requested content within the same portlet container.