Java Portlet (JSR 168)

annuncio pubblicitario
Java Portlet
(JSR 168)
i benefici di sviluppare portlet standard
Simone Federici
K-Tech
www.javaportal.it
1
Roadmap
1.Cosa sono le portlet
2.Architettura
3.Usare le portlet
4.Approfondimenti
5.Conclusioni
2
Il talk si rivolge agli
sviluppatori e
analisti J2EE
Perché usare le
Java portlet ?
3
1
Cosa sono le portlet?
?
4
Java Portlet = [
1
]
X
E' un Java Web Component !
E il suo ciclo di vita è gestito da un
portal container.
Ma cosa è un Portal Container?
5
1
Portals JSR Complaint
Pluto
Sun Java System
Jetspeed2
Plumtree
LifeRay
BEA
eXo
Oracle 9i
gridsphere
WebSphere
uPortal
MS SharePoint
Broadvision
6
1
Standard JSR 168
●
Portlet API
●
Portlet Requests
●
Preferences
●
User information
●
Security
●
Deployment packaging
●
Portlet Container
●
Extension of servlet container
●
Contract between component and container
7
2
Architecture
Web Browser
Portal Server
Web Browser
Web Browser
Portlet Container
DATA
8
2
Result Page
• Portal Server
• Portlet
Portal Server
• Fragment
F1
• Portlet
Container
F2
F3
Portlet Container
P1
P2
P3
9
Compiti del Portal server
•Aggregation
•Layout management
•Page personalization and configuration engines
•Portal administration and configuration
10
2
2
Portal and Portlet
Interaction
User
A
B
C
Portlet
container
Portal
Action on B
Do action on B
Render A
These requests
may be done in
parallel
B
Portlets
B
C
processAction
render
Render B
render
Render C
A’
A
render
C
Scope of the Portlet specification
11
2
Java Portlet
State:
•Normal
•Massimizza
•Minimizza
Modes:
•VIEW
•EDIT
•HELP
12
2
States
Normal, minimizzata e massimizzata.
Il portal server ha il compito di gestire la
renderizazione delle portlet nei deversi stati.
Il compito del container è gestire il
cambiamento dello stato delle portlet.
13
2
Modes
VIEW, EDIT e HELP
Il Portal Server puo' aggiungere altri
stati. (deve implementarli)
E' poi possibile accedere a questi
aggiungendo un
<custom-portlet-mode>
nel file descriptor.
14
2
Perche le portlet?
non posso fare tutto
tramite servlet?
in comune:
• J2EE Web Component
• Gestita dal container
• Generate da un paradigma request/response
15
2
Differenze
Portlet & Servlet
•
Mentre la servlet genera una pagina la portlet genera un fragment
•
Le portlet non mappate da una specifica url
•
Le P. hanno un sofisticato schema di request action / render
•
Le P. hanno stati e “modes” standard che definiscono le regole di azione e
visualizzazione
•
Le P. usano dei meccanismi di accesso e persistenza alle informazioni di
configurazione
•
Le P. possono fare portlet rewriting cosi da essere indipendenti
dall'implementazone del portale
•
Le P. hanno due differenti session scope: application e private.
•
Le P. non possono alterare l'HTTP header o setatre la response encoding.
16
2
Portability
La “stessa” portlet puo' essere usata
in contesti estremamente diversi
basta attivarla (deploy) in un portal
Compliant alle spefifiche JSR168
17
Portal/Portlet
Architecture
Portal server
Security
Remote
Execution
module
Aggregation
Engine
User
Configuration/
Personalization
Engine
2
Windo
w
Config
Portlet
Portlet
Dispatcher
Portlet
Portlet
Persistent
Data Store
Enterpris
e
Informati
on
Systems
18
3
Portlet Life Cycle
I medodi chiamati dal container sono:
• init()
• destroy()
• processAction()
• render()
+ cheamati dal render di GenericPortlet:
• doView()
• doEdit()
• doHelp()
19
Portlet Life Cycle
Initialized
by
container
render()
render() notifies the
Portlet to generate the
markup fragment
Handle
requests
3
init()
Notifies initialization of
portlet by container.
processActio
processAction() notifies
n()
the Portlet about user's
request for action.
Destroye
d by
container
destroy(
destroy()
notifies the
)
destruction of portlet by
container. Should free
up resources in this
method.
20
3
Init / destroy
void init(PortletConfig config) {
config.getInitParameter(java.lang.String name);
config.getInitParameterNames();
config.getPortletContext();
config.getPortletName();
config.getResourceBundle(java.util.Locale locale);
this.config = config;
}
void destroy () { config=null; }
21
3
processAction()
Viene chiamato dal container quando
una “azione” viene effettuata nella
portlet.
PortletURL()
createActionURL()
22
3
render()
Viene chiamato ogni volta che una
portlet deve essere visualizzata
su una pagina
PortletURL()
createActionURL()
23
3
GenericPortlet
E' una implementazione
javax.portlet.Portlet
sostanzialmente aggiunge un dispacher() che chiama i
seguenti metodi a secondo dello stato della portlet.
•doView()
•doEdit()
•doHelp()
24
3
Portlet Example
pub lic c las s Hel loW or ldP or tl et ex ten ds Gen eri cP ort le t {
publ ic vo id do Vi ew ( R en der Re que st re que st , Re nd er Res po nse re sp ons e) th ro ws Po rt let Exc ep tio n {
re sp ons e. set Co nte ntT yp e( “te xt /ht ml ”);
Pr in tWr it er wr ite r = r es pon se .ge tW rit er ();
Wr it er. wr ite (" Hel lo Wo rl d") ;
}
}
25
3
Render by JSP?
public class HTMLPortlet extends GenericPortlet
{
public void doView(RenderRequest request, RenderResponse response) throws ...
{
PortletPreferences pref = request.getPreferences();
String path = pref.getValue("path", "/hello_jip.jsp");
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(path);
rd.include(request, response);
}
}
26
3
CustomTag
<%@taglib uri='http://java.sun.com/portlet'
prefix="portlet" %>
<portlet:defineObjects/>
<!-- RenderRequest renderRequest -->
<!-- RenderResponse renderResponse -->
<% PortletSession renderSession =
renderRequest.getPortletSession(); %>
27
4
Multithread
Il container può chiamare i render delle
varie portlet da visualizzare in modo
concorrenziale.
Ricordiamo che le azioni sono gestite nel
processAction()
Il render va usato solamente per
renderizzare
28
4
Se il contenuto di una
portlet dipende da
un'altra?
Ci sono strutture dati condivise dalle
portlet / servlet
Non usate mai variabili di classe !!
29
4
Portal and Portlet
Interaction
User
A
B
C
Portlet
container
Portal
Action on B
Do action on B
Render A
These requests
may be done in
parallel
B
Portlets
B
C
processAction
render
Render B
render
Render C
A’
A
render
C
Scope of the Portlet specification
30
Comunicazione attraverso
PortletSession
APPLICATION_SCOPE
ossia nell'HttpSession
PORTLET_SCOPE
scope privato (*)
31
4
Portlet Web
Application

