Write portlet

xiaoxiao2021-03-06  75

This section introduces you to the concept of creating portlets, starting with a simple portlet that completely modified. Use the section of the Portlet API and Javadoc as a reference.

Creating a simple portlet instance portlet sample set portlet development environment Hello World portlet Compile Java Source package and deploy portlet generation tag Use a persistent portlet message Pass message and track record log refresh portlet cache output parallel portlet Personalization portlet

If you are familiar with WebSphere Portal Family version 2.1 Product development portlet, you should be able to note that the Portlet API has made significant improvements. See migrating portlets for more information.

Create a simple portlet instance

WebSphere Portal includes the following predefined portlets that can be found in the WP_ROOT / Install directory.

Portlet file name file server portlet, providing a static HTML file fileserverportlet.warservlet call portlet, call servlet as a portlet, ServletInvoker.warjsp portlet, serve the JSPJSPSERVERPORTLET.WARCSV viewer, display data in a comma-separated value format arranged in formatted file csv.warrss portlet Display remote URLs that provide data using rich site summary format. Xslt.warocs viewer displays the "Open Content Cindida" channel supply. OcsViewer.war

These portlets provide basic functions (such as providing static HTML services or dynamic JSP file services), so you don't have to write code to your portal. You can create and deploy any number of instances of these portlets by using the management of the portal. See Portlet management for more information.

Serve static content using the portlet file server

The portlet file server displays any HTML files in its path to the portlet window. By default, it displays Test.html in the FILESERVERPORTLET / HTML directory at the WAR file. To other content services, you can add HTML files to the path to the Portlet file server and use portlet management to modify its URL parameter to a new file in the portal management. The root of the URL parameter points to the WAS_ROOT / InstalledApps / Portlet_ID.EAR / FILESERVER.WAR directory, the portlet_id is the unique identifier created in this directory. You can create multiple portlet instances, each of which serves different content from its respective path.

Portlet sample

A set of sample portlets, which demonstrate the functionality of the Portlet API. These portlets are provided by the Bookmark_Samplets.zip file in the wp_root / dev directory. These sample portlets contain the following files:

Bookmark0.war demonstrates how to get, set and remove a specific portlet. However, this portlet does not produce any output. Bookmark1.war Write output to the portal using PortletResponse. Bookmark2.war implements listeners (for example, inserting an HTML output before the portlet tag in the page). Bookmark3.war Retrieves parameters from portletconfig and retrieves properties from PortletData and PortletSetting. Bookmark4.war gets localized text from the resource bundle. Bookmark5.war contains JSP for viewing methods for portlets. Bookmark6.war contains JSPs for editing methods and implementing ActionListener so that users add bookmarks. The following sections describe how to create a simple Hello World portlet, as well as how to compile, package, and deploy this portlet. No file samples for Hello World; you must use the examples provided in text to create it. However, HelloWorld2.War provided in the WP_ROOT / DEV directory, which demonstrates how to use JSP to provide portlet tags.

Set the portlet development environment

Before trying to discuss any classes and samples discussed in this section, you should set an environment that makes written, compile, and test portlets more easily implement. WebSphere Portal product packages include the following development tools:

WebSphere Studio Application Developer version 4.02 supports e-commerce application terminals to the development, testing and deployment of the terminal. The Portal Toolbox Portal Toolbox is inserted into the Application Developer and provides a wizard to create a portlet application project and create a portletAdApter and MVCPortlet class, as well as a template-based portlet (servletinvokerport, jspportlet, and xsltport, jspportlet, and xsltport, JSPportlet, and xsltportlet). Make sure you set your system PATH environment variable to use JDK 1.3.0, which is JDK used by WebSphere Application Server. This JDK level is required to compile class files to use in portlets.

In addition to developing workstations, the portal server should be set to publish and test your portlet application project by installing the following components:

WebSphere Portal WebSphere Application Server - Advanced Edition, Single Server

Hello World Portlet

The Hello World Portlet provides an introduction to your first portlet. Hello World Extension AbstractPortlet Heliers Class and provides a minimum way for portlet. It uses PortletResponse to provide a simple output to the portal page.

Example: Hello World Portlet

Package com.ibm.wps.samples.helloworld;

Import org.apache.jetspeed.portlet. *;

Import org.apache.jetspeed.portlets. *;

Import java.io. *;

Public Class HelloWorld Extends Abstractportletlet

