SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
1




A portlet-API based approach for application
integration




Wolfgang Habicht
Magnolia Conference, Basel




2009-09-10
2




Agenda

Motivation
Concept
The portlet API and portlet basics
Implementation details
Magnolia integration
Real world experiences & findings
3




Application Integration

Application integration is a generic problem
§ Not CMS specific
§ Depending on specific application issues

In general huge range of options
§ Link, IFrame, “merged” content, integrated menu
§ Adapting the application may be possible. Needed effort???
4




Discussed solution

Possible solution for
§ Seamless integration into Magnolia
§ Small, new applications

Portlet-API based approach offers:
§ Simple and flexible API
§ Dynamic flow over several pages
§ Different applications on the same page
§ Configuration in AdminCentral
5




Concept

§ Two-phase model
            Phase 1                   Phase 2




            action                    render


          Somewhere in filter chain    While page rendering
6




Interaction overview
7




Portlet

§ JSR-168 (and JSR-286)
§ Standard for developing portal components with Java
§ Run in a Portlet Container / Portal Server

§ Action / render phase
§ Simple API
8




Portlet API (simplified)

  interface Portlet
  {
    void init(PortletConfig);
    void processAction(ActionRequest, ActionResponse);
    void render(RenderRequest, RenderResponse);
    void destroy();
  }

  interface PortletRequest
  {
    Object getAttribute(String);
    Collection<String> getAttributeNames();
  }

  interface ActionRequest extends PortletRequest
  {
    String getParameter(String);
    String[] getParameterValues(String name);
    Collection<String> getParameterNames();
  }
9




Portlet API (simplified)

  interface Portlet
  {
    void init(PortletConfig);
    void processAction(ActionRequest, ActionResponse);
    void render(RenderRequest, RenderResponse);
    void destroy();
  }

  interface PortletRequest
  {
    Object getAttribute(String);
    Collection<String> getAttributeNames();
  }

  interface ActionRequest extends PortletRequest
  {
    String getParameter(String);
    String[] getParameterValues(String name);
    Collection<String> getParameterNames();
  }
10




Portlet API (simplified, continued)



  interface PortletResponse
  {
  }




  interface ActionResponse extends PortletResponse
  {
    void sendRedirect(String);
    void setRenderParameter(String, Object);
    HttpServletResponse handleResponseMyself();
  }
11




Portlet API (simplified, continued)

  interface RenderRequest extends PortletRequest
  {
  }


  interface RenderResponse extends PortletResponse
  {
    PortletURL createActionURL(String);
    Writer getWriter();
  }


  interface PortletURL
  {
    void setParameter(String, String)
    void setParameter(String, String[])
    String toString();
  }
12




Portlet API (simplified, continued)

  interface RenderRequest extends PortletRequest
  {
  }


  interface RenderResponse extends PortletResponse
  {
    PortletURL createActionURL(String);
    Writer getWriter();
  }


  interface PortletURL
  {
    void setParameter(String, String)
    void setParameter(String, String[])
    String toString();
  }
13




Portlet API usage example
public class DemoPortlet implements Portlet
{
  public void init(PortletConfig config) {
    String myJspTemplate = config.getParameters().get("myJspTemplate");
  }

    public void processAction(ActionRequest request, ActionResponse response) {
      String action = request.getAttribute(ActionRequest.ACTION_ATTRIBUTE_NAME);
      if ("redirect".equals(action))
        response.sendRedirect(request.getParameter("target"));
      response.setRenderParameter("jsp", myJspTemplate);
    }

    public void render(RenderRequest request, RenderResponse response) {
      Writer out = response.getWriter();
      PortletURL url = response.createActionURL("new_action");
      out.write("<a href="" + url.toString() + "">execute new_action</a>");

        String jspTemplateName = (String) request.getAttribute("jsp");
        ((WebContext) MgnlContext.getInstance()).include(jspTemplateName, out);
    }

    public void destroy() { }
}
14




Portlet API usage example
public class DemoPortlet implements Portlet
{
  public void init(PortletConfig config) {
    String myJspTemplate = config.getParameters().get("myJspTemplate");
  }

