eric-1001c

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  3 随笔 :: 45 文章 :: 12 评论 :: 0 Trackbacks

1.Number of portlet instances

For a single system which is not clustered, there is only one portlet object per portlet definition. In a clustered environment
(marked distributable in the web.xml), only one portlet object will be instantiate per portlet definition per VM


2.Portlet windows

The portlets may contain preferences and default values. These values are used to create the PortletPreferences object.The portlet entity has the PortletPreferences attached to it.Administrators can globally change the parameters while in Config mode. The changes will affect all of the portlet instances on all pages. If a user modifies a portletPreference, it will only affect their PortletPreferences object.



3.Thread safety

The PortletRequest and PortletResponse objects are not guaranteed to be thread safe. These object should only be used in the scope of the processAction and render methods. You should not reference the PortletRequest or PortletResponse in any object outside these methods. If the request handling methods modify class variables, these variables will also be modified for all instances of the portlet. This can cause unexpected problems in your portlets that are difficult to debug. Use method local variables to avoid this problem.

4.JSR 168 comparison to servlets

The JSP 168 API does not extend or implement any of the Servlet classes or interface. However, JSR 168 portlets are modeled after the servlet specification. Portlets therefore cannot set character set encoding for the response. They also cannot set HTTP header responses.This allows the ServletContext and the PortletContext to share attributes. This also allows the HttpSession to share attributes with the PortletSession. The opposite is true also, the PortletSession can share attributes with the HttpSsession.


5.JSR168 portlet modes

JSR 168 supports three modes,View, Edit, and Help. JSR 168 also supports custom modes. IBM WebSphere Portal at the time of this writing only supports the custom mode Configuration.
 * Custome-portlet-mode: Configuration mode is used to globally update a portlet configuration. In Configuration mode an administrator can update the read-only ortletPreferences. Changes are reflected in all occurrences of the portlet on all pages. The doDispatch() method of the GenericPortlet class needs to be overridden to handle this custom mode.


6.JSR 168 Porlet window states

Like portlet mode the Window state can be programmatically changed in processAction() while processing an action request. The state can also be requested while creating a render or action URL.

7.Core JSR 168 objects

7.1 Portlet

 * void destory()
 * void init(PortletConfig config): requests
. The init is called only once per portlet object and should be used to load any expensive resources (such

as database connections). A unique PortletConfig object is passed into the init method. This PortletConfig object is per portlet definition. You can

gain access to the initialization parameters and the resource bundles from the PortletConfig object. You can also get the PortletContext from the

PortletConfig. The PortletContext will provide information about the portlet's runtime environment.
 * void processAction(ActionRequest request, ActionResponse response): The processAction method is called in response to an action request. URLs

generated by the portlet using RenderResponse.createActionURL() or the ActionURL JSP tag will generate an action URL causing this method to be

invoked. This method should be used to update the portlets state based on the action request parameters.The ActionRequest provides access to the

parameters, window state, portlet mode, portlet context, portlet session and the PortletPreferences object. Changes to the window state and mode are

made through the ActionResponse object;
 * void render(RenderRequest request, RenderResponse response): The RenderRequest does not have access to the parameters passed into the ActionRequest unless they have been explicitly added during the action request using the ActionResponse.setRenderParameter() method.The RenderResponse is used to display content, it can either use the RenderResponse Writer or it can delegate to a JSP or Servlet using the PortletRequestDispatcher.



7.2 GenericPortlet

 * String getInitParameter(String name)
 * Enumeration getInitParameterNames(): Returns all the initialization parameters names in an Enumeration of Strings.
 * PortletContext getPortletContext():
 * String getName(): Returns the name of the portlet defined by either the administrator or the application deployment descriptor.
 * ResourceBundle getResourceBundle(Locale locale): Portlets may define basic information to be used in the title bar. This information may include title, short-title and keywords. This information can be added directly in the portlet deployment descriptor or it may be added in an external ResourceBundle. If this information is located in an external ResourceBundle, the portlet deployment descriptor must provide the name of the ResourceBundle.Portal will search the values in the ResourcesBundle first and then it will look for the resources inline. If the resource cannot be found, an empty String will be returned.
 *void doDispatch(RenderRequest request, RenderResponseresponse) : The doDispatch method is called from the render method.The doDispatch will determine the portlet mode and invoke the correct method. If using a custom mode, you should override the doDispatch method to test for your custom mode.If the request is not for your custom mode invoke super.doDispatch to allow GenericPortlet do dispatch the correct method.
 * void doEdit(RenderRequest request, RenderResponseresponse): When the portlet mode is Edit, the doEdit method will be invoked by doDispatch.
 * void doHelp(RenderRequest request, RenderResponseresponse): When the portlet mode is Help, the doHelp method will be invoked by doDispatch.
 * void doView(RenderRequest request, RenderResponse response): like as doHelp();
 * PortletConfig getPortletConfig()
 * String getPortletName()
 * String getTitle(RenderRequest request)
 *void processAction(ActionRequest reqeust, ActionResponse response): The processAction method is invoked for all action requests for the portlet.
 * void render(RenderRequest request, RenderResponse response): The render method sets the portlet title and then invokes the doDispatch() method.