All resources, portlets, deployment descriptors are
packaged in one web application archive (WAR file)

PortletApp\
 jsp
 htmls
 WEB-INF\
 web.xml
 portlet.xml
 sun-portlet.xml
 classes\
 Lib\
4
32
Localization
4
• Portlets can be localized by using
resource bundles
• Resource bundles are specified in
deployment descriptor
• Portlet can access resource bundle
via
PortletContext.getResourceBundle()
API
33
4
Portlet.xml
<p ort le t­a pp > <por tle t>
<po rtl et ­n ame >H ell oWo rl dPo rt let </ por tl et ­
na me>
<po rtl et ­c las s>
Cu sto m. He llo Wo rld Por tl et
</p ort le t­ cla ss >
<ex pir at io n­c ac he> 0</ ex pir at ion ­c ach e>
<su ppo rt s>
<mi me ­t ype >t ext /ht ml </m im e­t yp e>
<por tl et ­mo de >VI EW< /p ort le t­m od e>
</ su ppo rt s>
<p or tle t­ pr efe ren ce >
<pr ef er enc e>
<n am e>l oc ale < /na me>
<v al ue> US A</ va lue >
</p re fe ren ce >
</ po rtl et ­p ref ere nc e>
</ po rtl et >
</po rt let ­a pp >
34
4
Apache Bridge Struts
http://portals.apache.org/bridges/multiproject/portals-bridges-struts/
Sviluppate una Applicazione Struts!!
l'applicazione potra poi essere usata come una webapp standard
oppure messa dentro un portal come una portlet.
Richiede che il container implementi una ulteriore interfaccia...
35
Grazie alla Community di Javaportal
che sempre cresce sempre più
Grazie a tutti voi di essere qui
Restate con noi.. perchè
Programmiamo da far Paura!
36
Framework
Si sposano bene con altri
framework?
37
Resources
• Javapassion
http://www.javapassion.com
• Java Community Process
http://www.jcp.org/en/jsr/detail?id=168
38
Scarica