Top Banner
Powerful Portals with JSF How to combine JSF and Portlets? Andy Bosch Independent Consultant www.jsf-forum.de
52

Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Feb 28, 2019

Download

Documents

vuongquynh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Powerful Portals with JSF•How to combine JSF and Portlets?•How to combine JSF and Portlets?

Andy Bosch

Independent Consultant

www.jsf-forum.de

Page 2: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Who am I?

• Name: Andy Bosch

• Trainer, Coach, Developer, …

• Specialized on JSF and Portlets

• Expert Group member of JSR-301 and JSR-329

• Editor of www.jsf-forum.de

• Author of „Portlets und JSF“ (German)

Page 3: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Agenda

• Portals and Portlets

• Motivation for JSF+Portlets

•• Portlet Bridge Specification for JSF

• What is JSR-301?

What is JSR-329?

• Using JSR-301 and JSR-329

• Forecast: JSF 2.0 and Portlet 2.0

• Summary

Page 4: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Agenda

• Portals and Portlets

• Motivation for JSF+Portlets

•• Portlet Bridge Specification for JSF

• What is JSR-301?

What is JSR-329?

• Using JSR-301 and JSR-329

• Forecast: JSF 2.0 and Portlet 2.0

• Summary

Page 5: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

First, what is a „Portal“?

• A Portal is an online community, where you can find information abouta specific topic, e.g. a Portal for jugglers, a Portal for Mercedes drivers

• „A Portal is a website“

• A Portal is a web application, which offers at least the followingcharateristics:

• Aggregation of content and services

• Single Sign On

•• Single Sign On

• Personalization

• …

Page 6: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

„Real Portals“

Page 7: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Portal engines

• IBM WebSphere Portal

• BEA WebLogic Portal

• SAP Netweaver Portal

•• Oracle Portal

• Liferay Portal

• JBoss Portal / GateIn

• …

Unfortunately there is no standard for Portals. Yet, most ofUnfortunately there is no standard for Portals. Yet, most ofthe current Portal engines offer more or less the same functionality. But in detail, there a huge differences.

Page 8: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

From Portals to Portlets

� A portal is responsible for the aggregation of content, applications and services.

� Every fragment of a portal page is called a portlet. � Every fragment of a portal page is called a portlet.

� In that way, many portlets together form a portal page and many portal pages form a portal.

� In contrast to portals, portlets are standardized. � In contrast to portals, portlets are standardized. The underlying standard is JSR-168.

� In 2008, the latest portlet standard, JSR-286 was published.

Page 9: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

How does a Portlet work?

� A portlet is triggered by the portal (to be exact: by the PortletContainer) to display itself (render phase).

� The Portal aggregates all fragments of the portlets included in a page. � The Portal aggregates all fragments of the portlets included in a page. The aggregated output is sent to the browser (e.g. as html-page).

� If an action is triggered by the user (e.g. clicking on a button), the action phase of this portlet will be called. After calling the action phase, all

portlets will be rendered again.

Page 10: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Life cycle of a Portlet (JSR-168)

Init

Render Action

DestroyDestroy

JSR-286 (portlet V2) will extend this life cycle.

Page 11: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

A very simple Portlet