    public void processAction(ActionRequest request, ActionResponse response) {
      String action = request.getAttribute(ActionRequest.ACTION_ATTRIBUTE_NAME);
      if ("redirect".equals(action))
        response.sendRedirect(request.getParameter("target"));
      response.setRenderParameter("jsp", myJspTemplate);
    }

    public void render(RenderRequest request, RenderResponse response) {
      Writer out = response.getWriter();
      PortletURL url = response.createActionURL("new_action");
      out.write("<a href="" + url.toString() + "">execute new_action</a>");

        String jspTemplateName = (String) request.getAttribute("jsp");
        ((WebContext) MgnlContext.getInstance()).include(jspTemplateName, out);
    }

    public void destroy() { }
}
15




Portlet API usage example
public class DemoPortlet implements Portlet
{
  public void init(PortletConfig config) {
    String myJspTemplate = config.getParameters().get("myJspTemplate");
  }

    public void processAction(ActionRequest request, ActionResponse response) {
      String action = request.getAttribute(ActionRequest.ACTION_ATTRIBUTE_NAME);
      if ("redirect".equals(action))
        response.sendRedirect(request.getParameter("target"));
      response.setRenderParameter("jsp", myJspTemplate);
    }

    public void render(RenderRequest request, RenderResponse response) {
      Writer out = response.getWriter();
      PortletURL url = response.createActionURL("new_action");
      out.write("<a href="" + url.toString() + "">execute new_action</a>");

        String jspTemplateName = (String) request.getAttribute("jsp");
        ((WebContext) MgnlContext.getInstance()).include(jspTemplateName, out);
    }

    public void destroy() { }
}
16




createActionURL

Creates a link to the active portlet on the current
page with specified action

§ Use the original URI of the current request as target address
§ Set “action” and “portletId” parameters
§ Add all (other) parameters of the current request
17




API extensions



ActionResponse {
  HttpServletResponse handleResponseMyself();
}

§ Portlet must (and can!) do any further request handling
  itself
§ “Generalization” of the redirect concept
18




Reply caching

§ Not every page load has an “action” and “render” phase!

Example: Page with a shopping cart and a weather forecast
§ Remove one item of the shopping cart
§ Change the displayed location in the weather gadget
  à the last shopping cart action is “invalid”


Caching the RenderRequests for every portlet on the page
          allows independent portlet behaviour!

A basic principle in the portlet context
19




Implementation details

ActionRequestImpl:
  § Special handling for action and uuid
  § Needs access to HttpServletRequest
ActionResponseImpl:
  § Needs access to HttpServletResponse
  § Store redirect location if called
RenderRequestImpl:
  § Needs ActionResponse in constructor
RenderResponseImpl:
  § Needs HttpServletRequest and Writer in constructor
  § createActionURL(…)
20




Implementation details (2)

PortletURLImpl:
  § “Merge” parameters and action/portletId and create
     parameter string

PortletConfig:
  § Bean to provide the configuration (content2bean)
  § classname
  § portletId
  § Description
  § Map<String, String> parameters
21




Keeping the RenderRequest
§ Put portlet id, portlet object and RenderRequest in a
  container
§ Store container in session
§ G container is page-specific

On a request:
§ Check for action command à do it!
  § store in new container in session
§ Check for stored container entry
  § move to new container and keep in session
  § render it later during rendering
§ Call default action for missing entries and store them
§ Remove old container
22




Default action

Provide a default action per portlet and page

§ Place the same portlet on different pages with different
  functionality (i.e. login, logout, display data, edit data, …)
§ Simple and intuitive menu integration
§ Configure the default action on the page
§ Allows one portlet per application
  (in principle, different portlets could share the same data /
  state)
§ Transparent for the portlet!
23




Integration into Magnolia

Action phase:
§ Add a portlet filter
§ Alternative: action phase in template’s model (Mgnl 4.x)
  (in the paragraph’s model it’s already too late)



Render phase:
§ Called while rendering the paragraph containing the portlet
24




