Java Portlets (JSR-168)
Java Portlets (JSR-168)
Java Portlets
(JSR-168)
1
12/09/2003
Sang Shin
[email protected]
www.javapassion.com
Java™ Technology Evangelist
Sun Microsystems, Inc.
2
12/09/2003
Agenda
What is a Portlet?
4
12/09/2003
What is a Portlet?
? Java technology based web component
? Managed by a portal container
? Generates a piece of markup called
“fragment”
– Adheres to certain rules such as no <html> tags, for
instance
– Fragment generated by a Portlet aggregates with
that from other Portlets to form a portal page
– Fragment generated by a Portlet may vary from one
user to another depending on the user
configuration
12/09/2003
Default Desktop
Bottom-
level
Portlet
12/09/2003
Portal/Portlet Architecture
Window
Security Config
Remote Portlet
Execution
module Portlet
Portlet Enterprise
Dispatcher
Aggregation Information
Engine Portlet Systems
User
Configuration/ Persistent
Personalization Data Store
Engine
12/09/2003
Render A
render
A’
B’ C
Outside of the scope of the Portlet specification Scope of the Portlet specification
12/09/2003
Why Portlet?
(Why can't we use Servlet?)
11
12/09/2003
Why Portlets?
? Servlet architecture does not define the
Desktop metaphor where markup
aggregation can occur
? Servlet architecture does not define the
possible states and transitions of an
included Servlet or JSP
? Servlet architecture does not define how
the state of one Servlet or JSP affects the
display of the other included Servlets or
JSPs
12/09/2003
Why Portlets?
? Servlet architecture does not define a
personalization interface nor the idea of
persisting the personalization information
? Servlet architecture does not define URL-
rewriting functions to allow the creation of
links and actions targeted to a specific form
within the fragment of a page (Portlet
markup fragment)
? Servlet architecture does not support
caching scheme of fragments
12/09/2003
Deploy to Many
Write Once
Portlet Interface
JSR 168
Compliant
Portals
12/09/2003
Portlet Architecture
15
12/09/2003
Portal Architecture
With JSR 168 Support
Portlet
Container
User Agent
Browser, Phone, PDA Network
12/09/2003
Portal
? A “specialized” web application that
provides value-added services such as
– Personalization
– Single Sign-On
– Content aggregation from various sources
– Secure search facilities
– Localization of content
? A Portal “page” represents a complete
markup document consisting of several
Portlet components
12/09/2003
Portlet Container
? Portlets are deployed in a Portlet container
such that container can
– Provides runtime environment for Portlets
– Manage life cycle of Portlets
– Provide persistent storage for storing Portlet
preferences
– Cache the portlets
– Receive requests from the portal to execute
requests on the portlet
? Not responsible for contents aggregation
12/09/2003
19
12/09/2003
? Deployment model
? Classloading
? Packaging and deployment
? Lifecycle management
? Session management
? Request dispatching
12/09/2003
Portlet and
Web App. Frameworks
27
12/09/2003
30
12/09/2003
Portlet Modes
? Indicates function that a portlet performs
– Execute different tasks and generate different
content based on the function they perform
? Portals must support three modes
– VIEW
? Portlet renders markup fragment in this mode
– EDIT
? Used to change per-user settings to customize
rendering
– HELP
? Used to display help information
12/09/2003
Windows State
? Is an indicator of the amount of portal page
space that will be assigned to the content
generated by a portlet
? Provided by portlet container
? Three states
– NORMAL
– MAXIMIZED
– MINIMIZED
? Custom states are possible
12/09/2003
Portlet Features
34
12/09/2003
Portlet Persistence
Portal context
Security
? Authentication is left to the underlying
servlet container
? Authorization
– Follows J2EE ‘roles’ model
– Supports programmatic role checking
12/09/2003
Session Management
? Facade on top of the HttpSession
? Two scopes: APPLICATION & PORTLET
– PORTLET is a convenience namespacing
– It’s common for portlets to appear more than once in
a page (i.e.: EU-News, US-News)
? Servlets, JSPs and Portlets within a Portlet
Application share the same session
? Session creation event notification is
supported
12/09/2003
Localization
Caching
Portlet URL
?
Portlets are always accessed through a
Portal
?
Portlets do not have a direct URL mapping
? Portlet URLs allow Portlets to create URLs
that target to themselves (through the
Portal end-point)
12/09/2003
Portlet API's
44
12/09/2003
GenericPortlet class
? Implements Portlet interface
? Render()--like service() in servlets, calls
specified render methods based on Portlet
mode
– doView() for View mode
– doEdit() for Edit mode
– doHelp() for Help mode
? Is extended by portlet developers
– Override render methods as necessary
12/09/2003
DoView()
Render() doView()
doEdit()
doHelp() HTML
Portlet
12/09/2003
DoEdit()
doView() HTML
Render() doEdit()
doHelp()
Edit Form
Portlet
12/09/2003
ProcessAction()
Portlet
Render() DoView()
ProcessAction() HTML
store()
S1DS
12/09/2003
Other Interfaces/Classes
? PortletConfig, PortletContext,
PortalContext,PortletSession
? PortletPreferences interface
? WindowState (MINIMIZED,
NORMAL & MAXIMIZED)
? PortletMode (VIEW, EDIT & HELP)
? PortletURL
? PortletRequestDispatcher
? Portlet Tag Library
12/09/2003
PortletPreferences
? Persistent read/write Portlet configuration
– getValues(), setValues() to access PortletPreferences
– May modify attributes and store() in persistence
during processAction()
? Normally, portlet preferences are per
portlet/per user
? Persistency is managed by the portlet-
container
? Default values are defined in the portlet.xml
deployment descriptor
12/09/2003
Packaging &
Deployment
54
12/09/2003
WeatherPortlet
Sample Code
57
12/09/2003
WeatherPortlet
58
12/09/2003
WeatherPortlet (1 of 7)
WeatherPortlet (2 of 7)
1. public void doView(RenderRequest rReq, RenderResponse rRes)
2. throws PortletException, IOException {
3. rRes.setContentType("text/html");
4. PortletPreferences prefs = rReq.getPreferences();
5. String zip = rReq.getParameter("zip");
6. if (zip==null)
7. zip = prefs.getValue("zip","10000");
8. String unit = prefs.getValue("unit","F");
9. try {
10. W eatherForecaster weatherForecaster =
11. _weatherService.getWeatherForecasterPort();
12. W eather weather =
13. weatherForecaster.getWeather(zip,unit.charAt(0));
14. weatherForecaster = null;
15. rReq.setAttribute("weather",weather);
16. PortletRequestDispatcher rd = getPortletContext().
17. getRequestDispatcher("/weather/weatherView.jsp");
18. rd.include(rReq,rRes);
19. }catch (Exception ex) {
20. rRes.setProperty("expiration-cache","0"); 60
21. PortletRequestDispatcher rd =
12/09/2003
WeatherPortlet (3 of 7)
weatherView.jsp
1. <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
2. <h3>Weather Information</h3> <p>
3.
4. City: <jsp:getProperty name="weather" property="city"/> <p>
5. Zip Code: <jsp:getProperty name="weather" property="zip"/> <p>
6. Time: <jsp:getProperty name="weather" property="time"/> <p>
7. Temperature unit: <jsp:getProperty name="weather" property="unit"/>
<p>
8. Current Temperature: <jsp:getProperty name= "weather"
property="currentTemp"/> <p>
9. Low: <jsp:getProperty name="weather" property="minTemp"/><p>
10. High: <jsp:getProperty name="weather" property="maxTemp"/><p>
11. <form method="post" action="<portlet:actionURL/>">
12. Enter Zip Code:
13. <input type="text" name="zip" value="">
14. <input type="submit" name="submit" value="Search">
15. </form>
61
12/09/2003
WeatherPortlet (4 of 7)
WeatherPortlet (5 of 7)
1. public void processAction(ActionRequest aReq, ActionResponse aRes) throws
PortletException, IOException {
2. PortletPreferences prefs = aReq.getPreferences();
3. String zip = aReq.getParameter("zip");
4. if (aReq.getPortletMode().equals(PortletMode.VIEW))
5. aRes.setRenderParameter("zip",zip);
6. else
7. if (aReq.getPortletMode().equals(PortletMode.EDIT)) {
8. ... // some variables initialization
9. String unit = aReq.getParameter("unit");
10. prefs.setValue("zip",zip);
11. prefs.setValue("unit",unit);
12. try {
13. prefs.store();
14. editOK = true;
15. }catch (ValidatorException ex) {
16. editOK = false;
17. errorMsg = ex.getMessage();
18. }
19. if (editOK)
20. aRes.setPortletMode(PortletMode.VIEW);
21. else {
22. aRes.setRenderParameter("error", URLEncoder.encode(errorMsg));
23. } }
63
12/09/2003
WeatherPortlet (6 of 7)
64
12/09/2003
portlet.xml
1. <portlet-app>
2. <portlet>
3. <portlet-name>WeatherPortlet</portlet-name>
4. <portlet-class>sample.portlet.WeatherPortlet</portlet-class>
5. <init-param>
6. <name>weather.url</name>
7. <value>java:/comp/env/WeatherProvider</value>
8. </init-param>
9. <expiration-cache>3600</expiration-cache>
10. <supports>
11. <mime-type>text/html</mime-type>
12. <portlet-mode>EDIT</portlet-mode>
13. <portlet-mode>HELP</portlet-mode>
14. </supports>
15. <portlet-info><title>WeatherPortlet</title></portlet-info>
16. <portlet-preferences>
17. <preference>
18. <name>zip</name> <value>95054</value>
19. </preference>
20. <preference>
21. <name>unit</name> <value>F</value>
22. </preference>
23. <preferences-validator>sample.portlet.WeatherValidator
24. </preferences-validator>
25. </portlet-preferences>...
65
12/09/2003
WSRP
(Web Services for
Remote Portlet)
66
12/09/2003
Portal Architecture
With WSRP Support
Portlet:Portlet.processAction()
–
WSRP: WSRP.performBlockingInteraction()
Portlet: Portlet.render()
–
WSRP: WSRP.getMarkup()
12/09/2003
70
12/09/2003
Integrated Communications
Desktop and Wireless Access
Access Mail, Calendar and
Instant Messaging Channels
Instant Messaging Server
from your Desktop or...
Forward From Any
Alerts to Mobile Device
a Phone
Messaging Server
Calendar Server
Make Calendar
Appointments
Respond to Email
12/09/2003
Personalization
?
Modify any aspect of the desktop (as
allowed by the Administrator)
– Add or delete portlets
– Customize the desktop layout
– Use or create personalized themes
– Modify or create multiple tabs
– Update user profile information
– Modify portlets settings and properties
12/09/2003
Producer
WSRP
SOAP
WSRP
Portlet Container
Consumer Portlet
(remote Portal)
Portlet
HTTP/S
Network
HTML/WML
Portlet
VoiceXML
HTTP/S
WSRP
Consumer
SOAP
WSRP Producer
Network
(remote Portal)
12/09/2003
SAP Vendor
Portlet Specific EIS
PSFT
Portlet
Portlet Container
JDBC
User Agent JDBC
(Browser) Portlet
Network
(PDA) Portal JCA Network
(Phone) Portlet
XML
Portlet XML
WS Web
Portlet SOAP Server
URL
Portlet Html
76
12/09/2003
Portlet Builder
Resources
80
12/09/2003
Resources
? JSR 168
http://www.jcp.org/jsr/detail/168.jsp
TM
? Sun ONE Portal Server
http://wwws.sun.com/software/products/portal_srvr/home_portal.html
? WSRP @ OASIS
http://www.oasis-open.org/committees/wsrp/
Thank You!
82