14.1 Overview

 <  Day Day Up  >  

The Struts framework divides your application into three functional areas. The model is the business logic, which in most cases involves access of data stores such as relational databases. The development team that handles the model may be expert at writing DB2 COBOL programs, or EJB entity beans, or some other technology appropriate for storing and manipulating enterprise data.

The view is the code that presents images and data on Web pages. The code comprises JSPs and the JavaBeans that store data for use by the JSPs. The controller is the code that determines the overall flow of events.

Figure 14-1. The three tiers of the Struts framework

graphics/14fig01.gif

Struts supports this model by providing the following components :

  • The Struts action servlet handles run-time events in accordance with a set of rules that are provided at deployment time. Those rules are contained in a Struts configuration file (struts-config.xml) and specify how the servlet responds to every outcome received from the business logic. Changes to the flow of control require changes only to the configuration file.

    Struts also provides the Java class org.apache.struts.action.Action, which a Java developer subclasses to create an "action class". At runtime, the ActionServlet is said to "perform actions", which means that the servlet invokes the perform method of each of the instantiated action classes.

    Note : The object returned from the perform method directs ActionServlet as to what action or JSP to access next .

  • Struts provides the Java class org.apache.struts.action.ActionForm, which a Java developer subclasses to create a form bean. At runtime, the bean is used in two ways: when a JSP prepares the related HTML form for display, the JSP accesses the bean, which holds values to be placed into the form. Those values are provided from business logic or from previous user input. When user input is returned from a Web browser, the bean validates and holds that input either for use by business logic or (if validation failed) for subsequent redisplay.

  • Struts provides numerous , custom JSP tags which are simple to use but are powerful in the sense that they hide information. The page designer does not need to know much about form beans beyond, for example, the bean names and the names of each field in a given bean.

Note:

For more detailed information, you can find numerous sources available about Struts. The Struts Web site offers resources for developers, including a User Guide, informative JavaDoc, and the source code. For more information about Struts, see the Struts Application Framework at:

http://jakarta.apache.org/struts/


14.1.1 The Struts portlet framework

Struts application can run within WebSphere Portal using the Struts portlet framework. Developers that have worked with Struts in the servlet environment should adapt easily to the Struts Portlet Framework. The packaging of a Struts portlet application is very similar to a Struts application in the servlet environment.

However, WebSphere Portal also introduces additional concepts, such as portlet modes, multiple device support, and portlet communication, which might need to be addressed by the Struts application. Because of this, developers have to consider the following main issues when developing Struts portlets:

  • Action processing and rendering

    In a normal servlet application all servlet processing occurs during the service() method. The Struts rendering of the page is usually immediately preceded by action processing; they are essentially part of one step. Portlet processing, however, is implemented in two phases, an action phase and a rendering phase.

    When a Struts application is migrated to the portlet environment, some of the information that was available during the action phase, namely the request parameters, is no longer available during the rendering phase. Additionally, since rendering methods , such as doView(), can be called when the portlet page is refreshed without a new event occurring for that portlet, all information required to render the page must be available every time that method is called.

    A command pattern can be used to encapsulate the rendering of the view, and the information required during this rendering. The pattern is implemented using the IViewCommand interface.

  • URI construction

    URIs are constructed differently for portlets than for servlets. The portlet creates the URI using the PortletResponse.createURI() method. The Struts Portlet Framework has modified the tags in Struts so that they create portal links.

  • Changes to the configuration files

    To run a Struts Web application within WebSphere Portal, developers have to add new init parameters to the Web deployment descriptor (web.xml). The Struts configuration file (struts-config.xml) must also be changed to specify the WpsRequestProcessor as the controller

For more detailed information about the Struts portlet framework, see the Struts Portlet Framework chapter of the Portal Infocenter:

http://publib.boulder.ibm.com/pvc/wp/500/ent/en/InfoCenter/index.html

 <  Day Day Up  >  


IBM WebSphere Portal V5 A Guide for Portlet Application Development
IBM Websphere Portal V5: A Guide for Portlet Application Development
ISBN: 0738498513
EAN: 2147483647
Year: 2004
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net