PortletFilter

 Get all portlets                                                    Call
                          Get action
 of current page                                                processAction


                             yes            Get default
                                              action
                                                                  Redirect?     yes
    Portlets                Have
                    yes                         no
    found?                 action?                                   no

                                       no
                                              Have
                                                                Store in new
       no                    yes            container     yes
                                                                 container
                                             entry?

  Remove old               More
                    no
   container              portlets?
25




Render a portlet

§ JSP or Freemarker-template with only one tag:
  <mgnlportlet:portlet/>
  (integrated in Magnolia as paragraph)

§ Tag implementation:
  § get portletId out of current content node
  § get portlet object and render request out of container
  § call portlet.render(…)
26




Configuration (backend)

§ configure portlet classname and portletId
§ content2bean à pass any configuration value(s)
27




Configuration (frontend)

Portlet-Paragraph to add Portlets
à choose portlet
  and default action




Alternativ: “PortletApps” with preconfigured values

Portlet-specific configuration values:
§ add subparagraph(s) inside your portlet
§ access values by iterating through JCR nodes
28




Advanced configuration (portlet config dialog)




                                            g
                                  g dialo
                         et c onfi
                     l
                 port
29




Advanced configuration (subparagraphs)



                                          g dialog
                               le t confi
                        port
30




Interaction overview (repetition)
31




Putting all together: seamless Magnolia integration
                      applicational pages


                                                      h
                                         r a g ra p
                                te xt pa




                                      para graph
                            portlet



   CMS (only) pages
32




Unaddressed issues



§ Caching
§ Deployment
§ Several applications on same page may conflict (due to
  redirects)
  à how should the applications behave?
§ Integration of 3rd party frameworks
33




Real world experiences

§ Used in production
§ Several applications integrated and live:
  § virtual portfolio system
  § serving personalized content (account information)
  § CSV download of table content
    (render into a CSV file instead of a HTML table)
  § form editor (for Magnolia 3.5 / 3.6)
  § wizards
34




Real world experiences (2)

§   Well-suited for small applications
§   Multi-page setup is fragile
§   Additional configuration inside the paragraph possible
§   Use “normal” CMS page for additional content (help, …)
§   Mixing of portlet-paragraphs and normal paragraphs on
    same page possible
35




Findings

  Intuitive and flexible
  Simple API (no specific framework to use)
  Proper model phase support
  Fusing with Magnolia (menu, mix paragraphs, …)

  Few programmer support
  Configuration dependencies (links to other pages)

  Complexity of bigger applications
36




Any Questions?

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Rails 6 frontend frameworks
Rails 6 frontend frameworksRails 6 frontend frameworks
Rails 6 frontend frameworks
 
Angular2 & ngrx/store: Game of States
Angular2 & ngrx/store: Game of StatesAngular2 & ngrx/store: Game of States
Angular2 & ngrx/store: Game of States
 
Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]Lap trinh web [Slide jsp]
Lap trinh web [Slide jsp]
 
50 new features of Java EE 7 in 50 minutes
50 new features of Java EE 7 in 50 minutes50 new features of Java EE 7 in 50 minutes
50 new features of Java EE 7 in 50 minutes
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte III
 
Simplified Android Development with Simple-Stack
Simplified Android Development with Simple-StackSimplified Android Development with Simple-Stack
Simplified Android Development with Simple-Stack
 
React + Redux. Best practices
React + Redux.  Best practicesReact + Redux.  Best practices
React + Redux. Best practices
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3
 
Workshop 26: React Native - The Native Side
Workshop 26: React Native - The Native SideWorkshop 26: React Native - The Native Side
Workshop 26: React Native - The Native Side
 
React & Redux
React & ReduxReact & Redux
React & Redux
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results Asynchrhonously
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
Redux vs Alt
Redux vs AltRedux vs Alt
Redux vs Alt
 
Practical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingPractical Protocol-Oriented-Programming
Practical Protocol-Oriented-Programming
 
React и redux
React и reduxReact и redux
React и redux
 
