Develop and deploy a Struts application as a WebSphere Portal V5 portlet

xiaoxiao2021-03-06  69

This document describes how to develop and deploy an application that runs and deployed as a portlet in IBM WebSphere Portal V5 using Jakarta Struts Framework (incorporated into IBM Struts portlet framework).

Introduction This article discusses how to use Struts Portlet Framework to implement a portlet written for IBM WebSphere Portal Version 5 (hereinafter referred to as WebSphere Portal). Struts is an Apache Jakarta project that provides a very popular open source framework for creating a web application. WebSphere Portal V5.0 provides Struts Portlet Framework to support the Struts application as a portlet deployment. The Struts Portlet Framework also supports Portal mode and devices in the Struts application.

If you have read the previous article describing the use of status mode to implement portlet, you will be familiar with the sample application used in this article. It follows the same design principle, but here is the use of Struts to develop and deploy. This application maintains a contact list that is specific to the user who logs in to Portal (address this entry). The contact list is stored in the database or memory. Users can individually view the contacts in the list for more detailed information. The edit mode of the portlet allows the user to add, delete, or modify contact information.

The focus of this article is not to develop a Struts web application; in the development of the implementation and configuration required for the Struts application as a portlet. You can learn how to create a portlet using Jakarta Struts Framework. In WebSphere Portal V5, Struts Portlet Framework came with Jakarta Struts 1.1.0.

The following products are used in the development and deployment of the sample application:

IBM WebSphere Portal Server Version 5.0 IBM WebSphere Application Server Version 5 A database for saving a contact entry (optional) IBM WebSphere Studio Version 5 (optional)

About the sample portlet application sample application implements a create / read / update / delete (crUd) operation for a set of persistent data. It maintains a list of contacts for specific users (such as simple address books). This application allows users to individually view contact entries or view contact entries in a list.

From a visual perspective, the implementation of the contact list application includes the following view (page):

Login View - Displays the view of the user login. Main View - Displays the contact list and takes options to select more information. Detailed View (Detail View) - Displays the details of the selected contact. Main Edit View - Displays the contact list and has an option to add, delete, and modify contact information. Add a contact view - Displays the table view to enter the information of the new contact. Modify the contact view (Modify Contact View) - Displays the form view to display the elements data of the existing contacts and allow updates.

This app does not provide an explicit page to delete an entry. Instead, to delete an entry, the user needs to select a contact entry from the main editing page, and then delete the process and refresh the main editing page. If there is an error, the system will display the appropriate message. No confirmation page and successfully executed page. Figure 1. Main view

Design portlet application

The previous article on the use of status mode implementation portlet is similar to the discussion below, because Struts implementation and status mode are basically similar.

Consider the operation and view of this application. You can see the operation as a user-level function or behavior you want to implement for the portlet. For example, you may need an action to add a contact or display a specific view. The view is the performance of the application after completing the user operation. For example, the result of adding a new contact can produce the result of the editing mode, the view of the portlet displays the contact home list.

Next, consider how you want the app to be visual. In this example, you need a main view page to list the contacts created. This page should allow users to choose a contact and obtain additional details about this person.

You want the contact list to each user; therefore, this portlet requires the user (user) object to be associated with the logged user.

You want to allow users to add, delete, and modify contacts in the list. You can provide a master-editing page to list contacts and support the deletion and modification of the selected entry. You don't need to delete a selected entry for the user to implement another view; you only need to allow users to delete a selected entry, and then use the modified contact list to refresh the primary editing page.

If the user selects a contact for modification, you can display a detailed page that can update any properties of this contact entry. After the user has completed the modification, you can restrict the main editing page.

Similarly, you can add a new contact from the main editing page. You can display another detailed page that users can enter and save properties of the contact entries. After the user is saved, you can re-display the primary editing page with the updated list.

Now you can determine the state shift available for this application. By applying appropriate operations to generate specific views, you can manage transfer. In the figure below, the view (JSP) is indicated by an ellipse, and the operation is indicated by a rectangle.

Figure 2. Status transfer graph

Implement portlet using Struts

This design requires you to achieve 7 operations. These operations are defined in the implementation provided herein:

MainviewAction DetailViewAction MAINEDITACTION AddContactivity deleteContactAction ModifyAction ModifyContactAction

