This section provides a brief description of the Portlet API.
Overview Portlet Concept Portlet API Elements Core Objects Listener Configuration Objects Miscellaneous Object Portlet Event PortletService Deployment Descriptor
Overview
Portlets are a reusable component that can be provided to web-based content, applications, and other resource access. The web page can be accessed via the portlet, web services, applications, and Cindida content supply. Companies can create their own portlets or select Portlet from third-party portlet catalog. Portlet is intended to be assembled into a larger portal page, where multiple instances of the same portlet displays different data for each user.
From a user's point of view, Portlets are a window that provides specific services or information (eg, providing calendars and news) in the portal site. From an application developer's point of view, portlet is an insertable module that is designed to run in the portlet container of the portal server.
Portlet containers provide a runtime environment that instantiates, uses, and ultimately destroyed portlets in this environment. Portlets rely on the portal infrastructure to access user profile information, participate in the window and operational events, communicate with other portlets, access remote content, find credentials, and storage persistent data. Portlet API provides standard interfaces for these features. Portlet containers are not a stand-alone container similar to a servlet container. It is implemented as a thin layer on the servlet container and reuses the functions provided by the servlet container.
IBM is working with other companies to standardize the Portlet API, so that the portlet can be used in collaboration between portal servers implementing this specification. The portlet API provided in WebSphere Portal version 4.1 is the first step towards the Standling of Portlet API. For more information on portlet specification, see
http://jcp.org/jsr/detail/168.jsp
Portlet and Servlet API
Abstract portlet classes are the core abstraction of the Portlet API. Portlet class expands the HTTPSERVLET for the Servlet API. All portlets extend this abstract class indirectly, inheriting from httpservlet, as follows:
... - javax.servlet.http.httpservlet
|
- org.apache.jetspeed.portlet.portlet
|
- Org.apache.jetspeed.portlet.portletApterapter
|
- com.mycompany.myApplication.myportlet
Therefore, Portlet is a special type of servlet. This type of servlet features them easily inserted and run in the portal server. Unlike servlets, portlets cannot send redirects or errors directly to browsers, forward requests, or write any marked to output stream. The portlet container depends on the J2EE architecture implemented by the WebSphere Application Server. As a result, portlet is packaged in a way similar to J2EE Web applications and deployed in a way similar to servlet.
Generally speaking, the management of portlets is more dynamic than servlet. You can apply the following updates without starting and restarting the portal server:
You can use the portal to manage the user interface to install and remove portlet applications consisting of several portlets. The portlet settings can be changed by administrator changes with appropriate access You can use the management portlet to dynamically create and delete portlets. For example, once an administrator creates a new crop, cropping the portlet can be used to create a new portlet instance. The portlet container depends on the J2EE architecture implemented by the WebSphere Application Server. As a result, the portlet is packaged in the WAR file in a way similar to the J2EE web application and deployed in a way similar to servlet. Similar to other servlets, use the servlet deployment descriptor (web.xml) to define the portlet to the application server. This file defines the class file and read-only initialization parameters of the portlet.
The figure below shows the portlet after deploying its WAR file. Each portlet for deployment on the portal server is created on the application server, or a portlet class instance is created on the application server.
The initialization parameter is set by the portlet developer and can be read by the portletConfig object. The Servlet deployment descriptor can contain multiple web applications, each of which is defined by the
Portlet deployment descriptor
In addition to the servlet descriptor, Portlet must also provide portlet.xml to define the ability of portlets for portal servers. This information contains configuration parameters specific to specific portlets or portlet applications, as well as general information provided by all portlets (such as portlets supported by portlet). The portal server uses this information to serve the portlet. For example, if the portlet registers its support in the portlet deployment descriptor, the portal server will present the icon to allow the user to call the help and editing page of the portlet.
The following is a sample portlet deployment descriptor with minimal tag.
XML Version = "1.0" encoding = "UTF-8"?>
supports>
portlet>
portlet-app>
logage>
concrete-portlet>
concrete-portlet-app>
portlet-app-def>
To get more information that contains a description of each tag, see Deploying a descriptor.
Portlet concept
The following image shows that the portlet is placed on the page to place portlets and users access portlets. Note that the first two steps involve the use of persistent data, but for the third step, the data is only available during the session duration.
The portal administrator uses the management interface to deploy a new portlet application WAR file or install a copy of the portlet. Both operations create a concrete portlet, which is a portlet that is parameterized by a single portletSettings object. Each portlet may have multiple specific portlets. PortletSettings is a read / write access and is lasting. PortletSettings contains configuration parameters defined in the portlet deployment descriptor.
Using specific portlets can run instances of different configurations of many portlets without creating additional portlet class instances. Many specific portlets can be created and destroyed during the life cycle of a single portlet. None explicitly represents the object of the specific portlet. The same specific portlet can be shared between many users.
Users or administrators put portlets on the page. This creates a concrete portlet instance, which is a specific portlet that is parameterized by a single portletdata object. Each specific portlet may have a plurality of specific portlet instances. PortletData stores lasting information for portlets added to the page. For example, users can edit stock quotation portlets and save a list of stock symbols for company tracking.
The scope of the portletdata depends on the scope of the page where the specific portlet is located.
If the administrator places the specific portlet to the group page, the portletdata object contains data stored for the user. This will remain in the user group to view access to the page. However, if the user has an editing access to the portlet on the group page, create a new specific portlet instance for each user of the portlet. In this case, PortletData contains data for each user of the portlet. If the specific portlet is placed on the user's page, the portletdata contains the data of that user.
When the user accesses a page containing the portlet, a user portlet instance is created. When the user logs in to the portal, the portal server creates a portletSession for each user's portlet. PortletSession parameterized concrete portlet example is called a user portlet instance. Each specific portlet instance may have multiple user portlet instances. The user portlet instance is a specific portlet instance for a single portletSession parameterized. Each specific portlet instance may have multiple user portlet instances. PortletSession storage is instantaneous information related to a single use portlet.
Portlet application
The Portlet application provides a method of encapsulating a portlet that shares the same context. The context contains all resources, such as images, attribute files, and classes. All portlets must be encapsulated as part of the portlet application.
Specific portlet application
The specific portlet application is a portlet application that is parameterized by a single portletApplicationSettings object. For each portlet application, there may be multiple specific portlet applications. PortletApplicationSettings is a read / write access, and is lasting. None explicitly represents the object of the specific portlet application.
The specific portlet application contains at least a specific portlet from the portlet application, but no need to contain them.
Portlet applications do not provide code, but form a logical group for portlets. In addition to this more logical revenue, the portlet of the same portlet application can also exchange messages.
Portlet
Portlets allow portlets to display different user interfaces, depending on the tasks required for the portlet. Portlets have four display modes that are defined in the portlet deployment descriptor. The portlet container maintains the portlet mode in the portlet.mode object. Provides the following ways through the Portlet API:
view
When the portlet is initially built on the portal page, it is displayed in its view mode. This is the normal operation of the portlet.
help
If this method is supported by portlet, the portlet provides the user with a help page to get more information about portlets.
edit
If the way is supported by the portlet, the portlet provides the user to customize the portlet by itself. For example, Portlets provide a page to specify its location to obtain local weather and event information. Users must log in to the portal to access the edit method.
Configure
If the way is supported by portlet, the portlet provides a page for the portal administrator to configure portlets to the user or user group.
Portlet API provides a way to determine the current or previous way. All portlets must support view mode. Portlet containers provide users to interact with portlets on their portal page. Click one of the controls to change the way or status of the portlet. The portlet is displayed in the blank title bar in the view mode.
This title bar shows editing, help, minimizing, and maximizing icons. Click the pencil to make a portlet in edit.
Portlet status
The portlet state allows the user to change how the portlet window is displayed in the portal. In the browser, the user calls these status with icons in the title bar, which is the same as the operation method of the Windows application. The portlet status is maintained in the portletWindow.State object with the Boolean value.
When you first build a portlet on the portal page, it is displayed in normal status - arranged with other portlets on the page. When maximizing portlets, it is displayed as the entire body of the portal, replacing the view of the other portal. Minimize when minimizing portlets, only the portlet title bar on the portal page is displayed. Portlet API provides a way to the portlet to determine the current state.
Portlet API elements
This section describes the basic interfaces, classes, and methods of the Portlet API. The following figure shows the structural diagrams of many common objects in the portlet API.
Portlet extension by portletadapter
Service () 1 portletResponse
Createuri () portleturi service () 1 portletRequest
GetPortletSettings () portletsettings
GetletApplicationSettings PortletApplicationSettings getMode () portlet.mode getclient () Client getdata () portletdata getwindow () portletwindow
GetWindowState () portletwindow.state getPortletSession () portletsession getUser () user getPortletconfig () portletconfig
getContext () PortletContext
GetLog () PortletLog GetService () PortletService
1 PortletRequest and PortletResponse are passed by the Helper method of PortletAptaPter (such as Doview ()).
Portlet class
Abstract portlet classes are the core abstraction of the Portlet API. All portlet extends the abstraction class by extending one of the subclasses of abstract classes (eg, portletadapter), which provides methods that help developers.
Portlet life cycle
Portlet container calls the following method 2 of the abstract portlet during the lifecycle of the portlet:
init ()
After the portal is initialized, that is, the portlet is constructed and then initialized using the init () method. The portal always instantizes a single instance of the portlet, and this instance is shared between all users, exactly the same as the servlet shared between all users of the application server.
INITCONCRETE ()
After constructing the portlet, the specific portlet before the first visit to the portlet.
PortletSettings instantiates.
Service ()
When you ask portlets to present its content, the portal calls the service () method. The service () method is usually called multiple times during the life cycle of the portlet. For each portlet on the page, it is not called the service () method in the order of the guaranteed order, and may even call the service () method in different order for each request.
DestroyConcrete ()
Use the DestroyConcrete () method to remove the specific portlet from the service. This may happen when an administrator deletes a specific portlet during the running time of the portal server.
DESTROY ()
When the portal is about to terminate, the portlet will cancel the service and then use the destroy () method to destroy. Finally, the portlet is collected and ended as useless information.
2 This represents the method that is called on all portlets. Call other methods for the portlet of the listener. See the listener lifecycle for more information. getLastModified ()
In addition to the method called during the portlet lifecycle, the portlet container calls the getLastModified () method for each portlet request. This method returns the last time (in millisecond meter) of the change of the portlet content, this time is UTC in the current time and midnight on January 1, 1970 (java.lang.system.currentTimeMillis ()) or is negative (if time unknown). To get more information about when using getLastModified (), see Refresh the portlet cache.
Helper class
Portlets are not directly extending the abstract portlet class, but extended portletadapter or any other helper class to extend the portlet. Extend one of these classes to help protect portlets from abstract portlet class changes. In addition, it saves all methods of all portlet interfaces, even if portlet does not need to use them all. With the portletadapter class, simply override the truly needed approach.
In its service () method, the portletadapter class calls the method corresponding to the portlet. Extending the portlets of this class overwrites Doview (), doedit () and dohelp () methods without having to test the method or write a specific service () method.
In addition, portletadapter enables portlets to store variables in specific portlets. Specific portlet variables are different from Java instance variables because they are bound to the portlet class or a non-specific portlet. PortletApaater provides setvariable (), getVariable (), and RemoveVariable () methods and specific portlet variables.
Core object
The following objects are the most commonly used in portlet:
PortletRequest PortletResponse PortletSession
Each of these objects is an extension of its copy in the servlet API.
PortletRequest
PortletRequest objects are passed to portlets via login (), beginPage (), and provide specific data for portlets and allowing it to access further important information listed below.
Attributes
The attribute is the name / value pair related to the request. Attributes can only be used for the scope of the request. During a request, the portlet can get, set, and remove properties.
parameter
The parameter is a name / value pair sent by the client, which is part of the request in the URI query string. Usually the parameter is published from the form. The parameter is used for a scope of a particular request. Portlets can get the parameters from request acquisition but cannot set.
Client computer
Client objects encapsulates information about the user agent on a particular request. From
Client's information contains the tag types supported by the manufacturer or client of the user agent. Use the getClient () method from
PortletRequest extract
CLIENT. Can
Client Get the following information:
User agent
Portlets can get the string sent by the user agent to identify itself to the portal.
Tag name
Portlets can get a string that indicates the markup language supported by the client, such as "WML".
MIME type
Portlets get a string that indicates the MIME type supported by the client (eg
TEXT / VND.WAP.WML). If the portlet supports multiple device types, it will get the tag name instead of the MIME type. The following table shows the MIME type and their corresponding tag types. Retrieve the MIME type does not distinguish between HTML and ChTML tags. MIME Type Tag Type Text / HtmlHtmlText / VND.Wap.WmlWmlText / HTMLCHTML
ability
The Capability object is more detailed than the tag type (what is the level of the client supports), such as HTML, JavaScript, or WML table.
User data
PortletData object represents data for the specific portlet instance saved to lasting storage. For example, users can set up a portlet email application to check new messages every 30 minutes. in
The preferences are stored in the PortletData object.
Session
PortletSession represents instantaneous data of a specific user of multiple requests. With the request comparison, the request does not reserve the data after the request is complete, and the session property can be more than one request record / saved.
Portlet settings
PortletSettings object represents the configuration of the specific portlet saved to lasting storage. For example, an administrator can set which host and port should be connected to getting real-time data. in
The PortletSettings object stores this preference for the specific portlet.
the way
Portlet.Mode provides the current or previous portlet.
PortletWindow
PortletWindow object represents the current portlet window
status. Portlets can access the object to determine that the current portlet is to maximize, minimize or its normal view is rendered.
ModeModifier
Before presenting portlets, you can use this object to set the portlet to its current, previous or request. For example, a portlet in an edit mode can handle user operations and allow portlets to return to edit methods to wait for more inputs before returning a view mode.
PortletResponse
The response object package returns from the server to the client information. PortletResponse passes the BeginPage (), EndPage () and Service () methods and can be used by portlets to return to the portlet output by using Java PrintWriter. Responding to the method of creating a portleturi object or restricting the portlet tag using the namespace of the portlet.
Use one of the following methods to create portleturi:
Createuri ()
Create a call mode for the current way portlet
Portleturi object
Createuri (portletWindow.State
State)
Create a portlet that points to the call mode for the current mode and a given portlet window status
Portleturi object.
Createreturnuri ()
create
Portleturi pointing to the caller of portlet. For example, CreateReturnuri () can be used to create a postback button in the edit mode.
Each portlet runs in its own unique namespace. Portlets use the EncodeNameSpace () method to bring the property to the portlet output to avoid names with other portlet conflicts. The property contains parameter names, global variables, or JavaScript function names.
Portleturi
The portleturi object contains the URI to the portlet instance and can be further expanded by adding a specific portlet or by additional operations.
Operation is an activity of a particular portlet, but before calling the portlet service () method, it needs to be executed in the result of the inbound request. For example, when the user enters the data in the portlet editing method and click the Save button, the portlet needs to process the published data before generating the next tag. This can be implemented by adding the save operation to the URI of the representative save button. The complete URI can be converted to a string that can be embedded in the tag.
PortletSession
PortletSession Save the specific user data of the specific portlet instance of the portlet, create a portlet user instance. The specific portlet instances differ only in the data stored in their portletdata. The difference between the portlet user instance is only in instantaneous data stored in their portletations. Any persistent data must be stored using portletdata. Information stored in the instance variable of portlet is shared between all specific portlet instances (or even all specific portlets) through read and write access. Make sure that the instance properties are not used for user-specific data.
On the other hand, you must carefully treat the portlet to a session, especially if the portlet runs in a cluster environment, the environment is where the shared database serialization session. Anything stored in a session must also serialize.
Similar to httpsession, PortletSession is not available on anonymous page. During login, the portlets will be automatically created for each portlet on the page. To get portletSession, you must use the getSession () method (available in portletRequest). This method returns the current session, or if there is no current session, and given the parameter "CREAT" is True, it will create one and return it.
Listener
Portlet API provides a listener that adds more features to portlets. To enable the functions of the listener, the portlet must implement one of the following interfaces.
PortletSessionListener PortletpageListener PortletTitleListener PortletSettingSttributesListener PortletApplicationSettingSattributeSlistener
PortletSessionListener
In addition to the specific portlet instance of the portlet that appears on the page, the portlet may have a finer granularity. PortletSessionListener enables portlets to identify the lifecycle of the user portlet instance:
Login () After the user logs in to the portal, each portlet creates a session for the user. The specific portlet example and a combination of a user session creates a user portlet instance. The launch of the user instance is sent by the portal to call the login () method on the portlet. This method allows the portlet to initialize the user's PORLET session instance, for example, to store properties in a session. Logout () When the user ends a session with the portal, the portal server calls the logout () method to notify the portlet user's session instance is terminating. The portlet will then clear any resources of the portlet user instance.
Portletpagelistener
Portlets are not used to write control or consciousness of the output order of all portlets on the page. PortletPageListener allows the portlet to start and end insert tags on the page.
BeGinPage () Call the BeginPage () method for each portlet () method that resides on the page before the start of each page and any service () method of any portlet on the page. Similar to the service () method, each portlet on the page is not called the beGinPage () method in the promised sequence surface, and may even call the beGinPage () method for each request. This method allows the portlet to output JavaScript visible to all portlets, or even set cookies or headers. After EndPage () After the end of each page and the service () method of all portlets on the page, the endpage () method is called for each portlet on the page. Similar to the service () method, not the endpage () method is called in the order of the guaranteed order, and even for each request, the endpage () method is called in different order. For example, portlets can insert a JavaScript that needs to occur after all other elements of the page are written to the end of the page. Listener life cycle
When implementing portletSessionListener and portletpagelistener, the following methods are called on the portlet during the life cycle.
Init () non-specific portlets and portletconfig together initialize. INITCONCRETE () specific portlets and portletsettings are initialized together. Login () User Portlet instance is initialized together with PortletSession. BeginPage () portlet may start an output every page at each page of each request. Service () portlet may present an output in each requested portlet window. Endpage () portlet may present an output at each page of each request. Logout () destroys the user portlet instance. DestroyConcrete () destroys specific portlets. Destroy () destroys non-specific portlets.
PortlettittleListener
As shown in the title bar, the portlettitlelistener interface is used to allow a condition (for example, device type for accessing the portal) or user input (for example, the user who sets up on the edit page) to change the portlet title. If a listener is not implemented, the portlet is displayed on the
PortletSettingSattributeSlistener
This interface listens to the changes to the portletsettings attribute, similar to the Administrator to configure the specific portlet.
PortletApplicationSettingSattributeSlistener
This interface listens to changes to the portletApplicationSettings attribute, similar to the Administrator to configure the specific portlet application.
Configuration object
Portlets use the following objects to retrieve and store data, depending on how to use data:
PortletConfig PortletSettings PortletApplicationSettings Portletdata
PortletConfig
PortletConfig Configure its initialization to provide non-specific portlets. Configure information with the portlet class. This information takes effect for each specific portlet from portlet.
The PORTLE configuration first reads the descriptor from its Servlet deployment. This information is defined by the portlet developer. The configuration is read-only, and the portlet cannot be changed. Pass PortletConfig to the portlet in an abstract portlet's init () method and use GetInitParameters () to access specific portlet configuration parameters. The portletconfig parameter is the name / value pair available throughout the non-specific portlet lifecycle. The parameters of non-specific portlet are defined by the
PortletSettings
PortletSettings objects provide its dynamic configuration to the specific portlet. Configure information that has a specific portlet. This information is valid for each of the specific portlets of the specific portlet.
The specific portlet configuration is first read from the portlet deployment descriptor. This configuration is read-only and only when the portlet can be written by the portlet in the configuration mode. This information is usually maintained by the portal administrator and may be changed when the portal server is running. The portlet can get, set, and remove properties during a request. To submit changes, you must call the Store () method.
PortletSettings objects can be accessed by the getPortletSettings () method available for PortletRequest. Typically, it is used to use GetAttribute () to access specific portlet configuration parameters. The attribute is the name / value pair of the entire specific portlet lifecycle. The specific portlet attribute is defined by the
PortletApplicationSettings
PortletApplicationSettings object provides its dynamic configuration to the specific portlet application. Configure information about portlet applications that have all specific portlet shares included in the application.
The specific portlet application is first read from the portlet deployment descriptor. This configuration is read-only and only when the portlet can be written by the portlet in the configuration mode. This information is usually maintained by the portal administrator and may be changed when the portal server is running. During a request, the portlet in the application can get, set, and remove properties. To submit changes, you must call the Store () method.
PortletApplicationSettings can be accessed by the getApplicationSettings () method available by the PortletSettings object. It is used to use GetAttribute () to access specific portlet configuration parameters. The attribute is the name / value pair of the entire specific portlet application lifecycle. The specific portlet application properties are defined by the
Portletdata
PortletData has data for specific portlet instances. Each of the page has a specific portlet instance. PortletData contains persistent information about the specific portlet instance, while portletsSession only contains instantaneous data of the user portlet instance.
There is a specific portlet instance on each of the portlets on the page. The page can have a single user (personal home page) or a single user group (group page). PortletData contains specific user data on the Personal Home page, which contains specific group data on the group page.
The portletdata object stores the property as name / value pair. The portlet can get, set, and remove properties during a request. To submit changes, you must call the Store () method. The data is read-only and only when the portlet can be written by the portlet in editing mode. Miscellaneous object
The following objects are used by portlets:
PortletContext PortletLog PortletWindow User
PortletContext
The portletcontext interface defines the portlet view of each portlet container that runs in. PortletContext also allows portlet to access its available resources. For example, using context, portlets can access the portlet log, accessing the portlet to all portlets in the application, which is a common context parameter, get the URL reference to the resource, or access the portlet service.
A very important detailed information about PortletContext is described below.
INITPARAMETERS
The parameter is a name / value pair available in all portlets in the web application. These definitions under the
Attributes
The property is a name / value pair available in all portlets in the web application. Portlets can get, set, and remove properties. The context of the attribute is stored on a single machine and is not distributed in the cluster.
Localized text
The GetText () method is portlet to access the resource bundle in a given language environment.
Resource
by
PortletContext, portlet can be loaded or included in the portlet application scope. The available methods include include () and getResourceceAsStream (). Include () method is usually used to call JSP for the output.
Message delivery
Communication between portlets and shared data by message delivery, or sending notifications may be possible. Send messages by using the send () method. For more information, see
Portlet message delivery
Portlet service
PortletService object allows portlets to be insertable through dynamic discovery.
Log
PortletLog objects provide portlet logging information, warning, or error messages. The log is maintained by the portlet container. Enable or not enable the log log is determined by the portlet container. For more information, see
Message and tracking logs.
This object can also be obtained from getPortletLog () from the PortletApter class.
PortletWindow
PortletWindow object represents the window of the package portlet. For example, on an HTML page, the Portlet window can usually be rendered as a table unit. The portlet window can send events on its various window controls, such as the user clicks minimized or off. Portlets can ask the window in turn on its current state. For example, the portlet may exhibit its content differently, depending on whether it is maximized. PortletWindow is available using the getWindow () method of the portletRequest object.
User
The USER interface contains methods accessing user properties such as a full name of the user or username.
Portlet event
The portlet event contains information about events that may require a response. For example, an operating event will be generated when a user clicks on a link or button. To receive the notification of the event, the portlet must implement an event listener in the portlet class. Operating Event: Generate when the HTTP request is received by receiving the portlet container associated with the operation (such as when the user clicks on the link). Message Event: Generate when another portlet in the portlet application sends a message. Window event: Generate when the user changes the status of the portlet window.
Before generating new content requirements (and therefore portlet), the Portlet container sends all events to their respective event listeners. If the listener finds another event when the listener is processed, the event will be queued by the portlet container and transmitted at the moment of the portlet container. It is guaranteed to send it and happen before the content production phase.
Once the content is started, there will be no further events will be sent. For example, a message cannot be sent from BeGinPage (), service () and endpage (). The result message event will not be sent and substantially discarded.
Implement the event listener directly in the portlet class. The listener can access portletRequest from events and responses using the portletRequest or PortletSession property.
Operating event
When receiving the HTTP request associated with portletivity, send an ActionEvent to Portlet. To receive an operation event, the portlet class must implement an ActionListener interface and an object with the portletAction type. PortletAction links to the URI that uses the portleturi class and its addAction () method. ActionEvent can be used to get associated portletAction and portletRequest.
Typically, portletAction is linked to the HTTP reference or button in the HTML form. The ActionEvent that is then click the ActionEvent to transmit the associated portletAction back to the portlet, which can act in sequentially different processing paths based on user operation. Portlet operations can transmit any information. However, it should not store requests, response, or session objects. This information is part of the operational event and will be sent to the registered listener.
The following shows how JSP uses URIs, including portletAction. When the user clicks the "Add" button, a new HTTP request is sent to the operation URL of the form.