Spring MVC Annotations
Spring MVC AnnotationsSpring MVC Annotations
Spring MVC Annotations
 
Ngrx
NgrxNgrx
Ngrx
 
AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.AngularJs $provide API internals & circular dependency problem.
AngularJs $provide API internals & circular dependency problem.
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
 
Anton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 lightAnton Minashkin Dagger 2 light
Anton Minashkin Dagger 2 light
 

Destaque (7)

Computer Technician
Computer TechnicianComputer Technician
Computer Technician
 
B&G Fuel Systems Presentation
B&G Fuel Systems PresentationB&G Fuel Systems Presentation
B&G Fuel Systems Presentation
 
Ch1Notes
Ch1NotesCh1Notes
Ch1Notes
 
Il progetto sperimentale di Quadrifoglio
Il progetto sperimentale di QuadrifoglioIl progetto sperimentale di Quadrifoglio
Il progetto sperimentale di Quadrifoglio
 
Presentatiepoliticus20
Presentatiepoliticus20Presentatiepoliticus20
Presentatiepoliticus20
 
About Me
About MeAbout Me
About Me
 
animales
animalesanimales
animales
 

Semelhante a A portlet-API based approach for application integration

Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
Guy Nir
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts App
Syed Shahul
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
Alexey Buzdin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
C.T.Co
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
Yekmer Simsek
 

Semelhante a A portlet-API based approach for application integration (20)

Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
 
Arquitecturas de microservicios - Medianet Software
Arquitecturas de microservicios   -  Medianet SoftwareArquitecturas de microservicios   -  Medianet Software
Arquitecturas de microservicios - Medianet Software
 
May 2010 - RestEasy
May 2010 - RestEasyMay 2010 - RestEasy
May 2010 - RestEasy
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
Retrofit library for android
Retrofit library for androidRetrofit library for android
Retrofit library for android
 
Retrofit Library In Android
Retrofit Library In AndroidRetrofit Library In Android
Retrofit Library In Android
 
Step By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts AppStep By Step Guide For Buidling Simple Struts App
Step By Step Guide For Buidling Simple Struts App
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
Apache Wicket Web Framework
Apache Wicket Web FrameworkApache Wicket Web Framework
Apache Wicket Web Framework
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Training: Day Four - Struts, Tiles, Renders and Faces
Training: Day Four - Struts, Tiles, Renders and FacesTraining: Day Four - Struts, Tiles, Renders and Faces
Training: Day Four - Struts, Tiles, Renders and Faces
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet Basic
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platforms
 
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R AugeHTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortal
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