From the state diagram you can see that the Add Contact view is actually direct steering from the main view to Add Contact JSP. Because no logic is required before rendering the Add Contact view, you can simply call the Add Contact JSP and configure it to global forward instead of operation.

Establish development environment

To launch a Struts-based Portle project in WebSphere Studio, you need to follow these steps:

Create a new J2EE Level 1.3 Enterprise Application Engineering. Import the Struts Portlet Framework. In the Standard WebSphere Portal V5.0 installer, you will find the portalstrutsblank.war file in the /dev/strutsblank.war directory. Importing this WAR file will add the Struts JAR file to the project lib directory for Jakarta Struts and IBM Struts Portlet Framework. Figure 3. Importing Struts Portlet Framework After the import is complete, you may see some verification warnings and an error in the project's WebSphere Studio task list. XML validation error: Attribute "bundle" must be declared for element type "field" in validation.xml WARNING: Target welcome does not exist in the following modules: / Warning: Target /Welcome.do does not exist in the following modules: / In Index.jsp and struts-config.xml. You can now ignore these messages. After you update the default validation.xml, you can solve the verification error. The validator in WebSphere Studio gives warnings about the resources that cannot be found in the basic module. You can now ignore these messages. This completes the basic settings of developing the Struts application in Studio.

If you don't use Studio, make sure that the following JAR files (and the Struts JAR file you import) are available in the build path. You can find these files in WebSphere Application Server and WebSphere Portal directories.

/lib/ivjejb35.jar /lib/j2ee.jar /lib/runtime.jar /lib/servletEvent.jar / Java / JRE / lib / rt.jar /shared/app/portlet-api.jar

Before considering the implementation details of the category, beans, forms, and supported classes, make sure the implementation of the application configuration file. These files include:

Web application deployment descriptor, web.xml struts form verification XML file, validation.xml portlet deployment descriptor, portlet.xml struts configuration file, struts-config.xml

You need to update all of these files.

Web deployment descriptor - web.xml default web.xml file is provided as part of Portal Struts Framework. You need to change the deployment descriptor based on a particular application. First, "DISPLAY-NAME" is changed to the name meaningful name, such as Contacts List. ID must be unique in the deployed portal environment. Change this value to a unique string.

Building Struts 1.1 support in this framework divides the application into a module. When using the module, the configuration information and directory structure of a program are divided by module. Therefore, instead of a single struts-config.xml file for the application, you have multiple control files with independent directory structures, which are identified by the application URI. Struts Portlet Framework utilizes module support to provide Struts configuration mode and device (tag) distinction. The search path is used to determine the module and struts-config.xml file you want to use. It also determines the basic directory for positioning JSP. When searching for modules, add the following initial parameters Set the search path to consider tag names and patterns when searching modules.

ModulesEarchPath

Markupname, Mode

You created two modules for this app, one for editing mode, and another for help mode. The view mode is configured by the basic Struts configuration. These two modules are configured as initial parameters in such a form: / config / / . Therefore, you have config / html / edit and config / html / help. Add the parameter values ​​associated with these modules to indicate where to start searching the Struts profile.

config / html / help

/web-inf/html/help/struts-config.xml

config / html / edit

/Web-inf/html/edit/struts-config.xml

Add two applications-specific initial parameters persist_to_db and DataSource to support persistence classes, which is part of the download. Setting this value to TRUE to cause deployment database proxies. If you use the database agent, you also need to set the data source. Set the value of the data source to the name of this data source. If you are using persistence in memory, you can ignore the value of the data source.

Finally, change the list of welcome files. Struts Portlet Framework allows you to specify an initial view of the device / mode. This can be specified by the list of welcome files.

Index.jsp

HTML / Help / Index.jsp

html / edit / index.jsp

Portlet deployment descriptor - portlet.xml

You must also change the default portlet.xml file, which is provided by the blank Struts portlet.

Change and to meaningful names. Change the to the unique identifier. Change HREF to the associated servlet ID, which is specified as a web.xml value. For example, if you specify a ContactSlistportlet for a servlet ID in Web.xml, you can specify a web-inf / web.xml # ContactSlistportlet for portlet href in portlet.xml. Specify the editing and help mode support for the HTML device, and view mode. For specific portlet applications, the unique UID and meaningful names are specified for portlet-app-name and portlet-name. The value of the Concrete-Portlet HREF matches the value of the portlet application . Finally, a meaningful value is specified for the language of the title, short title (Title-Short), a description and keyword (Keywords). Listing 1. Portlet.xml

