+ All Categories
Home > Technology > Jipday Portletjsr168

Jipday Portletjsr168

Date post: 05-Jul-2015
Category:
Upload: simone-federici
View: 570 times
Download: 0 times
Share this document with a friend
38
1 Java Portlet (JSR 168) i benefici di sviluppare portlet standard www.javaportal.it Simone Federici K-Tech
Transcript
Page 1: Jipday Portletjsr168

1

Java Portlet(JSR 168)

i benefici di sviluppare portlet standard

www.javaportal.it

Simone Federici

K-Tech

Page 2: Jipday Portletjsr168

2

Roadmap

1.Cosa sono le portlet

2.Architettura

3.Usare le portlet

4.Approfondimenti

5.Conclusioni

Page 3: Jipday Portletjsr168

3

Il talk si rivolge agli sviluppatori e analisti J2EE

Perché usare leJava portlet ?

Page 4: Jipday Portletjsr168

4

Cosa sono le portlet?

?

1

Page 5: Jipday Portletjsr168

5

Java Portlet = [ X]

E' un Java Web Component !

E il suo ciclo di vita è gestito da un portal container.

Ma cosa è un Portal Container?

1

Page 6: Jipday Portletjsr168

6

Portals JSR Complaint

Pluto

Jetspeed2

LifeRay

eXo

gridsphere

uPortal

Sun Java System

Plumtree

BEA

Oracle 9i

WebSphere

MS SharePoint

Broadvision

11

Page 7: Jipday Portletjsr168

7

Standard JSR 168●Portlet API●Portlet Requests●Preferences●User information●Security●Deployment packaging●Portlet Container●Extension of servlet container●Contract between component and container

1

Page 8: Jipday Portletjsr168

8

Architecture 2

DATA

Portal Server

Portlet ContainerWeb BrowserWeb BrowserWeb BrowserWeb Browser

Web Browser

Web BrowserWeb BrowserWeb BrowserWeb Browser

Page 9: Jipday Portletjsr168

9

Result Page

• Portal Server

• Portlet

• Fragment

• Portlet Container

Portal Server

Portlet Container

F1F3

P1 P2 P3

F2

2

Page 10: Jipday Portletjsr168

10

Compiti del Portal server

•Aggregation•Layout management

•Page personalization and configuration engines

•Portal administration and configuration

2

Page 11: Jipday Portletjsr168

11

Portal and Portlet Interaction

User PortalPortlet

containerPortlets

A B C

render

render

render

processAction

A

B C

A’

B C

Action on BDo action on B

Render A

Render B

Render C

These requests may be done in

parallel

Scope of the Portlet specification

2

Page 12: Jipday Portletjsr168

12

Java PortletState:

•Normal

•Massimizza

•Minimizza

Modes:

•VIEW

•EDIT

•HELP

2

Page 13: Jipday Portletjsr168

13

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.

2

Page 14: Jipday Portletjsr168

14

ModesVIEW, 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.

2

Page 15: Jipday Portletjsr168

15

Perche le portlet?non posso fare tutto

tramite servlet?

in comune:

• J2EE Web Component

• Gestita dal container

• Generate da un paradigma request/response

2

Page 16: Jipday Portletjsr168

16

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.

2

Page 17: Jipday Portletjsr168

17

Portability

La “stessa” portlet puo' essere usata in contesti estremamente diversi

basta attivarla (deploy) in un portal Compliant alle spefifiche JSR168

2

Page 18: Jipday Portletjsr168

18

Portal/Portlet Architecture

User Configuration/Personalization

Engine

PersistentData Store

PortletDispatcher

Window

ConfigSecurity

Portlet

Enterprise

Information

Systems

RemoteExecutionmodule

Portlet

AggregationEngine

Portlet

Portal server

2

Page 19: Jipday Portletjsr168

19

Portlet Life CycleI medodi chiamati dal container sono:

• init()

• destroy()

• processAction()

• render()

+ cheamati dal render di GenericPortlet:

• doView()

• doEdit()

• doHelp()

3

Page 20: Jipday Portletjsr168

20

Portlet Life Cycle

Handle requests

Destroyed by

container

Initialized by

containerinit()

processAction()

destroy()

Notifies initialization of portlet by container.

processAction() notifies the Portlet about user's request for action.

render() render() notifies the Portlet to generate the markup fragment

destroy() notifies the destruction of portlet by container. Should free up resources in this method.

3

Page 21: Jipday Portletjsr168

21

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; }

3

Page 22: Jipday Portletjsr168

22

processAction()

Viene chiamato dal container quando una “azione” viene effettuata nella

portlet.

PortletURL()

createActionURL()

3

Page 23: Jipday Portletjsr168

23

render()

Viene chiamato ogni volta che una portlet deve essere visualizzata

su una pagina

PortletURL()

createActionURL()

3

Page 24: Jipday Portletjsr168

24

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()

3

Page 25: Jipday Portletjsr168

25

Portlet Example

 public class HelloWorldPortlet extends GenericPortlet {

   public void doView( RenderRequest request,                        RenderResponse response)                        throws PortletException {

     response.setContentType(“text/html”);     PrintWriter writer = response.getWriter();     Writer.write("Hello World");   } }

3

Page 26: Jipday Portletjsr168

26

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);

}

}

3

Page 27: Jipday Portletjsr168

27

CustomTag

<%@taglib uri='http://java.sun.com/portlet' prefix="portlet" %>

<portlet:defineObjects/>

<!-- RenderRequest renderRequest -->

<!-- RenderResponse renderResponse -->

<% PortletSession renderSession = renderRequest.getPortletSession(); %>

3

Page 28: Jipday Portletjsr168

28

MultithreadIl 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

4

Page 29: Jipday Portletjsr168

29

Se il contenuto di una portlet dipende da

un'altra?

Ci sono strutture dati condivise dalle portlet / servlet

Non usate mai variabili di classe !!

4

Page 30: Jipday Portletjsr168

30

Portal and Portlet Interaction

User PortalPortlet

containerPortlets

A B C

render

render

render

processAction

A

B C

A’

B C

Action on BDo action on B

Render A

Render B

Render C

These requests may be done in

parallel

Scope of the Portlet specification

4

Page 31: Jipday Portletjsr168

31

Comunicazione attraverso PortletSession

APPLICATION_SCOPE

ossia nell'HttpSession

PORTLET_SCOPE

scope privato (*)

4

Page 32: Jipday Portletjsr168

32

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

Page 33: Jipday Portletjsr168

33

Localization

• Portlets can be localized by using resource bundles

• Resource bundles are specified in deployment descriptor

• Portlet can access resource bundle via PortletContext.getResourceBundle() API

4

Page 34: Jipday Portletjsr168

34

Portlet.xml<portlet­app>     <portlet>    <portlet­name>HelloWorldPortlet</portlet­name>

    <portlet­class>     Custom.HelloWorldPortlet    </portlet­class>    <expiration­cache>0</expiration­cache>    <supports>       <mime­type>text/html</mime­type>      <portlet­mode>VIEW</portlet­mode>   </supports>   <portlet­preference>       <preference>          <name>locale </name>          <value>USA</value>       </preference>   </portlet­preference>   </portlet> </portlet­app>

4

Page 35: Jipday Portletjsr168

35

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...

4

Page 36: Jipday Portletjsr168

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!

Page 37: Jipday Portletjsr168

37

Framework

Si sposano bene con altri

framework?

Page 38: Jipday Portletjsr168

38

Resources• Javapassion

http://www.javapassion.com

• Java Community Process

http://www.jcp.org/en/jsr/detail?id=168