Introduction Struts is a very popular open source platform basis, which is designed to make complex web applications creation and maintenance easier. Struts Framework Support Model - View-Controller (MVC) model, and proposes many important application design and implementation that requires attention. In order to be able to implement page navigation in the portal application, WebSphere® Portal V5 provides some tags that can be used for JavaServer Pages (JSP) when developing typical portlets and struts portlets. This article focuses on discussing the Struts framework to create multi-module capabilities, and introduce you to how to use JSP implementation page navigation methods through a sample struts portlet application.
We will pay attention to the following two complementary methods:
How to use a JSP tag available in WebSphere Portal to implement page navigation from JSP, we will see a sample application, including a screenshot of the development environment and portal resources, and code samples for page navigation methods. How to use multi-module support in the Struts Portlet Framework to organize web navigation scenarios. We will see some code samples that describe how to use page navigation features to perform multiple Struts modules converted in the portal environment.
This article assumes that you have basically learned the Struts application, including how to create a Struts application in WebSphere Studio Application Developer, how to deploy Struts as portlets, and also understand the portal resources in WebSphere Portal. (For more information on these aspects, see Resources.)
Used the following products when developing and deploying our sample applications:
WebSphere Portal V5.x WebSphere Application Server V5.X supports the WebSphere Studio Application Developer V5.0.1 of Struts Version 1.1 (hereinafter referred to as Application Developer).
The development tasks used to implement page navigation described herein can be used in both standard portlets and struts portlets.
Application Overview In the sample application, we will use three portlets located on three different pages. When a user selects a link in a portlet, the user will be directed to another page, which resides another portlet. The examples we developed and mentioned throughout the article will use the multi-Struts module to mark the WebSphere Portal page navigation tagged into the JSP file in each module itself in the portal environment. Figure 1 summary shows how the sample application works; in order to understand these methods, we deliberately simplify sample applications. Behind this article we will provide details of the application.
Figure 1. Advanced view of the sample application
Building Navigation Structure WebSphere Portal provides its own JSP tag for portlet JSP. One of them,
Select Administration => Portal Settings => Custom Unique Names in WebSphere Portal. We use Custom Unique Names to manage portlets to get the unique identifier for the portal resource specified by the ContentNode property. Administrators can use the Custom Unique Names portlet to view the unique identifier and assign the portal resource (let people read) custom name. Figure 2 shows the unique identifier and custom names of these configured sample pages: struts_test struts_receiver struts_receiver_2
Figure 2. Custom Unique Names portlet
In this example, the unique identifiers assigned to these pages are 6_0_lt, 6_0_p1 and 6_0_ip, respectively. (Your value may be different.) Also created the same portal resource struts_test, struts_receiver, and struts_receiver_2 portlet page on another machine residing WebSphere Portal. For the convenience of reading and work, we also configure custom names for these sample pages and use these custom names in the JSP file (instead of the only marker).
In the
Any Text
wps: urlGeneration>
<% @ Taglib URI = "/ Web-INF / TLD / ENGINE.TLD" prefix = "wps"%>
Sample pages and portlets Configuring the page navigation bar of the sample application consists of three portlets (the long names here help to emphasize the page navigation process):
Overview Struts Portlet: Two links for setting users to pages that include phone numbers to include phone numbers or address information, which are located in the struts_test page (custom name: struts_test_page), as shown in Figure 3. Figure 3. Struts_test page the Overview Struts Portlet Receive phone numbers Request Struts Portlet: display the user's telephone number, the page is located Struts_Receiver_2 (custom name: Struts_Receiver_2_Page), as shown in Figure 4: Receive phone numbers in FIG. 4. Struts_Receiver_2 page Request Struts Portlet Receive Address Request struts portlet: Displays the user address information, located on the page (custom name: struts_receiver_page), as shown in Figure 5: Figure 5. Remeve Address Request Struts portlet in the Struts_Receiver page, remember that all tasks described so far Can be used for regular portlets or struts portlet development. Next we will use the portal JSP tag in the multi STRUTS module to implement page navigation. Using Multi-Modules in Struts Struts Version 1.1 allows us to split a single Struts application into multiple modules, each module has its own operation, JSP page, and struts profile (Figure 6). Realizing multi-struts modules in the Struts application requires the following steps: Creating a standalone struts profile and Struts operations and JSPs for each application module. Configure the web deployment descriptor (web.xml). Switch from one module to another module. Although the Struts application is easy to apply, you need to perform other steps if you want to run the Struts application in your portal environment. (See Resources). Figure 6. Multi-module support in the Struts application Creates a separate Struts module and file For our sample application, we created four struts modules, as well as their own struts profiles, behaviors, and JSPs. These Struts modules are:
Address Phone-Numbers overview default. We also configure web.xml and portlet.xml files and use the Default module to perform conversions from one module to another module using the DEFAULT module. Next, we will explain the changes needed for our files based on the needs of the implementation. In the Struts module, the development page navigation we implements the page navigation in the following three modules:
In addition to some subtle differences, each page navigation development task in these modules is almost the same. Therefore, we will explain the task of the page navigation of the OverView module, and then describe the difference between the other modules to implement the task and this. In addition, we will also explain the development process specific to the Struts module, which is converted for the Default module. In our implementation, the DEFAULT module is used to hand over the control to the next appropriate module; do not need page navigation. However, since it launches other modules to perform module conversion and is a main part of the navigation structure, we also include it here. In Application Developer, we create a web project that supports Struts Version 1.1 and then creates files for development tasks, as shown in Table 1 below. Table 1. List of development components The following is a brief description of the components shown in Table 1: JSP file: We have developed five JSP files:
INDEX.JSP and FAILURE.JSP files for the Default module; address.jsp files for the Address module; Phone-number for the Phone-Numbers module; for the OverView.jsp file for the Overview module. Operation: We create four Struts operations in the com.test.strutstest.Am .Actions package. Their classes are:
DisplayAction DisplayAddressInfoAction DisplayPhoneInfoAction overviewAn: We create two form beans in the com.test.strutstest.forms package. Their classes are:
UserformBean OverviewFormBean. Back end bean and model class: We use a backend bean class (Userbean) and a model class in the package (userbeanhelper). (The backend bean contains the stub data, does not communicate with the true backend.) Struts configuration file: We develop four struts-config.xml files, each module uses:
WEB-INF / STRUTS / STRUTS-Config.xml for the Address Module for WEB-INF /-NUMBERS / STRUTS-Config.xml for the Phone-NumBers module WEB-INF / OVERVIEW / STRUTS-CONFIG.XML for OverView modules. Other configuration files: You need to modify the web.xml and portlet.xml file when deploying the Struts application as a portlet. Each of the above configuration files contains the following request processor:
Processorclass = "com.ibm.wps.ports.struts.wpsRequestProcessor"> Figure 7 shows the location of the development component in the Application Developer development environment: Figure 7. The location of the development component in WebSphere Studio Application Developer The default module To start the DEFAULT module and see how it transforms between Struts modules, you need to execute The following steps: The Default module is started when WebSphere Portal calls the index.jsp file, which is specified in the welcome-file-list> When calling index.jsp, specify the logic forwarding name DISPLAY in the Logic Struts tag: Define the logic forward name in the Struts-Config.xml file of the DEFAULT module as global forwarding: global-forwards> In the TYPE = "com.test.strutstest.actions"> ............................................... action> action-mappings> To enable module conversion, configure the struts-config.xml, portlet.xml, and config.xml files for the Remaining module: Configure the Struts-Config.xml file of the default module. We use DisplayAction as our operational and four logic forwarding: TYPE = "com.test.strutstest.actions"> ContextRelative = "true" Path = "/ failure.jsp" /> ContextRelative = "true" Path = "/ address / start.do" /> ContextRelative = "true" Path = "/ phone-number / start.do" /> ContextRelative = "true" PATH = "/ overview / start.do" /> action> action-mappings> Configure the portlet.xml file to make it compliant with the configuration in the Struts-Config.xml file of the DEFAULT module. In particular, each of the four logical forwarding names in the Struts-Config.xml file of the default module is matched to the View.ForWard configuration parameter value set in the portlet.xml file. Table 2 shows this mapping relationship: Table 2. View.Forward configuration Value Configures a web.xml file for forwarding name configuration values to define different modules. We use config initialization parameters to tell our default module; however, for each of the other modules, we list a initialization parameter called config / module, where Module is our module name. E.g: You can define the default module like this: init-param> can define other modules like this: param-value> init-param> param-value> init-param> param-value> init-param> (Other module configurations and the necessary web.xml configuration settings See the reference information.) Perform standard updates to Web.xml and portlet.xml files to deploy the Struts application as portlets. (To get more information, please refer to the sample web.xml and portlet.xml files for the Download section.) The module conversion is configured as the PortletSettings PortletSettings = Request.getPortletSettings (); String ViewForward = PortletSettings.GetaTribute ("View.Forward"); For our portlet, the View.Forward parameter has the following values: Table 3. View.Forward configuration parameters of the sample portlet If ViewForWard is empty, this variable is set to Failure in the Execute () method. The forwarded mapping of configured ViewForward values is retrieved from the struts-config.xml file: ActionForward Forward = New ActionForward (); Try { Forward = mapping.findforward (forwardname); } Catch (Exception E) { ........................................... } The last step in the execute () method returns an instance of an actionForward (FORWARD): Return (Forward); Configure other struts-config.xml files. Determine the result according to the module in the DisplayAction class, if the View.Forward parameter value is: Address: The Start path that matches in the global-forwards> Name = "Userformbean" Scope = "Request"> action action-mappings> Phone-number: The Start path that matches in the global-forwards> Type = "com.test.strutstest.Actions.displayphoneInfoaction" Name = "Userformbean" Scope = "Request"> action action-mapings> Overview: The Start path that matches in the global-forwards> TYPE = "com.test.strutstest.actions.overview" Name = "overviewFormbean" Scope = "Request"> action> action-mappings> failure: The Failure.jsp is started under this parameter value based on the configuration in the Struts-Config.xml file of the default module. So far, we have created the files listed in Table 1, and modify them according to our example needs. Now we can start writing code to implement page navigation using the OverView module. The following sections will guide you through the specific steps. Develop overview modules To generate Overview.jsp files, OverViewAction classes, OverViewFormBean classes, and overview / struts-config.xml files to develop overview struts portlets, follow these development tasks in operation and JSP files: Once the control is transferred from the Default module to the OverView module, the Execute () method in the OverViewAction class performs the following tasks: Access the OverViewFormBean form bean and set the following properties: Try { String forwardname = null; IF (Form == Null) { Form = (ACTIONFORM) Request.GetaTribute ("overviewformbean"); } // SET-UP FORM Bean Fields OverviewFormBean Formbean = (overviewFormbean) Form; FORMBEAN.SETPHONENENUMBERSLINKNAME ("List Phone Numbers"); FORMBEAN.SETADDRESSLINKNAME ("Address Information"); ................................................ Make the form bean in the correct scope: Try { // store the bean in the correct scope IF ("REQUEST" .Equals (mapping.getscope ())))) Request.setttribute (mapping.getname (), formbean; Else Session.SetAttribute (mapping.getname (), formbean; } Catch (Exception E) { ................................ } Find maps in Overview / Struts-Config.xml and return an actionForward type: String forwardname = null; ActionForward Forward = New ActionForward (); ....................................... // if no errors occur the ing for "success" TRY { Forward = mapping.findforward (forwardname); IF (Forward! = NULL) { ..................................... } Else ..................................... } Catch (Exception E) { ................................. } Return (Forward); if there is no error during the processing of the operation class, the forwarded name Success will allow Overview.jsp based on the configuration in our overview / struts-config.xml file. Overview.jsp Display two links, pointing to other portlets - Receive Phone Numbers Request Struts portlets and Receive Address Request Struts portlets. We use the page navigation method and the Struts tag to implement this feature: The Taglib instructions in the first place in the JSP page are used to make all Engine.TLD tags available for the remaining JSP pages with prefix.wps. <% @ Taglib URI = "/ Web-INF / TLD / ENGINE.TLD" prefix = "wps"%> Use the ContentNode parameter in the WPS: URLGENERATION> To start the page navigation to the Receive Phone Numbers Request Struts Portlet, we use the custom name Struts_Receiver_2_page: Property = "phonenumberslinkname" /> wps: urlGeneration> This way we get the custom name of the page from My Pages and the Unique Name list, as shown in Figure 2. In the Overview module, we use <% @ Taglib Uri = "/ Web-INF / TLD / STRUTS-HTML.TLD" prefix = "html"%> <% @ Taglib URI = "/ Web-INF / TLD / STRUTS-Bean.TLD" prefix = "bean"%> START property maps the following operations in OverView / Struts-Config.xml file: TYPE = "com.test.strutstest.actions.overview" Name = "overviewFormbean" Scope = "Request"> action> action-mappings> Struts tag connects the form field and the form bean in Struts. Positioning (or generated, if necessary) form bean based on a form bean specification (or generated, if necessary) based on the form bean specification for the associated actionmapping. The form bean defined in the overview / struts-config.xml file is UserformBean: FORM-Beans> . Address.jsp DisplayAddressInfoAction class UserFormBean form bean class UserBean backend bean class UserBeanHelper model class address / struts-config.xml file phone-numbers module implements Receive Phone Numbers Request Struts Portlet used are: phone-numbers.jsp DisplayPhoneInfoAction class UserFormBean form bean class UserBean backend bean class UserBeanHelper model class phone-numbers / struts-config.xml. For address and phone-numbers modules, and classes are rear UserBean bean model we are using UserBeanHelper These two classes require the use of stub data to simulate user information, while the stub data is set to the backend bean using our module classes. Both modules use the same form bean. To develop the Address module in the DisplayAddressInfoAction class is: Once the control is transferred from the Default module to the Address module, the Execute () method of the DisplayAddressInfoAction class performs the following tasks: Access Form Bean - UserformBean and set the following properties: Try { String forwardname = null; IF (Form == Null) { Form = (ACTIONFORM) Request.getaTribute ("Userformbean"); } // SET-UP FORM Bean Fields Userformbean formbean = (userformbean) Form; SetFormbean (FORMBEAN); ................................................ . Store this form bean in the correct scope: Try { ...................................... // store the bean in the correct scope IF ("REQUEST" .Equals (mapping.getscope ())))) Request.setttribute (mapping.getname (), formbean; Else Session.SetAttribute (mapping.getname (), formbean; } Catch (Exception E) { ................................ } Find mappings in Address / Struts-Config.xml and return an object of an ActionForward type: String forwardName = null; actionforward forward = new actionforward (); ....................................... // if no errors occur then ing for "success" Try { Forward = mapping.findforward (forwardname); IF (Forward! = NULL) { ..................................... } Else ..................................... } Catch (Exception E) { ................................. } Return (Forward); Call SetFormBean (UserformBean Formbean). This method gains a single instance of the model: Userbeanhelper userbeanhelper = userbeanhelper.getinstance (); This instance is implanted into backend data, sets the instance object of the userformbean, and returns the object using the following method calls: Userformbean userformbean = userbeanhelper.getuserformbean (); This method is to set the properties of the FORMBEAN together with the appropriate Getter and Setter methods, as shown below, where the objects returned from the model are used: Public void setFormBean (UserformBean FORMBEAN) { Userbeanhelper userbeanhelper = userbeanhelper.getinstance (); Userformbean userformbean = userbeanhelper.getuserformbean (); // There Two Parameters Are Just Text Values To Be Displayed On The Browser FormBean.SetAddress ("Address"); FormBean.SetUserName ("UserName"); // setting the formBeans Object Attributes with data obtained from the backend FORMBEAN.SETADDRESSVALUES (UserformBean.getaddressValues ()); FORMBEAN.SETUSERNAMEVALUES (UserformBean.getuserNameValues ()); } If there is no error in the operation class processing, the forwarding name Success will start the address.jsp file to be launched based on the configuration in our Address / Struts-Config.xml file. After appropriate modification, the above steps can be repeated to develop the Phone-Number module. Page Navigation Use the address.jsp and phone-numbers.jsp files for the Receive Address Request Struts Portlet and Receive Phone Numbers Request Struts portlets are performed using the Overview Struts Portlet and the Struts tag: The front end of the JSP page uses the Taglib tag library instruction to make all Engine.TLD tags can be used for the remaining JSP pages with Prefix.WPS. <% @ Taglib URI = "/ Web-INF / TLD / ENGINE.TLD" prefix = "WPS"%> Use the contentNode parameters in the Go to overview struts portlet b> wps: urlGeneration> td> In our implementation, the Declare the logic prefix: <% @ Taglib URI = "/ Web-INF / TLD / STRUTS-LOGIC.TLD" prefix = "logic"%> Use the Property = "UsernameValues" indexid = "index"> To establish a development environment and install the sample code To create your own development environment in Application Developer, use the information provided in a simple Struts application to WebSphere Portal 4.2 development struts applications and using WebSphere Studio V5. You need to import the Strutstest.war file of the download section into Application Developer and use all of its JAR files. Installing the sample code in WebSphere Portal does not require any special installation steps; you can use the WAR files you can use, which is willing to use which one can be used. Ending the text The page navigation feature provided by WebSphere Portal is described through a portlet mark, and also describes the multi-module support provided by the Struts portal framework. In our sample implementation, we created the portal page where the application is located, and then merge the portlet JSP to merge in the appropriate JSP. We use the page's custom name in JSP instead of the unique marker assigned by the portal server, which makes our JSP deployment relatively independent. Although our example is not a very complex application, the framework provided by Struts can process large and complex application flows well. Multimode supports a single file group for each module that supports parallel development, and also provides better file organizations, multi-module support can coordinate work with the page navigation method provided by WebSphere Portal JSP tags. Acknowledgment Author I sincerely thanked Tim Hanis and Jim Bonanno as a technological critics to comments and contributions to this article. Reference WebSphere Portal Information Center for v5.0: Provides fast and centralized information for WebSphere Portal. Important aspects include: Developing Portlets => Struts Portlet Framework => Changes to configuration files Developing Portlets => Struts Portlet Framework => Migrating existing Struts Applications Developing Portlets => JSP tag reference The Jakarta Apache Struts Web Application Framework's User and Developer Guides write a using WebSphere Studio V5 Simple Struts Application Develops and Deployed a Struts application as a WebSphere Portal V5 portlet to apply status mode to WebSphere Portal V5 portlet - Part 1: Overview Apply Status mode to WebSphere Portal Portlets for WebSphere Portal 4.2 Develop Struts Applications