"- // ibm // DTD portlet application 1.1 // en" "portlet_1.1.dtd">

Major-Version = "1" minor-version = "0">

Contacts list application

HREF = "Web-inf / web.xml # Contacts_list_portlet.contactslistportlet"

Major-Version = "1" minor-version = "0">

Contacts List portlet

0

no

Contacts List application

Contacts List portlet

en

Contacts List portlet </ title></p> <p><title-short> contacts list </ title-short></p> <p><Description> Contacts List portlet </ description></p> <p><Keywords> WPS, Struts </ keywords></p> <p></ logage></p> <p><config-param></p> <p><param-name> filterchain </ param-name></p> <p><param-value> strutstranscoding </ param-value></p> <p></ config-param></p> <p></ concrete-portlet></p> <p></ concrete-portlet-app></p> <p></ portlet-app-def></p> <p>The Struts Profile-Struts-Config.xmlstruts-Config.xml file contains the application definition of Struts Framework for control, navigation, and configuration settings (including the desired form bean).</p> <p>As mentioned above, when changing the web.xml file, the parameter value associated with each of the two application module definitions indicates where to start searching for a module-specific Struts profile. Therefore, you need to create a new struts-config.xml file, which will reside in / Web-INF / HTML / EDIT / and / WEB-INF / HTML / HELP /. These files will contain Struts configuration information specific to which they are made.</p> <p>First, change the Struts-Config.xml file in the / web-inf directory to the Structs configuration of the view mode. You need to create an action element in XML to support the operations identified in the transfer chart. There are seven specified operations. These operations can be defined below and will be displayed using the class names defined in the example implementation. You also specify the appropriate steering settings for each operation to indicate the JSP for rendering the request view. These rendering status are specified in the state transition chart. You can include these appropriate operations and steals in a module-specific configuration file.</p> <p>Next, create a new Struts-Config.xml file in the directory specified above.</p> <p>Struts-config.xml</p> <p><form-beneans></p> <p><form-bean name = "contactform"</p> <p>TYPE = "com.ibm.sample.contacts.struts.beans.contact" /></p> <p></ form-beans></p> <p>You can also specify global steering, message source files, and verify XML file references. Global steering enabling the logical name associated with a URI pointing to JSP or an operation.</p> <p>Listing 2. View - /web-inf/struts-config.xml<?XML Version = "1.0" encoding = "ISO-8859-1"?></p> <p><! DocType struts-config public</p> <p>"- // Apache Software Foundation // DTD Struts Configuration 1.1 // En"</p> <p>"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"></p> <p><struts-config></p> <p><form-beneans></p> <p><form-bean name = "contactform"</p> <p>TYPE = "com.ibm.sample.contacts.struts.beans.contact" /></p> <p></ form-beans></p> <p><global-forwards></p> <p><forward name = "mainview" Path = "/ mainview.do" /></p> <p><forward name = "notauthenticated" path = "/ not_authenticated.jsp" /></p> <p><forward name = "exception" path = "/ exception.jsp" /></p> <p></ global-forwards></p> <p><action-mappings></p> <p><action</p> <p>PATH = "/ mainview"</p> <p>TYPE = "com.ibm.sample.contacts.struts.action.mainview"</p> <p>Name = "ContactForm"</p> <p>Scope = "request"</p> <p>Validate = "false"></p> <p><forward</p> <p>Name = "mainviewpage"</p> <p>PATH = "/ main_view.jsp" /></p> <p></ action></p> <p><action</p> <p>Path = "/ detailview"</p> <p>TYPE = "com.ibm.sample.contacts.struts.action.detailview"</p> <p>Name = "ContactForm"</p> <p>Scope = "request"</p> <p>Validate = "false"></p> <p><forward</p> <p>Name = "detailviewpage"</p> <p>Path = "/ detail_view.jsp" /></p> <p></ action></p> <p></ action-mappings></p> <p><Controller</p> <p>Processorclass = "com.ibm.wps.ports.struts.wpsRequestProcessor"></p> <p></ controller></p> <p><message-resources</p> <p>Parameter = "com.ibm.sample.contacts.struts.nls.ApplicationResources" /></p> <p><plug-in classname = "org.apache.struts.validator.validatorPlugin"> <set-protety property = "pathnames"</p> <p>Value = "/ Web-inf / validator-rules.xml,</p> <p>/Web-inf/Validation.xml "/></p> <p></ plug-in></p> <p></ Struts-Config></p> <p>Listing 3. Edit - /Web-inf/html/Edit/struts-config.xml</p> <p><? Xml Version = "1.0" encoding = "ISO-8859-1"?></p> <p><! DocType struts-config public</p> <p>"- // Apache Software Foundation // DTD Struts Configuration 1.1 // En"</p> <p>"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"></p> <p><struts-config></p> <p><form-beneans></p> <p><form-bean name = "contactform"</p> <p>TYPE = "com.ibm.sample.contacts.struts.beans.contact" /></p> <p></ form-beans></p> <p><global-forwards></p> <p><forward name = "addcontactpage" Path = "/ add_contact.jsp" /></p> <p><forward name = "mariedit" path = "/ maindit.do" /></p> <p></ global-forwards></p> <p><action-mappings></p> <p><action</p> <p>Path = "/ mainedit"</p> <p>Type = "com.ibm.sample.contacts.struts.action.maundage"</p> <p>Name = "ContactForm"</p> <p>Scope = "request"</p> <p>Validate = "false"></p> <p><forward</p> <p>Name = "mainditpage"</p> <p>Path = "/ main_edit.jsp" /></p> <p></ action></p> <p><action</p> <p>PATH = "/ modify"</p> <p>TYPE = "com.ibm.sample.contacts.struts.action.modify"</p> <p>Name = "ContactForm"</p> <p>Scope = "request"</p> <p>Validate = "false"></p> <p><forward</p> <p>Name = "editcontactpage"</p> <p>PATH = "/ edit_contact.jsp" /></p> <p><forward</p> <p>Name = "deletecontact"</p> <p>Path = "/ deletecontact.do" /></p> <p></ action></p> <p><action</p> <p>Path = "/ modifycontact" type = "com.ibm.sample.contacts.struts.Action.modifyContactivity"</p> <p>Name = "ContactForm"</p> <p>Scope = "request"</p> <p>Validate = "false"></p> <p><forward</p> <p>Name = "marinedit"</p> <p>PATH = "/ mainedit.do" /></p> <p></ action></p> <p><action</p> <p>PATH = "/ deletecontact"</p> <p>TYPE = "com.ibm.sample.contacts.struts.action.deletecontactivity"</p> <p>Name = "ContactForm"</p> <p>Scope = "request"</p> <p>Validate = "false"></p> <p><forward</p> <p>Name = "mainditpage"</p> <p>Path = "/ main_edit.jsp" /></p> <p></ action></p> <p><action</p> <p>Path = "/ addcontact"</p> <p>TYPE = "com.ibm.sample.contacts.struts.action.addcontactivity"</p> <p>Name = "ContactForm"</p> <p>Scope = "request"</p> <p>Validate = "false"></p> <p><forward</p> <p>Name = "AddContactPage"</p> <p>PATH = "/ add_contact.jsp" /></p> <p></ action></p> <p></ action-mappings></p> <p><Controller</p> <p>Processorclass = "com.ibm.wps.ports.struts.wpsRequestProcessor"></p> <p></ controller></p> <p><message-resources</p> <p>Parameter = "com.ibm.sample.contacts.struts.nls.ApplicationResources" /></p> <p></ Struts-Config></p> <p>Listing 4. Help - /Web-inf/html/help/struts-config.xml</p> <p><? Xml Version = "1.0" encoding = "ISO-8859-1"?></p> <p><! DocType struts-config public</p> <p>"- // Apache Software Foundation // DTD Struts Configuration 1.1 // En"</p> <p>"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"></p> <p><struts-config></p> <p><action-mappings></p> <p></ action-mappings></p> <p><Controller</p> <p>Processorclass = "com.ibm.wps.ports.struts.wpsRequestProcessor"></p> <p></ controller></p> <p><message-resourcesparameter = "com.ibm.sample.contacts.struts.nls.applicationresources" /></p> <p></ Struts-Config></p> <p>Struts Verification - Validation.xml You have not used Struts input verification in this application. You can delete the default verification specification in Validation.xml.</p> <p><form-validation></p> <p></ form-validation></p> <p>Directory Structure Change reviews, you have changed the list of welcome files in the web.xml file. This list is used to indicate the starting point of the defined module. Depending on the root of the web application, you need to create a directory for the editing and help mode, and put the index.jsp.jsp of each mode in these directories.</p> <p>Each module's struts-config.xml file (indicating Portal mode) does not display additional path information of the JSP file; therefore, you need to add an appropriate JSP for the module in each of these same directory. In the / html / edit directory, you have add_contact.jsp, edit_contact.jsp, and main_edit.jsp, and index.jsp files. In the root directory, you have Detail_View.jsp and Main_View.jsp. In the / html / help directory, we only have index.jsp files.</p> <p>The implementation of the operation is next, you will implement the operations required for this application. Details of each class are not discussed here because of the full implementation of these classes in the download section. You need to implement class to extend org.apache.struts.Action.Apache.Struts.Action.Action that is identified in the status shift map and defined in the struts-config.xml file.</p> <p>Check the code of the DeleteContactAction class that implements the ability to delete the contact. You can also see an abstract class of our operation class extension, so you can put universal code for implementing all operations classes into it. For example, you can add a code to verify that the user is subject to wait before executing this feature.</p> <p>Listing 5. DeleteContactAction class</p> <p>Public class deletecontactivity extends postloginabstract {</p> <p>Public ActionForward PerformAction (ActionMapping Mapping, Actionform Form,</p> <p>User, httpservletRequest request, httpservletResponse response</p> <p>Throws exception {</p> <p>// Get the userid and successd OID</p> <p>String Userid = user.getuserid ();</p> <p>Contact Contact = (Contact) Form;</p> <p>String Oid = contact.getSelectedContact ();</p> <p>// delete the Contact</p> <p>ContactHelper ContactHelper = ContactHELPER.GETInstance ();</p> <p>ContactHelper.Deletecontact (Broker, UserID, OID);</p> <p>// render the main edit page</p> <p>Return (Mapping.Findforward (main_edit));</p> <p>}</p> <p>}</p> <p>Abstract operation class extension org.apache.struts.Action.Action and implementation method. This implementation ensures that the user is logged in, then calls the PerformAction method in the called operation class, transmitting the same parameters as the parameters of the user bean that have been transmitted to the execute method and the user bean retrieved during login verification. When you migrate your application to the Portal environment, you will only delete login operations and change this code to retrieve user objects from the portletRequest object. You can then change any application code to access the user object to use the WPS user object API. Listing 6. PostLoginabstractAction class</p> <p>Public Abstract Class AbstractActAction Extends Action Implements Constants {</p> <p>Public ActionForward Execute (ActionMapping Mapping, Actionform Form,</p> <p>HTTPSERVLETREQUEST REQUEST, HTTPSERVLETRESPONSE RESPONSE</p> <p>Throws exception {</p> <p>Try {</p> <p>// Initializations</p> <p>LOG = logfactory.getlog ("com.ibm.sample.contacts.struts.action");</p> <p>Bundle = ResourceBundle.getBundle (Resource, Request.getlocale ());</p> <p>// Initialize the Persistence Broker</p> <p>Broker = contactListBroker.getInstance ();</p> <p>IF (broker == null) {</p> <p>String persisttotb = getServlet (). GetInitParameter (DB);</p> <p>String DataSource = GetServlet (). GetinitParameter (Datasource);</p> <p>True.equalsignorecase (persisttoDB))</p> <p>ContactListdbroker.initialize (Datasource);</p> <p>Else</p> <p>ContactListMembroker.initialize ();</p> <p>Broker = contactListBroker.getInstance ();</p> <p>IF (log.Indebugenabled ())</p> <p>Log.debug ("Broker Initialized: Broker);</p> <p>}</p> <p>// Check for EXISTING WITH WITH Logged-in User</p> <p>HttpSession session = request.getations ();</p> <p>PortletRequest portletRequest = (portletRequest) Request;</p> <p>User = portletRequest.getuser ();</p> <p>IF (session == null || user == NULL)</p> <p>Throw new aimmessageexception (bundle.getstring);</p> <p>// Invoke the Action Class PerformAction Method</p> <p>Return PerformAction (Mapping, Form, User, Request, Response);</p> <p>} catch (exception e) {</p> <p>HttpSession session = request.getations ();</p> <p>Session.SetaTRibute (Exception, E); Return (Mapping.FindForward ("exception");</p> <p>}</p> <p>}</p> <p>Public Abstract ActionForward PerformAction (ActionMapping Mapping,</p> <p>Actionform Form, User User, HttpServletRequest Request,</p> <p>HttpservletResponse response) throws Exception;</p> <p>}</p> <p>The implementation of the remaining operations is very similar, and if this application has a minimum logic process, then they are not complex implementation.</p> <p>For example, in the DeleteContactAction class, some operation class uses the service of the persistence class. The Persistence method is provided as part of the download implementation. Now you can view the ContactListBroker interface, which defines the functions required for the contact list processing. Agent class's implementation management data storage (in this case, or representing the data in the database, or data for data in the data). This function is required by this portlet, but it doesn't matter to this point of this article, you can view the implementation of a specific agent in the Download Sector.</p> <p>Listing 7. ContactListBroker interface</p> <p>Public interface contactListBroker {</p> <p>/ **</p> <p>* Get the Contact Information Given a Contact Number</p> <p>* @Param Owner java.lang.string</p> <p>* @Param Contactoid java.lang.string</p> <p>* @Return ContactForm</p> <p>* /</p> <p>Public ContactForm getContact (String Owner, String Contactoid)</p> <p>THROWS AIMEXCEPTION;</p> <p>/ **</p> <p>* CREATE A Contact</p> <p>* @Param ContactForm</p> <p>* /</p> <p>Public void savecontact (Contact Contact)</p> <p>THROWS AIMEXCEPTION;</p> <p>/ **</p> <p>* Delete a Contact</p> <p>* @Param Owner java.lang.string</p> <p>* @Param Contactoid java.lang.string</p> <p>* /</p> <p>Public void deletecontact (String Owner, String Oid)</p> <p>THROWS AIMEXCEPTION;</p> <p>/ **</p> <p>* Get the contact list.</p> <p>* @Param Owner java.lang.string</p> <p>* @Return List of ContactForm Objects</p> <p>* /</p> <p>Public List GetContactList (String Owner)</p> <p>THROWS AIMEXCEPTION;</p> <p>}</p> <p>Application Bean We define two beans for this application. We define a contact form bean in the Struts-Config.xml file. It expands org.apache.struts.validator.validatorForm, and includes the characteristics of the column mapped to the contact database table (with accessor). See the part of setting up the database for our sample table definition. Another bean is a helper class that provides a common function to add and delete contacts. These codes are also available in the download, which is no longer displayed.</p> <p>The application resource defines the message feature file in the struts-config.xml file. Our file is named ApplicationResources.Properties, which is located in a resource folder. This resource package provides a displayed string in the package that makes the application easier to convert. The rest of the Java Server Page (JSP) file is the JavaTM Server Page (JSP) file. As you are defined in the struts-config.xml file, based on the status transfer graph, you need to implement 5 JSP to present a page for the following purposes:</p> <p>Add Contact Information Edit Contact Information Main View Page Editor Page (Main Edit Page) Contact Details View Page (Detail Contact View Page)</p> <p>You also need to update the index.jsp file to call the initialization operation for each mode.</p> <p>Examples of some critical parts of this JSP file, that is, the part of the part of the main view and the content presentation of this JSP. This JSP needs a bean that exists during a session contains a list of contacts. You define several standard Struts tag libraries used in JSP. When the user selects a contact in the presented list, you want to continue the DetailView operation, transfer the selected contact OID as a parameter to the request form data.</p> <p>Listing 8. Main view JSP</p> <p><% @ Taglib Uri = "/ Tags / Struts-Bean" prefix = "bean"%></p> <p><% @ Taglib URI = "/ Tags / Struts-HTML" prefix = "html"%></p> <p><% @ Taglib Uri = "/ Tags / Struts-Logic" prefix = "logic"%></p> <p><% @ Taglib Uri = "/ Tags / Struts-Portal-HTML" prefix = "portalhtml"%></p> <p><% @ Taglib Uri = "/ Web-INF / TLD / Portlet.tld" prefix = "portletApi"%></p> <p><JSP: Usebean ID = "ContactList" class = "java.util.list" scope = "session" /></p> <p><html: html locale = "true"></p> <p><table border = "0" width = "95%" align = "center" cellspacing = "0" cellpadding = "0"></p> <p><THEAD></p> <p><tr></p> <p><TD class = "wpstablehead"> <bean: message key = "contact.name" /> </ td></p> <p><TD class = "wpstablehead"> <bean: message key = "contact.company" /> </ td></p> <p><td class = "wpstablehead"> <bean: message key = "contact.email" /> </ td> <td class = "wpstablehead"> <bean: message key = "contact.mobile" /> </ td></p> <p></ TR></p> <p></ THEAD></p> <p><html: form method = "post" action = "/ detailview"></p> <p><html: hidden property = "selectedcontact" /></p> <p><logic: Iterate</p> <p>Name = "contactList" id = "acontact"</p> <p>TYPE = "com.ibm.sample.contacts.struts.beans.contact"></p> <p><tr></p> <p><TD class = "wpsportletsmtext" Valign = "TOP" align = "left"></p> <p><a style = "text-decoration: none; color: black;"</p> <p>OnMouseOver = "this.style.color = 'red'"</p> <p>OnMouseout = "this.style.color = '# 000000'"</p> <p>HREF = "JavaScript: Document. <portletAPI: EncodeNameSpace</p> <p>Value = 'contactform' />. SELECTEDCONTACT.VALUE =</p> <p>'<bean: write name = "acontact" property = "OID" />';</p> <p>Document. <portletAPI: EncodeNameSpace value =</p> <p>'ContactForm' />. Submit () "></p> <p><bean: write name = "acontact" property = "firstname" /></p> <p><bean: Write Name = "acontact" property = "lastname" /></p> <p></a></p> <p></ td></p> <p><TD class = "wpsportletsmtext" Valign = "TOP" align = "left"></p> <p><bean: Write Name = "acontact" property = "company" /></p> <p></ td></p> <p><TD class = "wpsportletsmtext" Valign = "TOP" align = "left"></p> <p><bean: Write Name = "acontact" property = "email" /></p> <p></ td></p> <p><TD class = "wpsportletsmtext" Valign = "TOP" align = "left"> <bean: write name = "acontact" Property = "Mobilephone" /></p> <p></ td></p> <p></ TR></p> <p></ logic: Iterate></p> <p></ html: form></p> <p></ TABLE></p> <p></ html: html></p> <p>Figure 4. Strong list view</p> <p>Setting up a database You can create two options for data persistence for this application: A database proxy implementation and the other with memory. To rapid development and testing, you may just want to use the form in memory because it does not require the steps of subsequent database settings. Of course, the data will be lost whenever the application server is restarted. The download section provides code for both proxy types (provided with the remaining parts of this sample application), the agent type is selected by the configuration parameters set in Web.xml through the web deployment descriptor file.</p> <p>However, if you choose to save the application data into the database, you need to create a database table first to store contact list data. To create the table, you need to run the following SQL commands from the command line to replace the SCHEMA name with the name you selected, but keep the specified table name. You can create a new database (data space) or add it to an existing database. If you use DB2, a connection to the appropriate database is established in the command center, then replicate the following command, and then run it.</p> <p>Create Table "DB2Admin". "Contacts" ("Owner" VARCHAR (64) Not NULL,</p> <p>"OID" VARCHAR (64) Not Null Primary Key, "first_name" varchar (32) Not null,</p> <p>"Last_name" VARCHAR (32) Not Null, "Email" varchar (128) Not null,</p> <p>"Title" VARCHAR (64), "Company" varchar (64), "bus_phone" varchar (32),</p> <p>"Mobile_phone" VARCHAR (32), "Fax_Phone" VARCHAR (32), "Web" varchar (128),</p> <p>"Address1" VARCHAR (32), "Address2" VARCHAR (32), "City" varchar (32),</p> <p>"State" VARCHAR (2), "ZIP" VARCHAR (10), "Country" VARCHAR (32))</p> <p>Now you can add an entry to your contact list database table so you can test it easier to develop portlets. You can perform the following SQL commands to create a new entry. If you want to log in to Portal for the purpose of the test, you can use this user ID to replace WPSADMIN in the following SQL declaration.</p> <p>Insert Into Contacts (Owner, Oid, First_Name, Last_Name, Email, Company,</p> <p>Mobile_phone) Values ​​('wpsadmin', '01', 'Tim', 'Hanis', 'Hanistt@us.ibm.com', 'IBM', '919-254-9072')</p> <p>Next, create a data source for the database where the contact table created in WebSphere Application Server creates a data source. This portlet is packaged as a J2EE 1.3 application, so you need to specify the Application Server V5 data source. J2EE Level 1.3 includes Servlet Specification Level 2.3 and JSP Specification Level 1.2.</p> <p>Use the DB2 Legacy CLI-BASED TYPE 2 JDBC DRIVER JDBC driver in Application Server and specify Data Sources instead of Data Sourcees (Version 4). On Application Server Administrative Console, select Resources => JDBC Providers. If you have already installed DB2 Legacy CLI-BASED TYPE 2 JDBC Driver, choose it. Otherwise, add it by selecting the New command and complete the next page. On the DB2 Legacy CLI-BASED TYPE 2 JDBC DRIVER page, make sure the class path is set to the correct location of the DB2JAVA.ZIP file. Select Data Sources and then select New to create a new V5 data source. Specify the name of the data source. For JNDI names, use the JDBC / sub-context as the prefix of the name. For example, if you want a data source JNDI name AIM, you can enter JDBC / AIM. The portlet is pre-considering the JDBC / sub context when performing a JNDI name. If your database requires a user ID and password for authentication, you specify an authentication alias in Component-Managed Authentication Alias. If you haven't defined an alias yet, you can create one in Security => JaaS Configuration => J2C Authentication Data. Make sure the configuration changes and test the data source connection.</p> <p>Figure 5. WebSphere Application Server Administrative Console</p> <p>Finally, create a data source for this same database in Application Developer. This is also required if you want to use Application Developer to test and debug this Struts application. Editing WebSphere Portal Server V5 Test Environment from the Application Developer Server perspective, select the Data Source tab in the Edit pane, add a DB2 Legacy CLI-BASED TYPE 2 JDBC DRIVER driver, and then add a V5 data source. Make sure you use JDBC / as a context prefix for your JNDI name. As in Application Server, you may need to add security verification alias (if you haven't created yet).</p> <p>Figure 6. Defining data sources</p> <p>Implementation Class Summary The following table lists the Java class implementation for implementing the sample application (which can be found in the download section) and a brief description of each class.</p> <p>Table 1. ConactsListportlet</p> <p>Package Description com.ibm.sample.contacts.struts.beanscontactHelper Assistant class, used to call persistence management functions for contacts to indicate contacts for contacts to contact Struts Forms.Sibm.Sample.Contacts.Struts.ActionAddContactAction Processing Add Contacts Information Request DeleteContactAction Processing DeleteContactAction Processing DetailViewAction Processing DetailViewAction Processing MODIFYACTION Processing Corresponding ContactAction Processing Corresponding Contact Part Control MAINEDITACTION Processing MAINEDITACTION Processing MAINEDITACTION Processing MAINVIEWACTION processing the display request of the main contact list view AbstractAction abstract class for persistent com.ibm.sample.contacts.struts.persistenceContactListBroker operation abstract class interface AbstractDBBroker ContactListDBBroker database agent for common functions implemented database agent that extends DbAbstractBroker ContactListBrokerContactListMemBroker implemented and implemented to achieve ContactListBroker of memory agent, com.ibm.sample.contacts.struts.utilitiesAIMException base exception class AIMWrapperException another package (basic) AIMExceptionAIMMessageException abnormal termination processing and sent user message abnormality constants constants defined application program interface com.ibm.sample.contacts.struts.nlsapplicationResources.properties The default resource package containing the print-print string ApplicationResources_en.properties contains a specific location-specific resource package that can print this article This article discusses how to use the Struts Portlet Framework implementation application. You know how to use the Struts module and how to use them with WebSphere Struts Portlet Framework to support multi Portal mode. The complete implementation of this example is provided in the download section below.</p> <p>Reference</p> <p>Portlet Development Guide - Second Edition WebSphere Portal V5 Info Center The Apache Struts Web Application Framework Struts in WebSphere Portal 4.1</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-88175.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="88175" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.040</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'cgxEf6trZp3pZbKy_2Ft361Op9yyp7sgo4U9XuXkOm32KFjq5xWVCGRvOjNy7iC_2FcsWfFTnEAFUg7_2BWV_2BWs71emw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>