Sie sind auf Seite 1von 27

Using J SR 168 for Portlet

Rosario Iannella

JSR168 Concepts
Rosario Iannella

30/11/2009
Agenda

§ Part I: JSR 168 Specification


§ Part II: JSR168 and the MVC Pattern
§ Part III: Spring MVC Portet
§ Part IV: Pattern - Builder
§

2 11/30/09
A
A portlet
portal is
portletis aa web
Javabased
container technology based
runs application
portlets andthatweb–commonly-
component,
provides managed
provides
them with by a runtime
portlet container,
personalization,
the required single that
environment.
processes
sign on, ……
A portlet requests and
A portal
container generates
may
containshave dynamic
sophisticated
portlets and manages content. Portlets
personalization
their are used to
features
lifecycle. by portals as pluggable
provide
user
It also Part I: JSR 168 Specification
customized
interface
provides contentstorage
components
persistent to users
that provide a presentation
for. [PLT.2.1]
portlet layer
preferences. to Information
A portlet Systems.
container receives[PLT.2.2]
requests
from the portal to execute requests on the portlets hosted by it. 30 [PLT.2.3]

Portal Definition
§
§

Portlet Container

Portlet

3 11/30/09
Part I: JSR 168 Specification

Portlet vs. Servlet


Only generates markup fragments, not complete Usually controls the entire page
documents
Interacts only through a portal system Not required
A more refined request handling, action requests Only httpRequest
and render requests
Predefined modes and window states that indicate No
the function the component is performing and the
amount of real state in the portal page
Exists many times in a portal page No
Accesses to user profile information No
Accesses and stores persistent configuration and No
customization data
No Setting the character set encoding of the response
No Setting HTTP headers on the response

No The URL of the client

4 11/30/09
Part I: JSR 168 Specification

§ Significant Types:

• PortletConfig
• PortletContext
• PortalContext
• Portlet
• PortletSession

5 11/30/09
Part I: JSR 168 Specification

Portlet Config:

The PortletConfig object provides the portlet object with information to


be used during initialization. It also provides access to the portlet context
and the resource bundle that provides title-bar resources.[PLT 6]

•One per portlet definition


•Access to the portlet init parameter
•Resource Bundle

6 11/30/09
Part I: JSR 168 Specification

PortletContext:

Defines a set of methods that a portlet uses to communicate with its


portlet container and defines the portlet’s view of the portlet application
within which the portlet is running.

•One context instance per portlet-app per JVM.


•Access to Context init parameter
•Access to Resource
•Request Dispatching

7 11/30/09
Part I: JSR 168 Specification

PortalContext:

The PortalContext interface provides information about the portal that is


invoking the portlet.

•Portal Vendor and portal version information.


•Portal properties
•Portal Modes and Windows available
•Obtained from the getPortalContext

8 11/30/09
Part I: JSR 168 Specification

Portlet:

A portlet is managed through a well defined life cycle that defines how it
is loaded, instantiated and initialized, how it handles requests from
clients, ….. This life cycle of a portlet is expressed through the init,
processAction, render and destroy methods of the Portlet interface…

•Lifecycle:
•Init()
•Destroy()
•Request Processing:
•ProcessAction()
•RenderRequest

9 11/30/09
Part I: JSR 168 Specification

Request Processing: processAction & RenderRequest

Process Action Render Request


Request
Change portlet mode Process render logic

Change business Read business data


data for display
Executed on action Executed after each
request request. (render or
action)
Does not render / Always dispatches to
dispatches to a view a view.

10 11/30/09
Part I: JSR 168 Specification

PortletSession:

PortletSession objects must be scoped at the portlet application context


level. Each portlet application has its own distinct PortletSession object
per user session. The portlet container must not share the
PortletSession object or the attributes stored in it among different portlet
applications or among different user sessions.

PortletSession session = request.getSession(true);


