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
Cosa sono le portlet? 1? 4
Java Portlet = [ X ] 1 E' un Java Web Component! E il suo ciclo di vita è gestito da un portal container. Ma cosa è un Portal Container? 5
Portals JSR Complaint 1 Pluto Jetspeed2 LifeRay exo gridsphere uportal Sun Java System Plumtree BEA Oracle 9i WebSphere MS SharePoint Broadvision 6
Standard JSR 168 1 Portlet API Portlet Requests Preferences User information Security Deployment packaging Portlet Container Extension of servlet container Contract between component and container 7
Architecture 2 Web Browser Web Browser Web Browser Portal Server Portlet Container DATA 8
Result Page 2 Portal Server Portlet Fragment Portlet Container Portal Server F1 F3 F2 Portlet Container P1 P2 P3 9
Compiti del Portal server 2 Aggregation Layout management Page personalization and configuration engines Portal administration and configuration 10
Portal and Portlet 2 Interaction A User Portal Portlet container Portlets A B C B C Action on B Do action on B processaction Render A render These requests may be done in parallel Render B render A Render C render B C Scope of the Portlet specification 11
Java Portlet 2 State: Normal Massimizza Minimizza Modes: VIEW EDIT HELP 12
States 2 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
Modes VIEW, EDIT e HELP 2 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
Differenze 2 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
Portability 2 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 2 Security Windo w Config Remote Execution module Aggregation Engine User Configuration/ Personalization Engine Portlet Dispatcher Persistent Data Store Portlet Portlet Portlet Enterpris e Informati on Systems 18
Portlet Life Cycle 3 I medodi chiamati dal container sono: init() destroy() processaction() render() + cheamati dal render di GenericPortlet: doview() doedit() dohelp() 19
Portlet Life Cycle 3 Initialized by container init() Notifies initialization of portlet by container. render() render() notifies the Portlet to generate the markup fragment Handle requests Destroye d by container processactio n() processaction() notifies the Portlet about user's request for action. destroy( ) destroy() notifies the destruction of portlet by container. Should free up resources in this method. 20
Init / destroy 3 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
processaction() 3 Viene chiamato dal container quando una azione viene effettuata nella portlet. PortletURL() createactionurl() 22
render() 3 Viene chiamato ogni volta che una portlet deve essere visualizzata su una pagina PortletURL() createactionurl() 23
GenericPortlet 3 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
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
Render by JSP? 3 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
CustomTag 3 <%@taglib uri='http://java.sun.com/portlet' prefix="portlet" %> <portlet:defineobjects/> <!-- RenderRequest renderrequest --> <!-- RenderResponse renderresponse --> <% PortletSession rendersession = renderrequest.getportletsession(); %> 27
Multithread 4 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
Se il contenuto di una 4 portlet dipende da un'altra? Ci sono strutture dati condivise dalle portlet / servlet Non usate mai variabili di classe!! 29
Portal and Portlet 4 Interaction A User Portal Portlet container Portlets A B C B C Action on B Do action on B processaction Render A render These requests may be done in parallel Render B render A Render C render B C Scope of the Portlet specification 30
Comunicazione attraverso 4 PortletSession APPLICATION_SCOPE ossia nell'httpsession PORTLET_SCOPE scope privato (*) 31
Portlet Web Application 4 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
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
Portlet.xml 4 <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
Apache Bridge Struts 4 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