7.3 PortletURL

PortletURLs: action URL and RenderURL. By using the RenderResponse.createActionURL, RenderResponse.createRenderURL or the JSP tags, the portlet developer can create the different types of URLs. When a render URL is encountered, the render method is invoked and it turn invokes the appropriate doXXX method. When an action URL is encountered, the processAction method is invoked. Only action URLs should be used for forms. Render and Action parameters are different. Parameters set for an action URL (parameters in an HTML form) are not available to the render method unless they are explicitly added using the setRenderParameter of the ActionResponse class.
 * void setParameter(String name, String value)
 * void setParameter(String name, String[] values)
 * void setParameters(Map parameters)
 * void setPortletMode(PortletMode portletMode)
 * void setWindowState(WindowState windowState)
 * void String toString()
 * void setSecure(boolean secure)

7.4 PortletContext

The PortletContext provides the portlet with information about the portlet application that it is running in. If the portlet application is not in a distributed environment, there is nly once PortletContext object instantiated for each portlet application deployed. If the application is in a distributed environment (marked distributable in the web.xml) then there will be one instance per JVM.
The following methods of the PortletContext class will have the sameimplementation as the ServletContex:
 getAttribute
 getAttributeNames
 getInitParameter
 getInitParameternames
 getMimeType
 getRealPath
 getResource
 getResourcePaths
 getResourceAsStream
 log
 removeAttribute
 setAttribute

7.5 PortletRequest

 The portlet request object will contain information about the client request. The request will also include parameters, the portlet mode, the window state, session, and access to the portlat context. PortletRequest defines commonly used functionality for ActionRequest and RenderRequest.
 * String getParameter(java.lang.String name)
 * Enumeration getParameterNames()
 * String[] getParameterValues(java.lang.String name)
 * Map getParameterMap()
 * void setAttribute(java.lang.String name, java.lang.Objectvalue)
 * Object getAttribute(java.lang.String name)
 * void removeAttribute(java.lang.String name)
 * Enumeration getAttributeNames()
 * java.lang.String getContextPath():
The path returned starts with ‘/’ character but it does not end with a ‘/’. This method should be used when including resources such as images<%= portletResponse.encodeURL(renderRequest.getContextPath() + "/images/myImage.jpg") %>
 * boolean isPortletModeAllowed(PortletMode mode): This method will true if the mode is defined in the portlet deployment descriptor. If the mode is

not defined it will return false.
 * PortletMode getPortletMode(): This method will return the current portlet mode.
 * boolean isWindowStateAllowed(WindowState state): If the window state is defined in the deployment descriptor this will return true, else it will return false.
 * WindowState getWindowState()
 * String getProperty(java.lang.String name)
 * Enumeration getProperties(java.lang.String name)
 * Enumeration getPropertyNames()
 * String getRemoteUser()
 * boolean isUserInRole(java.lang.String role)
 * javax.security.Principal getUserPrincipal():
Returns the Principal object of the current user who is logged in. If security is not enabled, this method will always returns null.

7.6 ActionRequest

The ActionRequest interface extends the PortletRequest interface and is used during an action request. The ActionRequest object is passed into the processAction method. he ActionRequest object is in scope only during execution of the processAction method.
* BufferedReader getReader(): This returns a BufferedReader containing the body of the HTTP request as character data. The character data returned will be of the same type as the character encoding of the body. If the character encoding is not supported, an UnsupportedEncodingException will be thrown.
 * InputStream getPortletInputStream(): An InputStream containing the HTTP request body in the form of binary data will be returned.When the data is of type application/x-www-form-urlencoded, portal has already processed the form and the parameters will be available via request parameters. An IllegalStateException will be thrown if the data is of type application/x-www-form-urlencoded.Either the getPortletInputStream or the getReader may be called for the ActionRequest object but not both. If the getreader has been called, an ensuing call to getPortletInputStream will throw an IllegalStateException.
 * String getContentType()
 * String getCharacterEncoding()
 * void setCharacterEncoding(String enc):
This method will set the character encoding for the returned input of the getReader method. This must be called before the call to getReader. An UnsupportedEncodingException is thrown if the encoding passed in is unsupported or unknown. An IllegalStateException will be thrown if this method is called after getReader().
 * int getContentLength()



7.7 RenderRequest

The RenderRequest interface extends the PortletRequest. The RenderRequest does not define any additional functionality. The RenderRequest object is scoped to the render method.

posted on 2008-03-02 20:05 Eric-1001c 阅读(344) 评论(0)  编辑  收藏 所属分类: Websphere Portal

只有注册用户登录后才能发表评论。


网站导航: