5. 1
Java Portlet = [ X
]
E' un Java Web Component !
E il suo ciclo di vita è gestito da un
portal container.
Ma cosa è un Portal Container?
5
6. 1
Portals JSR Complaint
Pluto Sun Java System
Jetspeed2 Plumtree
LifeRay BEA
eXo Oracle 9i
gridsphere WebSphere
uPortal MS SharePoint
Broadvision
6
7. 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
8. 2
Architecture
Web Browser
Portal Server
Web Browser
Web Browser
Portlet Container
DATA
8
9. Result Page 2
• Portal Server
• Portlet
Portal Server
• Fragment
F1
• Portlet F3
F2
Container
Portlet Container
P1 P2 P3
9
10. 2
Compiti del Portal server
•Aggregation
•Layout management
•Page personalization and configuration engines
•Portal administration and configuration
10
11. 2
Portal and Portlet
Interaction
Portlet Portlets
User Portal container A B C
A
Action on B
B C Do action on B processAction
Render A
render
These requests Render B
may be done in
parallel render
Render C
render
A’
B C
Scope of the Portlet specification
11
13. 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
14. 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
15. 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
16. 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
17. 2
Portability
La “stessa” portlet puo' essere usata
in contesti estremamente diversi
basta attivarla (deploy) in un portal
Compliant alle spefifiche JSR168
17
18. Portal/Portlet
2
Architecture
Portal server
Windo
w
Security Config
Remote Portlet
Execution
module Portlet
Portlet Enterpris
Dispatcher
Aggregation e
Engine
Portlet
Informati
on
User
Configuration/ Persistent Systems
Personalization Data Store
Engine
18
19. 3
Portlet Life Cycle
I medodi chiamati dal container sono:
• init()
• destroy()
• processAction()
• render()
+ cheamati dal render di GenericPortlet:
• doView()
• doEdit()
• doHelp()
19
20. Portlet Life Cycle 3
Initialized
by init()
container Notifies initialization of
portlet by container.
render() Handle processActio
requests
render() notifies the n()
processAction() notifies
Portlet to generate the the Portlet about user's
markup fragment request for action.
Destroye
d by destroy(
container
)
destroy() notifies the
destruction of portlet by
container. Should free
up resources in this
method. 20
22. 3
processAction()
Viene chiamato dal container quando
una “azione” viene effettuata nella
portlet.
PortletURL()
createActionURL()
22
23. 3
render()
Viene chiamato ogni volta che una
portlet deve essere visualizzata
su una pagina
PortletURL()
createActionURL()
23
24. 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
25. Portlet Example 3
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
26. 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
28. 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
29. 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
30. 4
Portal and Portlet
Interaction
Portlet Portlets
User Portal container A B C
A
Action on B
B C Do action on B processAction
Render A
render
These requests Render B
may be done in
parallel render
Render C
render
A’
B C
Scope of the Portlet specification
30
32. Portlet Web
4
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
32
33. 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
34. 4
Portlet.xml
<p ort le ta 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 nc ac he> 0</ ex pir at ion c ach e>
<su ppo rt s>
<mi me t ype >t ext /ht ml </m im et yp e>
<por tl et mo de >VI EW< /p ort le tm 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
35. 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
36. 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