{

Public void init (portletconfig portletconfig) Throws unavailableException

{

Super.init (portletconfig);

}

Public Void Service (PortletRequest portletRequest, PortletResponse portletResponse)

Throws portletException, IOException

{

PrintWriter Writer = portletResponse.getwriter ();

Writer.println ("

Hello Portal World! ");

}

}

Compilation Java source code

Compile the JAVA source file using the JDK provided by WebSphere Application Server. Before compiling the Java source, set the ClassPath for the compiler to find the JAR file of any portlet package used by the portlet. The following JAR files should always be set in the ClassPath to compile:

WAS_ROOT / LIB / App / Portlet-Api.jar;

WAS_ROOT / LIB / APP / WPSPORTLETS.jar;

WAS_ROOT / LIB / APP / WPS.JAR;

Where WAS_ROOT is the installation directory of WebSphere Application Server. Also, if you need any classes of the servlet function, add the following:

WAS_ROOT / LIB / J2EE.JAR;

WAS_ROOT / LIB / WebSphere.jar;

Then, compile the portlet using the fully qualified path of the Java portlet source code.

Javac-ClassPath% classpath% com.ibm.wps.samples.Helloworld.java

To test the Hello World after compiling, you must first package it into a WAR file and install it to the portal server. However, the first step is to encapsulate the portlet into a JAR file format. To create a JAR file named helloWorld.jar, enter the following command:

Jar -cf helloworld.jar HelloWorld.class

See the JDK document for more information on JAR commands.

Package and deploy portlet

After completing the development and testing portlet, the portlet is ready to deploy to the portal server in the form of a web application archive or WAR file. You also need to package your portlet into a WAR file to test it in the portal server.

The WAR file format contains Java classes and resources that make up a single portlet. The resource can be an image, a JSP file, or an attribute file that contains a message text that is translated. In addition to portlet code and resources, the WAR file also includes web application deployment descriptors (web.xml) and portlet.xml, which contains the information required to install and configure portlets. Package the portlet class, resources, and descriptive information into a single file, making the distribution and deployment of portlet easier.

WebSphere Portal contains a management portlet for installation, uninstall, and updating portlets. The benefits of containing portlets in the WAR file can be dynamically downloaded and installed. The portal administrator can download the WAR file from the Internet and then use the portal management interface to install the portlet to WebSphere Portal. The portlet is ready for use, and does not need to restart the server.

To encapsulate the portlet in the WAR file, follow these steps:

Create a deployment descriptor. Press the WAR file directory structure to arrange the portlet file. Use the JAR utility to encapsulate files.

Hello World deployment descriptor

The following samples can be encapsulated with the Hello World Portlet. See Deploying descriptors for complete information about this topic.

Web application deployment descriptor:

"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">

Hello World Portlet Application - Portlet Sample # 1

HelloWorld

com.ibm.wps.samples.HelloWorld

HelloWorld

/ helloworld / *

Portlet deployment descriptor:

"portlet_1.1.dtd">

Hello World Portlet Application - Portlet Sample # 1

HelloWorld

0

no

Concrete Hello World Portlet Application - Portlet Sample # 1

portlet master

YourId@yourDomnain.com

HelloWorld

en

Hello World - Sample Portlet # 1 </ Title></p> <p><title-short> hello-world </ title-short></p> <p><Description> Hello World - Sample Portlet # 1 </ description></p> <p><keywords> Portlet Hello World </ keywords></p> <p></ logage></p> <p></ concrete-portlet></p> <p></ concrete-portlet-app></p> <p></ portlet-app-def></p> <p>WAR file directory structure</p> <p>Before encapsulating your portlet, you must arrange the class files and resources as described here. The portlet application exists as a structured directory hierarchy.</p> <p>/</p> <p>The root directory of the portlet file structure.</p> <p>/ images</p> <p>The location of any image required for portlet.</p> <p>/ Web-inf</p> <p>All positions of protected resources.</p> <p>The / web-inflicment is used to store the portlet descriptor documentation required by the package portlet, and the JAR files and classes that can be performed at all runtime.</p> <p>The portlet information directory is not part of the application utility document tree. The files residing in / web-infers are not directly serving clients.</p> <p>/ Web-INF / LIB</p> <p>Store the location of the portlet jar file.</p> <p>/ jsp</p> <p>The location of the JSP file.</p> <p>/ Web-inf / classes</p> <p>The location of the portlet class file. Individual class files should be stored</p> <p>/ WEB-INF / CLASSES is reflected in the directory structure of the class package. For example, packages</p> <p>Com.ibm.wps.samples.helloworld classification</p> <p>HelloWorld.class should be stored</p> <p>/Web-inf/classes/com/ibm/wps/samples/helloworld.class</p> <p>.</p> <p>/ META-INF</p> <p>The location of the Manifest file,</p> <p>MANIFEST.MF. Manifest is defined for the Java 1.3 specification in the standard JAR file format.</p> <p>The content in / meta-infers is not serving the client.</p> <p>Multilingual view selection</p> <p>WebSphere Portal supports the internationalization of portals and portlets. Those JSPs that contain most of the text (for example, help JSP) can be directly translated. This means that the text is included in the JSP instead of the resource bundle. For JSPs that do not use the resource bundle, you need to store it to the appropriate localization. When the portlet uses JSP to the output portlet, the portal will search and select the correct JSP based on the settings of the target browser and the target browser of the country or region. To use the portletcontext.include () function to include the JSP to portlet: getPortletConfig (). GetContext (). Include (Path, PortletRequest, portletResponse);</p> <p>To make the portlet, you must use the following directory structure to encapsulate the portlet's JSP to the WAR file:</p> <p>WEB-INF / JSP / MARKUP_TYPE / LANGUAGE _COUNTRY_VARIANT /JSPNAME.JSP</p> <p>among them:...</p> <p>path</p> <p>The path of the developer defines. Path can't be included</p> <p>MIME-TYPE /</p> <p>Language_</p> <p>Country_</p> <p>Variant. The include () method has positioned the correct JSP in these directories.</p> <p>Markup_type</p> <p>Yes</p> <p>HTML,</p> <p>WML or</p> <p>Chtml.</p> <p>Language</p> <p>Is a language of JSP, for example</p> <p>EN,</p> <p>JA or</p> <p>DE.</p> <p>COUNTRY</p> <p>Is a country or region of JSP, such as US, UK or CA.</p> <p>Variant</p> <p>It means different browsers, such as IE5 or NS4.</p> <p>For example, if the client is used by the language characteristics, the Internet Explorer 5, method includes include (/mypath/mytemplate.jsp, portletRequest, PortletResponse) Let the portal server look for JSPs in the following order.</p> <p>/html/mypath/ie5/EN_us/mytemplate.jsp /html/mypath/ie5/EN/MyTemplate.jsp /HTML/mypath/ie5/mytemplate.jsp /html/mypath/en_us/mytemplate.jsp / html / mypath / en /mytemplate.jsp /html/mypath/mytemplate.jsp /html/en_us/mytemplate.jsp /html/en/mytemplate.jsp / HtML/Mytemplate.jsp /mytemplate.jsp</p> <p>Pack portlet and resource into the WAR file</p> <p>Any JAR utility can be used to build a WAR file. Here's an example of how the JAR utility provided by WebSphere Application Server.</p> <p>To create a WAR file named mailportlet.par and contain all files in / web-inf and / images: jar -cf helloworld.war images Web-INF</p> <p>To update an existing WAR file helloworld.war: jar -uf helloworld.war Web-inf / portlet.xml</p> <p>To extract the portlet descriptor from the WAR file helloworld.war: jar -xf helloworld.war web-inf / portlet.xml</p> <p>To take all the files from the existing WAR file helloworld.war: jar -xf helloworld.war</p> <p>Once you have created a WAR file, you can press Portlet to install it to WebSphere Portal. To make portlet applications and complex portlets easy, XML access is a portlet configuration file called for installation. Use the portlet configuration file to allow the specified location and page to place your portlets, topics, and appearances, support tags, and clients, and other settings. This is especially useful for portlets that use messages because these portlets must be placed on the same page. To get more information about XML access, see the XML input and output and the representation of the XML Mural.</p> <p>Generate marker</p> <p>In the first example, Portlets provide tags using Java PrintWriter. Most tags are generated using JSP. When the portlet must transform the XML source, there is an exception. In this case, the portlet can use the XSLT to generate tags.</p> <p>Use JSP to generate tags</p> <p>One of the easiest ways to divide the portlet marker from the main function of portlet is to use JSP. Below is a JSP for editing pages for Hello World2 samples. Separated views or help JSP will exist to provide user interfaces to support additional portlets.</p> <p>There are a few considerations when writing your JSP:</p> <p>To keep the consistency of the portal appearance, use the portlet class specification in the style sheet of the portlet. Make sure to include the JSP tag library for WebSphere Portal to get the features you need to manage the namespace of your portlet. In addition, the request parameter name is set using the <portletAPI: EncodeNameSpace> tag. See Using the Portlet API tag to get more information. In this example, the Java String object is passed to the JSP from the DoedIt () method of the portlet. For more complex data transfer, you may need to create a separate object (data view bean or hash table) to include the data required.</p> <p>Example: JSP for editing methods for Hello World2</p> <p><% @ Taglib Uri = "/ Web-INF / TLD / Portlet.tld" prefix = "portletApi"%></p> <p><portletapi: init /></p> <p><jsp: usebean id = "saveuri" class = "java.lang.string" scope = "request" /></p> <p><JSP: usebean id = "ca ZENLURI" class = "java.lang.string" scope = "request" /></p> <p><JSP: usebean id = "username" class = "java.lang.string" scope = "request" /></p> <p><! - build table for edit screen -></p> <p><div class = "wpseditback"></p> <p><span class = "wpsedithead"> Configure Hello World portlet </ span> <br></p> <p><form method = "post" name = "form" action = "<% = saveuri%>"></p> <p><table width = "100%" cellspacing = "0" cellpadding = "0" border = "0"></p> <p><tr></p> <p><td align = "right" class = "wpsedittext"> Enter string to display: </ td></p> <p><TD> <Input Class = "WPSEDITFIELD" SIZE = "20" TYPE = "Text"</p> <p>Name = "<% = portletresponse.encodenamespace (" UserName ")%>"</p> <p>Value = <% = Username% >></p> <p></ td></p> <p></ TR></p> <p><! - EMPTY ROW -></p> <p><tr></p> <p><TD> </ td></p> <p></ TR></p> <p><tr></p> <p><TD Class = "WPSButtonTontext"></p> <p><Input Type = "Submit" name = "save" value = "save"></p> <p><Input Type = "Button" value = "ca Zancel"</p> <p>OnClick = "WINDOW.LOCATION.HREF = '<% = canceluri%>"> "></p> <p></ td></p> <p></ TR></p> <p></ table></p> <p></ form></p> <p></ div></p> <p>Generate tags for multiple devices</p> <p>One of the main features of WebSphere Portal is its support capabilities for multiple devices. WebSphere Portal supports PC browsers, I-MODE, and WAP phones, which will also support other device types in this product. The challenge to support a variety of devices is to output content in different ways according to the features of the browser. A browser accepts HTML 4.0; another acceptable WML; a WAP phone can display four lines of text, 25 characters per row; and another phone may have its own PDA-style interface.</p> <p>The following example demonstrates a method that selects the tag type associated with the current device before generating the portlet. DomarkUpOutput () method is provided, calling this method to handle the request for each portlet mode. The Client object acquired from PortletRequest identifies the tag language required for the current device.</p> <p>Example: Add method to handle different tags</p> <p>...</p> <p>{</p> <p>Public void init (portletconfig portletconfig) Throws unavailableException</p> <p>{</p> <p>Super.init (portletconfig); // Call Super to do further init</p> <p>}</p> <p>Public Void DoView (PortletRequest Request, PortletResponse Response)</p> <p>Throws portletException, IOException</p> <p>{</p> <p>DomarkupOutput (Request, Response, "View");</p> <p>}</p> <p>Public Void Dohelp (PortletRequest Request, PortletResponse Response) throws portletException, IOException</p> <p>{</p> <p>DomarkupOutput (Request, Response, "Help");</p> <p>}</p> <p>Public void doedit (PortletRequest Request, PortletResponse Response)</p> <p>Throws portletException, IOException</p> <p>{</p> <p>DomarkupOutput (Request, Response, "Edit");</p> <p>}</p> <p>Public void Domarkupoutput (PortletRequest Request,</p> <p>PortletResponse Response,</p> <p>String portletmodestring) throws portletException, IOException</p> <p>{</p> <p>String markup = Request.getClient (). GetMarkupname ();</p> <p>PrintWriter Writer = response.getwriter ();</p> <p>/ / -------------------------------------------------------------------------------------------- -------------------------------------</p> <p>// check the client device to determine the Type of Markup to generate</p> <p>/ / -------------------------------------------------------------------------------------------- -------------------------------------</p> <p>IF (Markup.Equalsignorecase ("HTML")) // Standard HTML: TEXT / HTML</p> <p>{</p> <p>Writer.println ("<p> Hello Portal ... The portlet mode is:" portletmodestring "</ p>");</p> <p>}</p> <p>Else IF (Markup.Equalsignorecase ("WML")) // WML: TEXT / WML</p> <p>{</p> <p>Writer.println ("<Card ID = /" Hello / "> <p> Hello Portal ...");</p> <p>Writer.println ("The portlet mode is:" portletmodestring "</ p> </ cound>");</p> <p>}</p> <p>Else IF ("chtml") // Compact HTML: Text / HTML</p> <p>{</p> <p>Writer.println ("<p> Hello Portal ... The portlet mode is:" portletmodestring "</ p>");</p> <p>}</p> <p>Else // Unrecognized Markup Type Error: throw an exception</p> <p>{</p> <p>New PortletException ("Unknown Markup Type");</p> <p>}</p> <p>}</p> <p>}</p> <p>Use the MVCPortlet class</p> <p>WebSphere Portal provides a part of the MVCPortlet class as part of the com.ibm.wps.portlets package. Extending the portlet of the class does not have to check the client tag before sending output. Instead, they provide controller classes for each tag type. The servlet class tag in the web application descriptor defines an empty debug file class that extends the MVCportlet. The controller class is defined as an initialization parameter, as shown in the following example. <servlet-class> com.mycompany.myportlet.mymvcportlet </ servlet-class></p> <p><init-param></p> <p><param-name> Controller.html </ param-name></p> <p><param-value> com.mycompany.myportlet.htmlController </ param-value></p> <p></ init-param></p> <p><init-param></p> <p><param-name> controller.wml </ param-name></p> <p><param-value> com.mycompany.myportlet.wmlcontroller </ param-value></p> <p></ init-param></p> <p><init-param></p> <p><param-name> Controller.chtml </ param-name></p> <p><param-value> com.mycompany.myportlet.chtmlController </ param-value></p> <p></ init-param></p> <p>Controller class extension AbstractPortletController and contains portlet code, such as doView (), doedit () method or ActionListener (if necessary). Application Developers allow you to create a MVCportlet from the Creative Portlet project wizard.</p> <p>Persistence</p> <p>Save, retrieve or delete portlet data to persistence portlet data using the portletdata object. The portlet can store the value in the portletdata object when the portlet is in an edit mode. If the portlet is on the group page, the information saved in PortletData is available for all portlet users. Portlet retrieves references to the portletdata instance by calling the GetData () method of the portletRequest object.</p> <p>In the example of Bookmarkportlet.java to Bookmark6.war, the SetAttribute () and Store () methods save the information to PortletData after the user enters the bookmarks on the edit page. However, first retrieve the user's URL_Count from portletdata to update URL_COUNT.</p> <p>Portletdata Data = Event.getRequest (). GetData ();</p> <p>String count = (string) data.getattribute (URL_COUNT);</p> <p>INT i = 0;</p> <p>IF (count! = null)</p> <p>{</p> <p>I = integer.parseint (count);</p> <p>}</p> <p>i ;</p> <p>Data.setttribute (Name_PREFIX I, NAME);</p> <p>Data.setttribute (URL_PREFIX I, URL);</p> <p>Data.setttribute (url_count, integer.tostring (i)); TRY</p> <p>{</p> <p>Data.Store ();</p> <p>}</p> <p>Catch (IOException E)</p> <p>{</p> <p>Throw new portletException (e);</p> <p>}</p> <p>Only Java String types can be saved to the portletdata object.</p> <p>Note: Portlets (before users log in) are located in the default portal page page cannot be accessed. To prevent undesired errors on the default page, notify the administrator not to contain this portlet on the default page, or test the availability of PortletData before attempting to access its properties.</p> <p>PortletData is also used in Hello World2 samples, enabling users to edit greetings and save them as persistent states. In addition, PortletContext is used to call JSP to output viewing and editing tags.</p> <p>The default greeting to display is obtained from a Web application deployment descriptor. The following demonstrates a descriptor that sets the initialization parameter defaulthellostring to "Hello!". Example: Hello World2 Web Application Descriptor</p> <p><? XML Version = "1.0" encoding = "UTF-8"?></p> <p><! DocType web-app</p> <p>PUBLIC "- // Sun microsystems, Inc.//dtd Web Application 2.2 // en"</p> <p>"http://java.sun.com/j2ee/dtds/web-app_2.2.dtd"></p> <p><web-app id = "WebApp_3"></p> <p><Display-name> Helloportlet </ display-name></p> <p><servlet ID = "servlet_1"></p> <p><servlet-name> Hello World2 </ servlet-name></p> <p><servlet-class> com.ibm.wps.samplets.helloWorld.HelloWorld2 </ servlet-clas></p> <p><init-param></p> <p><param-name> defaultHellostring </ param-name></p> <p><param-value> Hello! </ param-value></p> <p></ init-param></p> <p></ servlet></p> <p><servlet-mapping id = "servletmapping_1"></p> <p><servlet-name> Hello World2 </ servlet-name></p> <p><url-pattern> / hello world2 / * </ url-pattern></p> <p></ servlet-maping></p> <p></ web-app></p> <p><init-param> tag setting configuration data is read-only and derived for each user and the specific portlet maintenance of each portlet. If you need to allow each particular portlets to have different configurations, you should set data in the <concrete-portlet> tag of the portlet deployment descriptor. DOVIEW () method receives control before this portlet is displayed. Access the portletdata object to get the string to display. If the user has not specified the string to be displayed, the default string will be used. This string stores in the PortletRequest object, allowing it to generate JSP (ViewJSP) for this portlet. The doEdit () method receives control before the editing page is displayed for this portlet. A returned URI is created and passed to the editing method using the portletRequest object. The save operation is included in the Return URI to call an ActionListener for this portlet. The portal passes the control to the ActionListener when the save operation is processed. ActionListener can reserve "editing" information entered in the persistent memory. See Operating Events for more information on ActionListener and portlet. The code of the HelloActionListener is displayed as the following portlet code. Example: Save and retrieve data from portletconfig</p> <p>Package com.ibm.wps.samplets.helloworld;</p> <p>Import org.apache.jetspeed.portlet.defaultportletAction;</p> <p>Import org.apache.jetspeed.portlet. *;</p> <p>Import org.apache.jetspeed.portlet.event. *;</p> <p>Import org.apache.jetspeed.portlets. *;</p> <p>Import java.io. *;</p> <p>Import java.util. *;</p> <p>Public class helloworld2 extends abstractportlet loading informationListener {</p> <p>// Since there is a single instance of the portlet, only use instance variables, ONLY USE INSTANCE VARIABLES</p> <p>// for Immutable Values ​​That Are The Same for All Users of the portlet</p> <p>Private final static string viewjsp = "/web-inf/helloWorld/html/helloWorldView.jsp";</p> <p>Private final static string editjsp = "/web-inf/helloWorld/html/helloworldedit.jsp";</p> <p>PRIVATE STRING DEFAULTSTSTRING</p> <p>Public void init (portletconfig portletconfig) Throws unavailableException</p> <p>{</p> <p>Super.init (portletconfig);</p> <p>IF (getPortletLog (). IsDebugeNabled ()) {</p> <p>GetPortletLog (). Debug ("HelloWorld: Init Called);</p> <p>}</p> <p>// the default hello string is Obtained from the portlet configuration parameters</p> <p>DefaultString = PortletConfig.getinitParameter ("defaulthellostring");}</p> <p>Public Void DoView (PortletRequest Request, PortletResponse Response)</p> <p>Throws portletException, IOException</p> <p>{</p> <p>// Get the user's name to display from Persistent Storage</p> <p>PortletData portletdata = request.getdata ();</p> <p>String stringtodisplay = (string) portletdata.getattribute ("UserName");</p> <p>// if this is the first time the user has accessed this portlet, the</p> <p>// No Display String Will Be Found for this User In Persistent Storage</p> <p>IF (StringTodisplay == Null) {</p> <p>Stringtodisplay = defaultstring; // set default string</p> <p>}</p> <p>// add the display string to the portlet request to make it it it accessible by the view jsp</p> <p>Request.setattribute ("UserName", StringTodisplay;</p> <p>// Get a context for the capital session for invoking the jsp</p> <p>PortletContext Context = getPortletConfig (). GetContext ();</p> <p>Context.include (Viewjsp, Request, Response);</p> <p>}</p> <p>Public void doedit (PortletRequest portletRequest, PortletResponse portletResponse)</p> <p>Throws portletException, IOException</p> <p>{</p> <p>// Create the return uri for the edit page</p> <p>Portleturi Returnuri = portletResponse.createreeturnuri ();</p> <p>// Preserve the Cancel Uri in The Request to make it it accessible by The Edit JSP</p> <p>PortletRequest.setttribute ("Canceluri", Returnuri.toString ());</p> <p>// for the "save" Button The Return Uri Must Include The "Save" Action</p> <p>// so the action listener for this portlet will be invoked</p> <p>PortletAction SaveAction = New DefaultPortletAction ("save");</p> <p>Returnuri.Addction (SaveAction);</p> <p>// Preserve the Save Uri in The Request to make it it accessible by The Edit JSP</p> <p>PortletRequest.setttribute ("Saveuri", Returnuri.toTostring ()); // Get The user's name to display from Persistent Storage</p> <p>String stringtodisplay = (string) portletRequest.getdata (). GetAttribute ("UserName");</p> <p>IF (StringTodisplay == Null) {</p> <p>Stringtodisplay = defaultstring; // None Found, Set Default String</p> <p>}</p> <p>// add the display string to the request to make it it accessible by The Edit JSP</p> <p>// as an inital value of the input field on the Edit Form</p> <p>PortletRequest.setttribute ("UserName", StringTodisplay;</p> <p>// Get a context for the capital session for invoking the jsp</p> <p>PortletContext Context = getPortletConfig (). GetContext ();</p> <p>Context.includ (EditJSP, PortletRequest, PortletResponse);</p> <p>}</p> <p>Public void actionPerformed (ACTIONEvent Event) {</p> <p>DEFAULTPORTLETACTION Action = (DefaultportletAction) Event.getAction ();</p> <p>HelloWorld2 Helloportlet = (HelloWorld2) Event.getPortlet ();</p> <p>PortletLog log = helloportlet.getportletlog ();</p> <p>// if this is a save action, the see if the user specified a name</p> <p>IF (Action! = null) {</p> <p>IF (Action.getName (). Equals ("Save")) {</p> <p>PortletRequest Request = event.getRequest ();</p> <p>Portletdata portdata = request.getdata ();</p> <p>String Username = Request.getParameter ("UserName");</p> <p>Try {</p> <p>// save the name specified by the user</p> <p>IF (username! = NULL) {</p> <p>PortData.setttribute ("UserName", UserName;</p> <p>Portdata.store ();</p> <p>}</p> <p>} catch (accessdeniedException ad) {</p> <p>} catch (ioexception ie) {</p> <p>Log.Error ("<i> <b> couldn't Write the user Date to Persistence Because An I / O Error Occurred. </ b> </ i>");</p> <p>}</p> <p>}</p> <p>}</p> <p>}</p> <p>}</p> <p>As mentioned earlier, the Hello World2 Portlet implements an actionListener to handle the save operation. The user enters the name on the edit page, and the actionListener's actionPerformed () method obtains a string of a particular user from the portletRequest object to store the user's persistent memory. ActionListener is called before returning to the portlet, so if the user enters the name fails, ActionListener can force portlet to keep in editing, waiting for input from the user. Portlet message delivery</p> <p>Portlet API supports messaging between portlets on a page. For example, if four portlets (LEFT, RIGHT, TOP, BOTTOM) are part of the portlet application called Side, the portlet LEFT sends information to the portlet Right, TOP, and BOTTOM (as long as they are on the same page of the user). The following conditions are applied to the portlet of sending and receiving messages.</p> <p>Portlets must be on the same page. You can use XML access to the portlet application to create a portlet configuration file, which configures the portlet on the page within the installation time. Please refer to the portal configuration interface for more information. Portlets must be part of the same portlet application. This condition is only applied to portlets that implement the portletMessage interface. The portlet of the extension DefaultPortletMessage does not have to be a member of the same portlet application. Portlets deployed as a Web service cannot send and receive messages.</p> <p>Typically, the message is sent from the portlet's operation listener and is received by another portlet message listener. The user performs operations in a portlet. Capture and handle operational events. According to this result, the portlet can send the message to other portlets using the Send () method of the portletContext object.</p> <p>Example: ActionListener sent by sending a message</p> <p>...</p> <p>Public void actionPerformed (ACTIONEvent Event) {</p> <p>...</p> <p>IF (action.getname (). Equals ("browse")) {</p> <p>Log.debug ("BookmarkActionListener - Browse Action";</p> <p>String URL = (String) action.getParameters (). Get ("URL");</p> <p>Log.debug ("BookmarkPortletActionListener - Opening Link:" URL);</p> <p>...</p> <p>Try {</p> <p>Portlet.getConfig (). getContext (). Send (Null, New DefaultPortletMessage (URL));</p> <p>}</p> <p>Catch (AccessdeniedException ADE) {</p> <p>Log.Error ("BookmarkportletActionListener - Unable to send message /" url = " url " / "- accessdenated");</p> <p>}</p> <p>}</p> <p>...</p> <p>}</p> <p>In this sample, "Browse" operation has been defined in the bookmark portlet.</p> <p>DefaultPortletAction BrowseAction = new org.apache.compeed.portlets.defaultportletAction ("browse"); browseaction.addparameter ("URL", URL);</p> <p>Portleturi portleturi = response.createreturnuri ();</p> <p>Portleturi.Addaction;</p> <p>String actionuri = portleturi.toString ();</p> <p>The Send () method uses the following own variables:</p> <p>Portletname</p> <p>Receive the requested portlet name. In the above example, send the message to</p> <p>Null, which means it broadcasts all portlets in the same portlet application. To send a message to a specific portlet, specify the name of the portlet, just as defined in the <portlet-name> tag in the portlet deployment descriptor.</p> <p>news</p> <p>The message to send. Message must be the interface</p> <p>PortletMessage object or any subclass. In the above example, the message is</p> <p>DEFAULTPORTLETMESSAGE object exemplifies, containing</p> <p>URL string.</p> <p>The portlet received has a message listener that retrieves the message using the getMessage () method of the message event.</p> <p>Example: Messagelistener, received message</p> <p>Public void MessageReceived (MessageEvent Event)</p> <p>Throws portletException</p> <p>{</p> <p>PortletMessage Msg = event.getMessage ();</p> <p>IF (MSG InstanceOf DefaultPortletMessage) {</p> <p>String Url = (DefaultportletMessage) msg) .getText ();</p> <p>PortletApterapter portlet = (portletadapter) Event.getPortlet ();</p> <p>Portlet.getPortletLog (). Debug ("BookmarkPortletMessageListener MessageReceiVed";</p> <p>PortletRequest Request = event.getRequest ();</p> <p>PortletSession session = request.getations ();</p> <p>Session.SetAttribute ("URL", URL);</p> <p>}</p> <p>}</p> <p>}</p> <p>Since MessageListener sets the received message as a session attribute, the portlet that is receiving must obtain the "URL" parameter from the session.</p> <p>For more information on operating events and message events, see the portlet event.</p> <p>Message and track record log</p> <p>Portlets can write messages and tracking information to log files, which maintained in WP_ROOT / LOG / directory. The log file helps the portal administrator review portlet errors and special circumstances and helps the portlet developer test and debug portlet. Portlet API provides a PortletLog class, which writes messages and tracking information to logs:</p> <p>Debug ()</p> <p>Write track information to</p> <p>WPS_ [TimeStamp] .log.</p> <p>INFO ()</p> <p>Write the information news</p> <p>WPS_ [TimeStamp] .log.</p> <p>Error ()</p> <p>Write the error message</p> <p>WPS_ [TimeStamp] .log.</p> <p>Warn ()</p> <p>Write a warning message</p> <p>WPS_ [TimeStamp] .log.</p> <p>[TimeStamp] format is as follows: Year.Month.date-Hour.minute.second</p> <p>For example: WPS_2002.03.08-14.00.00.log is written at 2:00 pm March 8, 2002.</p> <p>If you have access to the portlet log multiple times in a method, it is recommended to specify the log reference to the variable, for example:</p> <p>Private portletlog mylogref = getPortletLog ();</p> <p>Since the log operation is high, PortletLog provides a way to determine if the log is enabled for a given level. Your portlet is written to a given level only when the log is tracking the level of message. E.g:</p> <p>IF (getPortletLog (). IsdebugeNabled ())</p> <p>{</p> <p>MYLOGREF.DEBUG ("Warning, Portlet Resources Are Low!");</p> <p>}</p> <p>To get more information about logs in WebSphere Portal, see Log Management.</p> <p>Refresh portlet cache</p> <p>Portlet cache keeps the full output of the portlet. As a result, when the user changes the portlet state, the portal server does not call the portlet's service () or DOVIEW () method. When the cache entry of the current portlet should be invalid, the getLastModified () method makes the portlet developer to notify the container, so you should refresh the content of the portlet. You can use WindowListeners to set up new timestamps and return timestamp in GetLastModified. The following example shows the part of the bookmark portlet that the bookmark caches its output, but if the window status is changed to provide other output, you will need to change its content immediately.</p> <p>First, in the portlet deployment descriptor, register the WindowListener and the supported portlet status and enable cache.</p> <p>GetLastModified () sample: portlet deployment descriptor</p> <p><listener></p> <p><listener-class type = "window"></p> <p>com.mycompany.portlets.bookmark.bookmarkportletwindowlistener</p> <p></ listener-class></p> <p></ listener></p> <p><cache></p> <p><expires> -1 </ expires></p> <p><shared> no </ shared></p> <p></ cache></p> <p><allows></p> <p><maximized /></p> <p><minimized /></p> <p></ allows></p> <p>Next, WindowListener sets timestamp for the Last_Modified property for the portlet session.</p> <p>GetLastModified () Example: WindowListener</p> <p>Package com.mycompany.portlets.bookmark;</p> <p>Import org.apache.jetspeed.portlets. *;</p> <p>Import org.apache.jetspeed.portlet. *;</p> <p>Import org.apache.jetspeed.portlet.event. *;</p> <p>Import java.io.ioException; // java stuff</p> <p>Public Class BookmarkportletWindowListener Extends WINDOWADAPTER {</p> <p>Public Void WindowMaximized (WindowEvent Event) THROWS portleTexception</p> <p>{</p> <p>SetLastModified (Event);</p> <p>}</p> <p>Public void windowRestored (WindowEvent Event) Throws portletException</p> <p>{</p> <p>SetLastModified (Event);</p> <p>}</p> <p>Private void setlastmodified (windowevent event) {</p> <p>PortletSession session = event.getRequest (). Getsession (false);</p> <p>IF (session! = null) {</p> <p>Session.SetaTRibute (Bookmarkportlet.last_modified, new long (system.currenttimemillis);</p> <p>}</p> <p>}</p> <p>Public void windowdetached (WindowEvent Event) throws portletException</p> <p>{</p> <p>}</p> <p>}</p> <p>Finally, when a request is issued, the GetLastModified () method of the portlet returns the timestamp.</p> <p>GetlastModified () example: Bookmarkportlet</p> <p>Public long getlastmodified (portletRequest request) {</p> <p>PortletSession session = request.getsession (false);</p> <p>IF (session! = null) {</p> <p>Long lastmodified = (long) session.getattribute (Last_Modified);</p> <p>IF (LastModified! = null) {</p> <p>Return LastModified.longValue ();</p> <p>}</p> <p>}</p> <p>Return -1;</p> <p>}</p> <p>Output parallel portlet</p> <p>By default, the portal server outputs into the portlet to the page (using separate processing thread). Administrators can set a certain number of threads or off the capability for portlet output, making it possible to use single-threaded serial output portlets. These settings are in the JetSpeedResources.properties file. See Managing portlets in the portal parallel output for more information.</p> <p>Also set portlet output at the portlet level, which is off. To set parallel portlets for the portlet, set the configuration parameters in the <Concrete-Portlet> tag of the portlet deployment descriptor.</p> <p><config-param></p> <p><param-name> Parallel </ param-name></p> <p><param-value> True </ param-value></p> <p></ config-param></p> <p>Setting this parameter in portlet.xml to help administrators avoid setting up the portlet.</p> <p>Personalized portlet</p> <p>WebSphere Personalization enables customers to easily build a Web site, so that the site content matches site visits. Although customization allows users to set their own preferences or determine what content, portal vendors (developers, administrators) use personalization to determine what is displayed based on user characteristics.</p> <p>All personalized solutions have user concept, content, and matching technology. WebSphere Portal provides user concept, which is implemented as a User class with user profiles. For each installed portal content is specific and can include customer data storage, old database, subscription content providers, and others. For matching technologies, WebSphere Personzalization provides a rule-based personalized resource engine and rule engine. Combined with these components allow you to develop portlets with personalized rules that match users. Consider an example of an internal web portal for purchasing office supplies. More than $ 50 orders must be approved by the manager. When the portlet user is a manager, the portlet needs to display a button that launches the approved form. In this case, the button can be added to the view JSP of the portlet as the content point. The content point is where you want to display a web page of personalized content. Then create the rules that map this point to the portlet user, for example:</p> <p>When the user is a manager, the approve button is displayed.</p> <p>WebSphere Studio Application Developer V4.03 is used to create content points in the Portlet JSP. The Personalization workspace is used to develop rules that display content in the user-characteristic-based point. About using a more detailed description developed by personalized portlet, you can find it in the WP_ROOT / DEV directory of the portal server.</p> <p>Related Information</p> <p>Portal configuration log management change appearance</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-93139.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="93139" 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.033</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 = '3wg3kVGaF4dhnCUTamKn93Kk08_2BfuIzOCy_2BS_2F27ygmieJv7MtZMkj_2BofekX_2FmBphnXVKE6d3ZGs4oXafVBPXVQ_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>