jsf2 liferay

Upload: emad-darvishi

Post on 04-Jun-2018

250 views

Category:

Documents


4 download

TRANSCRIPT

  • 8/13/2019 Jsf2 Liferay

    1/44

    Using JSF 2.x in Liferay PortalAndy Bosch, www.jsf-academy.com

  • 8/13/2019 Jsf2 Liferay

    2/44

    Agenda

    Portals and Portlets

    Motivation for JSF + PortletsJSR-301 and others: Portlet Bridge for JSFWhat is JSR-301?What is JSR-329?

    How does the Portlet Bridge work?JSF 2.x in Liferay Portal

  • 8/13/2019 Jsf2 Liferay

    3/44

    Who am I?

    Name: Andy Bosch

    Trainer, coach, developer,!Specialized in JSF and PortletsExpert Group member of JSR-301, JSR-329, and JSR-344Working with JSF since 2004

  • 8/13/2019 Jsf2 Liferay

    4/44

    Agenda

    Portals and Portlets

    Motivation for JSF + PortletsJSR-301 and others: Portlet Bridge for JSFWhat is JSR-301?What is JSR-329?

    How does the Portlet Bridge work?JSF 2.x in Liferay Portal

  • 8/13/2019 Jsf2 Liferay

    5/44

    Talking about real Portals

  • 8/13/2019 Jsf2 Liferay

    6/44

    Talking about real Portals

    Integration /

    Aggregation

    Personalisation

    Consistent

    look & feel

    SSO

  • 8/13/2019 Jsf2 Liferay

    7/44

    From Portals to Portlets

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

    Each fragment of a portal page is called a Portlet.That way, many portlets together form a portal page and many portalpages form a portal.

    ! In contrast to Portals, Portlets are standardized.The underlying standard is JSR-168.

    !The latest Portlet standard, JSR-286, was published in 2008.

  • 8/13/2019 Jsf2 Liferay

    8/44

    How does a Portlet work?

    A Portlet is triggered by the Portal (to be exact: by the Portletcontainer) to display itself (render phase).

    The Portlet container aggregates all fragments of the Portletsincluded 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), theaction phase of this Portlet is called. After calling the action phase,

    all Portlets will be rendered again.

  • 8/13/2019 Jsf2 Liferay

    9/44

    Life cycle of a Portlet (JSR-168)

    Init

    Render Action

    Destroy

    JSR-286 (Portlet V2) extends this life cycle.

  • 8/13/2019 Jsf2 Liferay

    10/44

    A very simple Portlet!

    public class SimplePortlet extends GenericPortlet{

    protected void doView( ... ) {

    PrintWriter writer = response.getWriter();

    writer.println( "Hello Portlet World" );

    String link = ....writer.println( "

    Click me" );

    }

    public voidprocessAction( ... ) {// TODO do some action logic

    }

    }

  • 8/13/2019 Jsf2 Liferay

    11/44

    Functionality within JSR-168

    Definition of the Portlet life cycle

    Interfaces and base classes(GenericPortlet and javax.portlet.Portlet)

    Window states and Portlet modesRequest and render parameterPortlet sessionsPortlet preferencesInclusion of JSP fragmentsPortlet tag library!Focus is on the Portlet itself

  • 8/13/2019 Jsf2 Liferay

    12/44

    Current specification: JSR-286

    Almost everything from JSR-168 is still valid

    Public render parametersPortlet eventsResource servingPortlet filtersBasis for AJAX integration!Focus is on the interaction of Portlets

  • 8/13/2019 Jsf2 Liferay

    13/44

    Agenda

    Portals and Portlets

    Motivation for JSF + PortletsJSR-301 and others: Portlet Bridge for JSFWhat is JSR-301?What is JSR-329?

    How does the Portlet Bridge work?JSF 2.x in Liferay Portal

  • 8/13/2019 Jsf2 Liferay

    14/44

    Building applications with plain Portlet functions?

    Programming with the Portlet spec is not very convenient.We are missing high level concepts like page flow, beanmanagement, conversion, validation, and many more.

    We would like to have modern UI components

    We have to combine the Portlet technology

    with a powerful user interface framework.

  • 8/13/2019 Jsf2 Liferay

    15/44

    The solution: JSF?

    JavaServer Faces is a framework specialized in the user interfaceJavaServer Faces is used in many projects in large and smallcompanies.

    JavaServer Faces features useful concepts like bean management,page flow, data conversion, and data validation

    JSF is also a standard.

  • 8/13/2019 Jsf2 Liferay

    16/44

    User interface components16

  • 8/13/2019 Jsf2 Liferay

    17/44

    JSF + Portlets: Isnt it easy?

    The problem is the glue code.

    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.

  • 8/13/2019 Jsf2 Liferay

    18/44

    Agenda

    Portals and portletsMotivation for JSF + PortletsJSR-301 and others: Portlet Bridge for JSFWhat is JSR-301?What is JSR-329?

    How does the Portlet Bridge work?JSF 2.x in Liferay Portal

  • 8/13/2019 Jsf2 Liferay

    19/44

    JSR-301: Portlet Bridge Specification for JavaServer

    Faces

    Started in December 2006Spec leader: Michael Freedman (Oracle)Goal is to provide a standardised bridge for executing JSFapplications within a portlet context.

    Another very important goal is to make the integration as simple aspossible for the application developer.

    To be more precise, there are two specs:JSR-301 = Portlet 1.0 (JSR-168) + JSF 1.2JSR-329 = Portlet 2.0 (JSR-286) + JSF 1.2 XXX = Portlet 2.0 (JSR-286) + JSF 2.x ?????????????

  • 8/13/2019 Jsf2 Liferay

    20/44

    High level overview

  • 8/13/2019 Jsf2 Liferay

    21/44

    Main challenge / goal

    Mapping of both life cycles

    JSF life cycle Portlet life cycle

  • 8/13/2019 Jsf2 Liferay

    22/44

    Mapping of life cycles: JSF

  • 8/13/2019 Jsf2 Liferay

    23/44

    Just to remind you: Portlet life cycle

    Init

    Render Action

    Destroy

  • 8/13/2019 Jsf2 Liferay

    24/44

    Mapping of life cycles: Bridge

  • 8/13/2019 Jsf2 Liferay

    25/44

    Mapping of life cycles: Bridge

  • 8/13/2019 Jsf2 Liferay

    26/44

    Bridge request scope

    In JSF, the entire life cycle is executed within one request.In Portlets, there are two requests, one for the render phase, one forthe action phase. The requests are independent of each other.

    That way, the bridge is responsible for supplying all the necessaryinformation for JSF, even if the life cycle is sub-divided into two

    phases.

    That means in detail: attributes from the action phase must be storedtemporarily by the bridge and set before executing a JSF render

    phase.

  • 8/13/2019 Jsf2 Liferay

    27/44

    Scopes for confusion (1)

    There is an JSF request scopeBut there is also a Portlet request(action request or render request)

    Storing a Managed Bean in the JSF request scope:What does in mean for the Portlet environment?

  • 8/13/2019 Jsf2 Liferay

    28/44

    Scopes for confusion (2)

    There is an JSF session scopeBut there is also a Portlet session.This session is devided into two parts:

    APPLICATION_SCOPE and PORTLET_SCOPE

    Storing a Managed Bean in the JSF session scope:Assigned to the Portlet PORTLET_SCOPE

    When aiming for IPC:Downcast and do it manually

  • 8/13/2019 Jsf2 Liferay

    29/44

    Using the Portlet Bridge

    1. Develop a normal JSF application2. Remove forbidden tags like , , etc.

    3. Include the JSR-301 / JSR-329 libs4. Provide a portlet.xml and adjust it

    5.

    Deploy and have fun"

  • 8/13/2019 Jsf2 Liferay

    30/44

    Agenda

    Portals and portletsMotivation for JSF + PortletsJSR-301 and others: Portlet Bridge for JSFWhat is JSR-301?What is JSR-329?

    How does the Portlet Bridge work?JSF 2.x in Liferay Portal

  • 8/13/2019 Jsf2 Liferay

    31/44

    JSF 2.x and Portlet 2.0

    No standard availableImplementation first approach to find the best possible solutionFor Liferay Portal (and perhaps others as well):www.portletfaces.org

    Base is the solution of the JSR-301/JSR-329 + extensions

  • 8/13/2019 Jsf2 Liferay

    32/44

  • 8/13/2019 Jsf2 Liferay

    33/44

    Liferay Faces

    Umbrella projectGoal is to support JSF in Liferay Portal

    Liferay Faces AlloyLiferay Faces BridgeLiferay Faces Portal

  • 8/13/2019 Jsf2 Liferay

    34/44

    Liferay Faces Bridge

    Supports the JSR-329JSF 2.0 and JSF 2.1 are supported (Mojarra and MyFaces)Should support ICEfaces, PrimeFaces and RichFaces

    Agenda for 2012: Alignment with JSR-344 (JSF 2.2)

  • 8/13/2019 Jsf2 Liferay

    35/44

    From theory to reality

    Write your JSF applicationProvide a portlet.xmlAdd the Liferay Faces Bridge jarsAdd some magic and it should work.

  • 8/13/2019 Jsf2 Liferay

    36/44

    Portlet definition

    MyPortlet

    javax.portlet.faces.GenericFacesPortlet

    javax.portlet.faces.defaultViewId.view

    /myGreatPage.xhtml

    ...

  • 8/13/2019 Jsf2 Liferay

    37/44

    Advanced units: Portlet events and JSR-329

    JSR-286 Portlets can send EventsJSR-286 Portlets can receive Events

    JSF can send Events in the sense of Portlets (that is communicatingwith other Portlets)

    So we have to bridge again between the two worlds

  • 8/13/2019 Jsf2 Liferay

    38/44

    Portlet Events: How to solve it?

    Register an event handler in portlet.xmlThe handler will be triggered upon incoming events.The handler provides you with access to the FacesContext.

  • 8/13/2019 Jsf2 Liferay

    39/44

    Portlet events - example

    javax.portlet.faces.bridgeEventHandler

    de.jsfportlets.handler.MyEventHandler

  • 8/13/2019 Jsf2 Liferay

    40/44

    Portlet events - example

    public EventNavigationResult

    handleEvent( FacesContext jsfContext,

    Event evt ) {

    MyJSFBean myBean = Facade.getBean()

    myBean.setNewValue( evt.getValue() );

    return null;

    }

  • 8/13/2019 Jsf2 Liferay

    41/44

    Back again to our confusion page

    Do you remember the different scopes?JSF request scope should last for one JSF request Within Portlets, it could live forever Within the Liferay Bridge, they decided to let theBridgeRequestScope end with the end of the RenderRequest.

    ...

  • 8/13/2019 Jsf2 Liferay

    42/44

    More on the way

    Public Render Parameters are supported as wellPortlet Preferences can be evaluated automaticallyLiferay Faces already has an upload componentExtended EL possibilities (access to portlet specific objects) ...

  • 8/13/2019 Jsf2 Liferay

    43/44

    Conclusion

    General statement: A combination of JSF and Portlets is possible.You have to use specific bridges for JSF 2.x. There is no generalstandard.

    The bridge, specifically for Liferay, works quite good and looks verymature. But including JSF Component Libraries could be a pain.

    Hoping for a JSR to come!

  • 8/13/2019 Jsf2 Liferay

    44/44

    Do you have questions?

    !" $"%&' () '*+(%, &-.

    !"#$%&'()*+,(-.!)!#/0$%)'0

    /-,,-$ +' -) 0$%1'".

    +!"#$&'()*