public class SimplePortlet extends GenericPortlet {

protected void doView( ... ) {protected void doView( ... ) {

PrintWriter writer = response.getWriter();

writer.println( "Hello Portlet World" );

String link = ....

writer.println( "<a href='" + link + "'>

Click me</a>" );

}

public void processAction( ... ) {

// TODO do some action logic// TODO do some action logic

}

}

Page 12: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Functionality within JSR-168

� Definition of the Portlet life cycle

� Interfaces and base classes

(GenericPortlet and javax.portlet.Portlet)(GenericPortlet and javax.portlet.Portlet)

� Window states and Portlet modes

� Portlet sessions

� …� …

� Focus is on the Portlet itself

Page 13: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Current specification: JSR-286

� Almost everything of JSR-168 is still valid

� Public render parameter

� Portlet events

� Resource serving

� Portlet filter

� Focus is on the interaction of Portlets

Page 14: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Agenda

• Portals and Portlets

• Motivation for JSF+Portlets

•• Portlet Bridge Specification for JSF

• What is JSR-301?

What is JSR-329?

• Using JSR-301 and JSR-329

• Forecast: JSF 2.0 and Portlet 2.0

• Summary

Page 15: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Building applications with plain portlet functions?

− Programming with the portlet spec is not very convenient.

− We are missing high level concepts like pageflow, bean management, − We are missing high level concepts like pageflow, bean management,

conversion and validation and many more.

− We would like to have modern ui components

We have to combine the Portlet technologieWe have to combine the Portlet technologie

with a powerful user interface framework.

Page 16: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

The solution: JSF?

� JavaServer Faces is a framework which is specialized on the userinterface

� JavaServer Faces is used in many projects in big and small� JavaServer Faces is used in many projects in big and smallcompanies.

� JavaServer Faces has usefull concepts like bean management, pageflow, data conversion and data validation

� JSF is a standard, too.� JSF is a standard, too.

Page 17: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

JSF and UI components

<h:form>

<rich:calendar popup="true"/><rich:calendar popup="true"/>

<rich:inputNumberSpinner

minValue="0"

maxValue="100" step="1"/>

</h:form>

17

Page 18: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

User interface components18

Page 19: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

JSF + Portlets: Isn‘t it easy?

� The problem is the “glue code”.

� We have to integrate both technologies.� We have to integrate both technologies.

Each technology should keep its own functionality, but use the benefits of the other.

� We should try to minimize the integration efforts.

Is this possible?

� Yes, as we can use JSR-301 and JSR-329

Page 20: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Agenda

• Portals and Portlets

• Motivation for JSF+Portlets

•• Portlet Bridge Specification for JSF

• What is JSR-301?

What is JSR-329?

• Using JSR-301 and JSR-329

• Forecast: JSF 2.0 and Portlet 2.0

• Summary

Page 21: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

JSR-301: PortletBridge Specification for JavaServer Faces

� Started in December 2006

�� Spec Lead: Michael Freedman (Oracle)

� Goal is to provide a standardized bridge for executing JSF applications

within a Portlet context.

� To be more precise, the are two specs:

� JSR-301 = Portlet 1.0 (JSR-168) + JSF 1.2 � JSR-301 = Portlet 1.0 (JSR-168) + JSF 1.2

� JSR-329 = Portlet 2.0 (JSR-286) + JSF 1.2

Page 22: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

High level overview

Page 23: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Main challenge / goal

• Mapping of both life cycles

JSF life cycle Portlet life cycle

Page 24: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Mapping of life cycles: JSF

Page 25: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Just to remind: Portlet life cycle

Init

Render Action

Destroy

Page 26: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Mapping of the life cycles: Bridge

Page 27: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Mapping of the life cycles: Bridge

Page 28: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Bridge Request Scope

• In JSF, the complete life cycle is executed within one request.

• In portlets, there are two requests. One for the render phase, one for

the action phase. The requests are independent of each other.the action phase. The requests are independent of each other.

• In that way, the bridge is responsible for supplying all the necessary information for JSF, even if the life cycle is separated into two phases.

• In detail, attributes from the action phase have to be stored temporarily by the bridge and set before executing a JSF render phase.by the bridge and set before executing a JSF render phase.

Page 29: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

JSR-301 / JSR-329 implementations

• Reference implementation within MyFaces communityhttp://myfaces.apache.org/portlet-bridge/index.html

• Open Portal implementation• Open Portal implementationhttps://jsfportletbridge.dev.java.net/

• JBoss implementationhttp://www.jboss.org/portletbridge/

• …• …

Page 30: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Agenda

• Portals and Portlets

• Motivation for JSF+Portlets

•• Portlet Bridge Specification for JSF

• What is JSR-301?

What is JSR-329?

• Using JSR-301 and JSR-329

• Forecast: JSF 2.0 and Portlet 2.0

• Summary

Page 31: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Agenda

• Using JSR-301 / JSR-329

• From JSF to JSF-Portlets

• GenericFacesPortlet

•• Default view id

• Portlet events

• Public render parameter

Page 32: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Using the PortletBridge (1)

1. Developing a “normal” JSF application

2.2. Remove “forbidden” tags like <html>, <body>, <head> etc.

3. Include the JSR-301 / JSR-329 libs

4. Provide a portlet.xml and adjust it.

5.5. Deploy and have fun ☺

Page 33: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Agenda

• Using JSR-301 / JSR-329

• From JSF to JSF-Portlets

• GenericFacesPortlet

•• Default view id

• Portlet events

• Public render parameter

Page 34: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

GenericFacesPortlet

• The Portlet specification defines the Portlet interface which must beimplemented to create a PortletAlso, the Portlet specification defines a base class, which offers some„convenience“ � GenericPortlet„convenience“ � GenericPortlet

• A JSF web application does not have a base class, which could

implement the Portlet interface

• JSR-301 offers a GenericFacesPortlet, which is a Portlet and also bridges to JSF

Page 35: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Using the PortletBridge (2)

<portlet>

<portlet-name>HelloJSFPortlet</portlet-name>

<portlet-class>

javax.portlet.faces.GenericFacesPortletjavax.portlet.faces.GenericFacesPortlet

</portlet-class>

<init-param>

<name>

javax.portlet.faces.defaultViewId.view

</name>

<value>/helloPage.jsp</value><value>/helloPage.jsp</value>

</init-param>

...

Page 36: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Agenda

• Using JSR-301 / JSR-329

• From JSF to JSF-Portlets

• GenericFacesPortlet

• Default view id• Default view id

• Portlet events

• Public render parameter

Page 37: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Default view id

<init-param>

<name>javax.portlet.faces.defaultViewId.view</name>

<value>/helloView.jsp</value>

</init-param>

<init-param>

<name>javax.portlet.faces.defaultViewId.edit</name>

<value>/helloEdit.jsp</value>

</init-param>

...

Page 38: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Agenda

• Using JSR-301 / JSR-329

• From JSF to JSF-Portlets

• GenericFacesPortlet

•• Default view id

• Portlet events

• Public render parameter

Page 39: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Portlet events

• Portlet events are a very useful mechanism within JSR-286 in order torealize IPC (inter portlet communication)

•• Portlets can fire events

• Portlets can listen to events

• The Portal is responsible for the distribution of events

Page 40: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Portlet events and JSR-329

• Define an eventhandler in portlet.xml

• Incoming events will be delegated to the handler• Incoming events will be delegated to the handler

• In the handler, you have access to the FacesContext

• Sending events is not specified. But you can work with the portlet API directly

Page 41: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Portlet Events - example

<init-param>

<name>

javax.portlet.faces.bridgeEventHandlerjavax.portlet.faces.bridgeEventHandler

</name>

<value>

de.jsfportlets.handler.MyEventHandler

</value>

</init-param>

Page 42: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Portlet Events - example

public EventNavigationResult handleEvent(

FacesContext jsfContext, Event evt ) {

MyJSFBean myBean = Facade.getBean()

myBean.setNewValue( evt.getValue() );

return null;

}

Page 43: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Agenda

• Using JSR-301 / JSR-329

• From JSF to JSF-Portlets

• GenericFacesPortlet

•• Default view id

• Portlet events

• Public render parameter

Page 44: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Public render parameter

• Public render parameter are a new feature auf JSR-286, too. WithPublic render parameter can also be used to realized IPC (inter portletcommunication)

• You can define parameters as „public“ within portlet.xml

• Many portlets can work on the „same“ parameter. All Portlets can readand write them.

Page 45: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

PRP and the JSR-329 bridge

• Using the faces-config.xml, you can connect a public render parameterto a bean property

• Optionally, you can register a handler which will be triggered on changes

• In portlet.xml, the well-known configurations have to be done

Page 46: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

PRP - example

<application-extension>

<bridge:public-parameter-mappings>

faces-config.xml

<bridge:public-parameter-mappings>

<bridge:public-parameter-mapping>

<parameter>publicNews</parameter>

<model-el>#{NewsBean.publicNews}</model-el>

</bridge:public-parameter-mapping>

</bridge:public-parameter-mappings>

</application-extension></application-extension>

Page 47: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

PRP - example

<init-param>

<name>

javax.portlet.facesjavax.portlet.faces

.bridgePublicRenderParameterHandler

</name>

<value>

de.jsfportlets.MyPRPHandler

</value>

</init-param> </init-param>

Page 48: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

PRP - example

public void processUpdates(

FacesContext context) {

// TODO do something useful

}

Page 49: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Agenda

• Portals and Portlets

• Motivation for JSF+Portlets

•• Portlet Bridge Specification for JSF

• What is JSR-301?

What is JSR-329?

• Using JSR-301 and JSR-329

• Forecast: JSF 2.0 and Portlet 2.0

• Summary

Page 50: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

JSF 2.0 and Portlet 2.0

• No standard started yet

• Some groups started their own implementation

• Liferay started a new project: portletfaces.org

� http://www.portletfaces.org� http://www.portletfaces.org

• Also JBoss has a PortletBridge 3.0

• Features should be

• Annotation support (@ManagedBean etc)

• Ajax integration

• Viewhandler for Facelets• Viewhandler for Facelets

• Resourcehandler

• …

Page 51: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Conclusion

• There is a ready-to-use standard for the combination of JSF andPortlets

• You can focus on your JSF development. Afterwards you can bring • You can focus on your JSF development. Afterwards you can bring everything into a Portal.

• You can also use Portlet events and public render parameter withinJSF.

• Still waiting for a standardized bridge for JSF 2.0 ☺• Still waiting for a standardized bridge for JSF 2.0 ☺

Page 52: Independent Consultant - jazoon.com · Bridge Request Scope • In JSF, the complete life cycle is executed within one request. • In portlets, there are two requests. One for the

Thank you. Any questions?

More tutorials for JSFhere (German pages)

Or write an email:

here (German pages)

www.jsf-forum.de

English pages:

www.jsf-portlets.net

Or write an email:[email protected]