A portlet-API based approach for application integration

  • 1. 1 A portlet-API based approach for application integration Wolfgang Habicht Magnolia Conference, Basel 2009-09-10
  • 2. 2 Agenda Motivation Concept The portlet API and portlet basics Implementation details Magnolia integration Real world experiences & findings
  • 3. 3 Application Integration Application integration is a generic problem § Not CMS specific § Depending on specific application issues In general huge range of options § Link, IFrame, “merged” content, integrated menu § Adapting the application may be possible. Needed effort???
  • 4. 4 Discussed solution Possible solution for § Seamless integration into Magnolia § Small, new applications Portlet-API based approach offers: § Simple and flexible API § Dynamic flow over several pages § Different applications on the same page § Configuration in AdminCentral
  • 5. 5 Concept § Two-phase model Phase 1 Phase 2 action render Somewhere in filter chain While page rendering
  • 7. 7 Portlet § JSR-168 (and JSR-286) § Standard for developing portal components with Java § Run in a Portlet Container / Portal Server § Action / render phase § Simple API
  • 8. 8 Portlet API (simplified) interface Portlet { void init(PortletConfig); void processAction(ActionRequest, ActionResponse); void render(RenderRequest, RenderResponse); void destroy(); } interface PortletRequest { Object getAttribute(String); Collection<String> getAttributeNames(); } interface ActionRequest extends PortletRequest { String getParameter(String); String[] getParameterValues(String name); Collection<String> getParameterNames(); }
  • 9. 9 Portlet API (simplified) interface Portlet { void init(PortletConfig); void processAction(ActionRequest, ActionResponse); void render(RenderRequest, RenderResponse); void destroy(); } interface PortletRequest { Object getAttribute(String); Collection<String> getAttributeNames(); } interface ActionRequest extends PortletRequest { String getParameter(String); String[] getParameterValues(String name); Collection<String> getParameterNames(); }
  • 10. 10 Portlet API (simplified, continued) interface PortletResponse { } interface ActionResponse extends PortletResponse { void sendRedirect(String); void setRenderParameter(String, Object); HttpServletResponse handleResponseMyself(); }
  • 11. 11 Portlet API (simplified, continued) interface RenderRequest extends PortletRequest { } interface RenderResponse extends PortletResponse { PortletURL createActionURL(String); Writer getWriter(); } interface PortletURL { void setParameter(String, String) void setParameter(String, String[]) String toString(); }
  • 12. 12 Portlet API (simplified, continued) interface RenderRequest extends PortletRequest { } interface RenderResponse extends PortletResponse { PortletURL createActionURL(String); Writer getWriter(); } interface PortletURL { void setParameter(String, String) void setParameter(String, String[]) String toString(); }
  • 13. 13 Portlet API usage example public class DemoPortlet implements Portlet { public void init(PortletConfig config) { String myJspTemplate = config.getParameters().get("myJspTemplate"); } public void processAction(ActionRequest request, ActionResponse response) { String action = request.getAttribute(ActionRequest.ACTION_ATTRIBUTE_NAME); if ("redirect".equals(action)) response.sendRedirect(request.getParameter("target")); response.setRenderParameter("jsp", myJspTemplate); } public void render(RenderRequest request, RenderResponse response) { Writer out = response.getWriter(); PortletURL url = response.createActionURL("new_action"); out.write("<a href="" + url.toString() + "">execute new_action</a>"); String jspTemplateName = (String) request.getAttribute("jsp"); ((WebContext) MgnlContext.getInstance()).include(jspTemplateName, out); } public void destroy() { } }
  • 14. 14 Portlet API usage example public class DemoPortlet implements Portlet { public void init(PortletConfig config) { String myJspTemplate = config.getParameters().get("myJspTemplate"); } public void processAction(ActionRequest request, ActionResponse response) { String action = request.getAttribute(ActionRequest.ACTION_ATTRIBUTE_NAME); if ("redirect".equals(action)) response.sendRedirect(request.getParameter("target")); response.setRenderParameter("jsp", myJspTemplate); } public void render(RenderRequest request, RenderResponse response) { Writer out = response.getWriter(); PortletURL url = response.createActionURL("new_action"); out.write("<a href="" + url.toString() + "">execute new_action</a>"); String jspTemplateName = (String) request.getAttribute("jsp"); ((WebContext) MgnlContext.getInstance()).include(jspTemplateName, out); } public void destroy() { } }
  • 15. 15 Portlet API usage example public class DemoPortlet implements Portlet { public void init(PortletConfig config) { String myJspTemplate = config.getParameters().get("myJspTemplate"); } public void processAction(ActionRequest request, ActionResponse response) { String action = request.getAttribute(ActionRequest.ACTION_ATTRIBUTE_NAME); if ("redirect".equals(action)) response.sendRedirect(request.getParameter("target")); response.setRenderParameter("jsp", myJspTemplate); } public void render(RenderRequest request, RenderResponse response) { Writer out = response.getWriter(); PortletURL url = response.createActionURL("new_action"); out.write("<a href="" + url.toString() + "">execute new_action</a>"); String jspTemplateName = (String) request.getAttribute("jsp"); ((WebContext) MgnlContext.getInstance()).include(jspTemplateName, out); } public void destroy() { } }
  • 16. 16 createActionURL Creates a link to the active portlet on the current page with specified action § Use the original URI of the current request as target address § Set “action” and “portletId” parameters § Add all (other) parameters of the current request
  • 17. 17 API extensions ActionResponse { HttpServletResponse handleResponseMyself(); } § Portlet must (and can!) do any further request handling itself § “Generalization” of the redirect concept
  • 18. 18 Reply caching § Not every page load has an “action” and “render” phase! Example: Page with a shopping cart and a weather forecast § Remove one item of the shopping cart § Change the displayed location in the weather gadget à the last shopping cart action is “invalid” Caching the RenderRequests for every portlet on the page allows independent portlet behaviour! A basic principle in the portlet context
  • 19. 19 Implementation details ActionRequestImpl: § Special handling for action and uuid § Needs access to HttpServletRequest ActionResponseImpl: § Needs access to HttpServletResponse § Store redirect location if called RenderRequestImpl: § Needs ActionResponse in constructor RenderResponseImpl: § Needs HttpServletRequest and Writer in constructor § createActionURL(…)
  • 20. 20 Implementation details (2) PortletURLImpl: § “Merge” parameters and action/portletId and create parameter string PortletConfig: § Bean to provide the configuration (content2bean) § classname § portletId § Description § Map<String, String> parameters
  • 21. 21 Keeping the RenderRequest § Put portlet id, portlet object and RenderRequest in a container § Store container in session § G container is page-specific On a request: § Check for action command à do it! § store in new container in session § Check for stored container entry § move to new container and keep in session § render it later during rendering § Call default action for missing entries and store them § Remove old container
  • 22. 22 Default action Provide a default action per portlet and page § Place the same portlet on different pages with different functionality (i.e. login, logout, display data, edit data, …) § Simple and intuitive menu integration § Configure the default action on the page § Allows one portlet per application (in principle, different portlets could share the same data / state) § Transparent for the portlet!
  • 23. 23 Integration into Magnolia Action phase: § Add a portlet filter § Alternative: action phase in template’s model (Mgnl 4.x) (in the paragraph’s model it’s already too late) Render phase: § Called while rendering the paragraph containing the portlet
  • 24. 24 PortletFilter Get all portlets Call Get action of current page processAction yes Get default action Redirect? yes Portlets Have yes no found? action? no no Have Store in new no yes container yes container entry? Remove old More no container portlets?
  • 25. 25 Render a portlet § JSP or Freemarker-template with only one tag: <mgnlportlet:portlet/> (integrated in Magnolia as paragraph) § Tag implementation: § get portletId out of current content node § get portlet object and render request out of container § call portlet.render(…)
  • 26. 26 Configuration (backend) § configure portlet classname and portletId § content2bean à pass any configuration value(s)
  • 27. 27 Configuration (frontend) Portlet-Paragraph to add Portlets à choose portlet and default action Alternativ: “PortletApps” with preconfigured values Portlet-specific configuration values: § add subparagraph(s) inside your portlet § access values by iterating through JCR nodes
  • 28. 28 Advanced configuration (portlet config dialog) g g dialo et c onfi l port
  • 29. 29 Advanced configuration (subparagraphs) g dialog le t confi port
  • 31. 31 Putting all together: seamless Magnolia integration applicational pages h r a g ra p te xt pa para graph portlet CMS (only) pages
  • 32. 32 Unaddressed issues § Caching § Deployment § Several applications on same page may conflict (due to redirects) à how should the applications behave? § Integration of 3rd party frameworks
  • 33. 33 Real world experiences § Used in production § Several applications integrated and live: § virtual portfolio system § serving personalized content (account information) § CSV download of table content (render into a CSV file instead of a HTML table) § form editor (for Magnolia 3.5 / 3.6) § wizards
  • 34. 34 Real world experiences (2) § Well-suited for small applications § Multi-page setup is fragile § Additional configuration inside the paragraph possible § Use “normal” CMS page for additional content (help, …) § Mixing of portlet-paragraphs and normal paragraphs on same page possible
  • 35. 35 Findings Intuitive and flexible Simple API (no specific framework to use) Proper model phase support Fusing with Magnolia (menu, mix paragraphs, …) Few programmer support Configuration dependencies (links to other pages) Complexity of bigger applications