URL url = new URL(“http://www.foo.com”);
session.setAttribute(“home.url”,url,PortletSession.APPLICATION_SCOPE);
session.setAttribute(“bkg.color”,”RED”,PortletSession.PORTLET_SCOPE);

11 11/30/09
Part I: JSR 168 Specification

Portlet Mode:

•VIEW – It generates the


output reflecting the actual
portlet status

•HELP – Provides
information about the portlet

•EDIT – Provides content
and logic to customize the
portlet behavior

•CUSTOMS – Defined by
the portal vendor for “vendor
specific functionality”

12 11/30/09
Part I: JSR 168 Specification

Window State: Normal / Maximize / Minimized / Customs

•NORMAL – All render

•MAXIMIZED – One render



•MINIMIZED – Others render

•CUSTOMS – Vendor Specific

13 11/30/09
Part II: JSR168 and the MVC Pattern

Model-View-Controller (MVC)
software architecture that separates an application's data model,
user interface, and control logic into three distinct components so
that modifications to the view component can be made with
minimal impact to the data model component.

Controller Responds to user


events

Controller Model View Render typically in


user interface

Model Define the views


View when the data
changes

14 11/30/09
Part II: JSR168 and the MVC Pattern

Portlet: Model-View-Controller (MVC)


Portlet MVC key point:
•HttpRequest not available
•PortletMode and Window
State
•Portlet depends on Action
and Render Request
•View render fragment

Portal wraps HttpRequest and handles the Portlet


Request. Portlet Request does not have direct
access to the URL.

15 11/30/09
Part II: JSR168 and the MVC Pattern

MVC: Features
§Request Parameter Mapping
§Request Handlers
§Request Validation
§Views
§

16 11/30/09
Part III: Spring MVC Portet

Portlet.xml Configuration
<portlet>
<description>Search Portlet</description>
<portlet-name>SearchPortlet</portlet-name>
<display-name>SearchPortlet</display-name>
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<init-param>
<name>contextConfigLocation</name>
<value>/WEB-INF/context/SearchPortlet-portlet.xml</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
<portlet-mode>config</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>Search by category Portlet</title>
<short-title>SP</short-title>
<keywords>Search</keywords>
</portlet-info>
</portlet>

17 11/30/09
Part III: Spring MVC Portet

SearchPortlet-portlet.xml: HandlerMapping
<bean id="portletModeParameterHandlerMapping"
class="org.springframework.web.portlet.handler.PortletModeParameterHandlerMapping">
<property name="order" value="0" />
<property name="portletModeParameterMap">
<map>
<entry key="config"> Mode
<map> ParameterValue
<entry key=“queryStr"><ref bean=“queryPortletController"/></entry>
<entry key=“advanced"><ref bean=“advancedSearch"/></entry>
</map>
</entry>
</map>
</property>
<property name="parameterName" value="setaction" />
</bean>

18 11/30/09
Part III: Spring MVC Portet

SearchPortlet-portlet.xml: HandlerMapping
<bean id="portletModeHandlerMapping"
class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property name="order" value="1" />
<property name="portletModeMap">
<map>
Mode
<entry key="config"><ref local=“configPortletController"/></entry>
<entry key="view"><ref local=“displayPortletController"/></entry>
</map>
</property>
</bean>

19 11/30/09
Part III: Spring MVC Portet

SearchPortlet-portlet.xml: Controller
<bean id=“displayPortletController" class=“portlet.mvc.DisplayPortletController">
<property name="commandName" value="DisplayCommand" />
<property name="commandClass" value="portlet.command.DisplayCommand" />
</bean>

20 11/30/09
Part III: Spring MVC Portet

SearchPortlet-portlet.xml: View
<bean id=“myView" class=“org.springframework.web.servlet.view.JstlView">
<property name="url" value=“/jsp/searchView.jsp" />
</bean>

21 11/30/09
Part III: Spring MVC Portet

SearchPortlet-portlet.xml: Form Validation


<bean id=“configValidator"
class="portlet.mvc.validators.ConfigValidator"></bean>

public class ConfigValidator implements Validator {


public boolean supports(Class clazz) {
log.debug(clazz);
if (clazz.getName().equals("portlet.command.DisplayCommand")){
return true;
}
return false;
}

public void validate(Object objectCommand, Errors


errors) {

errors.rejectValue(PortletConstants.queryString,"",ErrorMessages.MISSINGVALUE);

22 11/30/09
Part IV: Pattern - Builder

23 11/30/09
Part IV: Pattern - Builder

Builder

24 11/30/09
Part IV: Pattern - Builder

BuildContentSource
BuildContentType
BuildView

BuildByChannel/Byco
ntent/ByFeed

BuildLabels

25 11/30/09
Part IV: Pattern - Builder

protected ModelAndView showForm(RenderRequest renderRequest, RenderResponse


renderResponse, BindException bindException) throws Exception {
public void buildOrderBy(String type) {
…

String contentSource
SettingPageBuilder = parameterAdapter.getParameter(PortletConstants.contentSource);
pageBuilder = new CQSettingPage(modelAndView, renderRequest);
Content content = (Content)ServiceManager.getInstance().getService(contentSource);
pageBuilder.buildPage(action);

….

modelAndView.addObject(PortletConstants.orderableAttributes,content.getOrderableAttrib
public
utes());class CQSettingPage extends AbstractSettingPageBuilder {
 this.getParameterAdapter().setType(ParameterAdapter.PREFERENCES);
modelAndView.addObject(type,parameterAdapter.getParameter(type));
 } this.buildContentSource();
 this.buildContentType();
 this.buildFilterBy();
 // build view for type: channel
 this.buildDisplayView(viewForType);
 this.buildLabels();

26 11/30/09
Questions ?

27 11/30/09

Das könnte Ihnen auch gefallen