Developing Portlets With Java Server Faces Dave Meredith NGS Grid Development, e-Science Centre, Daresbury Laboratory, UK

Slides:



Advertisements
Similar presentations
A Toolbox for Blackboard Tim Roberts
Advertisements

JSF Portlet Backing Beans and UI Components Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in.
Apache Struts Technology
My First Building Block Presented By Tracy Engwirda 28 September, 2005.
JBoss Seam: Contextual Components Jason Bechtel
Internet Technologies 1 Master of Information System Management Java Server Faces Model/View/Controller Design Pattern for Web Development Slides.
WEB1P servintro1 Introduction to servlets and JSP Dr Jim Briggs.
Objectives:1. Investigate the Web application deployment descriptor 2. Install and deploy Tomcat and struts 3. Design and deploy a struts application Struts.
Tomcat Configuration A Very, Very, Very Brief Overview.
Apache Struts Technology A MVC Framework for Java Web Applications.
Web Applications Basics. Introduction to Web Web features Clent/Server HTTP HyperText Markup Language URL addresses Web server - a computer program that.
ECE356 – Database Systems Lab 1 – Building a Web Project with NetBeans Tiuley Alguindigue Lab Instructor – University of Waterloo, E & CE Dept. Fall 2013.
Portals and portlets Sean C. Sullivan October 24, 2006 Portland Java Users Group.
JSF Portlet Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
Introduction to Java web programming Dr Jim Briggs JWP intro1.
Grid (Portal) Application Development (Approaches, Best Practices, API choices, IOC/DI) David Meredith NGS + Grid Technology Group, e-Science Centre, Daresbury.
Sakai Architecture Charles Severance / Glenn Golden University of Michigan.
Lecture 2 - Struts ENTERPRISE JAVA. 2 Contents  Servlet Deployment  Servlet Filters  Model View Controllers  Struts  Dependency Injection.
Overview of JSP Technology. The need of JSP With servlets, it is easy to – Read form data – Read HTTP request headers – Set HTTP status codes and response.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
WebWork in Action An introduction to WebWork Patrick A. Lightbody.
JavaServer Faces: The Fundamentals Compiled from Sun TechDays workshops (JSF Basics, Web-Tier Codecamp: JavaServer Faces, Java Studio Creator; IBM RAD)
Java Server Faces Çağatay Çivici Apache MyFaces Team Member
Pittsburgh Java User Group– Dec Java PureFaces: A JSF Framework Extension.
© 2005 by IBM; made available under the EPL v1.0 | March 1, 2005 Tim deBoer Gorkem Ercan Extend WTP Server Tools for your.
1 Introduction to JavaServerFaces & MyFaces Anudeep Jassal.
JDeveloper 10g and JavaServer Faces: High-Performance UIs on the Web Avrom Roy-Faderman Senior Programmer May, 2006.
CS441 CURRENT TOPICS IN PROGRAMMING LANGUAGES LECTURE 5_1 George Koutsogiannakis/ Summer
JavaServer Faces Jeff Schmitt October 5, Introduction to JSF Presents a standard framework for building presentation tiers for web applications.
Design Patterns Phil Smith 28 th November Design Patterns There are many ways to produce content via Servlets and JSPs Understanding the good, the.
Java Server Pages A JSP page is a text-based document that contains two types of text: static template data, which can be expressed in any text-based format,
© 2006 IBM Corporation IBM WebSphere Portlet Factory Architecture.
|Tecnologie Web L-A Anno Accademico Laboratorio di Tecnologie Web Introduzione ad Eclipse e Tomcat
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
JSF Introduction Copyright © Liferay, Inc. All Rights Reserved. No material may be reproduced electronically or in print without written permission.
CHEF II / Sakai Architecture. CHEF II Changes uPortal replaces Jetspeed –jsr 168 portlet, servlet compliant Spring replaces Turbine component framework.
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Fall CIS 764 Database Systems Design L8. Web ….
1 ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 1 Building Portlets with ColdFusion Pete Freitag Foundeo, Inc.
J2EE Overview Web Programming CSCI J2EE multi-tier architecture Servlet: Java class loaded into Web server JSP page: enhanced HTML page that is.
Java Web Development with NetBeans IDE -- Kai Qian Chapter 5 JavaServer Faces (JSF) Technology.
BOF # The Struts Framework Community The Struts Framework Community Craig McClanahan.
Java Portals and Portlets Submitted By: Rashi Chopra CIS 764 Fall 2007 Rashi Chopra.
JAVA SERVER FACES ADITI RAJORIYA UNI – ar2630. POINTS TO BE DISSCUSED WHAT IS JSF? WHY JSF? ARCHITECTURE JSF VERSIONS UI COMPONENTS JSF STRUCTURE AND.
JSF Framework Java Server Faces Presented by Songkran Totiya (6/10/2014)
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
GLOCO – Integrated Corporate Portal Part 2 - Technical Specification Presented by Team 3 1 Team 3 Members: Joyce Torres Kenneth Kittredge Pamela Fisher.
Portlets 1.
The NGS Grid Portal David Meredith NGS + Grid Technology Group, e-Science Centre, Daresbury Laboratory, UK
Chính phủ điện tử TS. Phạm Văn Tính Khoa CNTT, ĐH Nông Lâm TP.HCM
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 41 JavaServer Face.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Spring MVC Essentials Getting started.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
1 Copyright © 2004, Oracle. All rights reserved. Oracle Application Development Framework.
JavaServer Faces framework Craig McClanahan is presented that created Struts web framework and based on experience gathered designed JavaServer.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
® IBM Software Group © 2003 IBM Corporation IBM WebSphere Studio V5.1.2: Making Java Development Easier May 2004.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
The NGS Grid Portal David Meredith NGS + Grid Technology Group, e-Science Centre, Daresbury Laboratory, UK
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
APACHE STRUTS ASHISH SINGH TOMAR ast2124. OUTLINE Introduction The Model-View-Controller Design Pattern Struts’ implementation of the MVC Pattern Additional.
SDJ INFOSOFT PVT. LTD. 2 BROWSERBROWSER JSP JavaBean DB Req Res Application Layer Enterprise server/Data Sources.
Apache Struts Technology A MVC Framework for Java Web Applications.
BlueDragon Editions and Advantages Lori Pacheco New Atlanta.
Introduction to Java Server Faces (covered topics) ● Reasons to use „Java Server Faces“ ● JSF application structure ● JSF component model ● JSF managed.
Intro to JavaServer Faces Mimi Opkins CECS 493 Fall 2016.
Examples with Java Server Faces (covered topics)
Sri Vatsav Konreddy CIS 764 FALL 2007
JavaServer Faces: The Fundamentals
Presentation transcript:

Developing Portlets With Java Server Faces Dave Meredith NGS Grid Development, e-Science Centre, Daresbury Laboratory, UK

Overview JSR 168 – Some Comments Why develop portlets with Java Server Faces Required Steps to Deploy a JSF Web Application as a Portlet Some Development Issues Summary / Useful Links

JSR 168 – Some Comments Assumes developers will be happy to ignore other (well known) development development frameworks like Velocity, Struts, and Java Server Faces and learn new Portlet API.  168 nvolves developing a GenericPortlet extension for every single portlet they develop.  Can result in complicated processAction() and doView() methods.  Will have to replicate functionality that is provided with web app framework.  Assumes developers will be happy with the JSR 168 portlet-style Model-View-Controller. Fortunately, it is possible to map these other web application frameworks to portlet actions (portal bridges – e.g. Struts portal bridge).

Why Develop Portlets with Java Server Faces ? JSF designed from the outset to be compatible with portals/ portlets. Some other frameworks involve quite complex portal-bridges – have heard using a portal bridge is comparable to ‘trying to fit a square peg in a round hole.’ (Stan Silvert, Java One Online 2005) Can deploy a JSF web application either as a standalone web application, or as a portlet for inclusion in a JSR168 portal container. Existing JSF Applications can be (semi-transparently) deployed as a Portlet application. Helps move away from common notion that portlets are mostly small apps. This requires a little (or no modification) – steps to do this will be shown later in talk.

Same JSF Application Deployed in Pluto Portal Container as Single Portlet JSF Application Deployed As Standalone Web Application (Cog4, JPA + Hibernate, JSF, JSDL, Jargon, JAX-WS, Vine ?)

Why Develop Portlets with Java Server Faces ? Same reasons as for developing regular JSF web applications JSF is standard Powerful MVC programming framework for building (large) Web Applications: Enforces good structuring of code – cleanly splits view from model Well defined navigation rules Managed beans / backing beans for logic (POJOs) Event handling (action events, action listeners, value-change events, phase listeners) Can interact with JSF processing lifecycle at different levels – (v.powerful if required) Powerful form validation Dependency injection via “faces-config.xml” file Not dependent on J2EE Application Server (can run is servlet container like Tomcat) Reusable UI components: e.g. tabbed panes, scrolling tables, calendars, hierarchical trees, table models.....etc Apache MyFaces has over 100 reusable components with addition of Oracle ADF (Trinidad). Future – AJAX enabled UI components (hope it will save me from having to learn AJAX and JS) Good tool support: e.g. drag 'n' drop design of JSF components in JSP using Sun Studio Creator. Developers may already be familiar with JSF: – have own code base (for me, this was a strong reason that I started to develop portlets with JSF).

In JSP (View - No logic / scriptlets ): <h:inputText id="jsdlNameInputText" value="#{ActiveJobProfile.name}" required=”true” validator="#{ActiveJobProfile.validateName}" valueChangeListener="#{ActiveJobProfile.valueChangeName}" /> In Backing Bean (Model): public class ActiveJobProfileBean implements Serializable { private String name; public void validateName(FacesContext context, UIComponent component, Object val) throws ValidatorException { /**TODO implement validation logic, throw ValidatorException if 'val' is incorrect */ } public void valueChangeName(ValueChangeEvent event){ /**TODO implement logic if value has changed */ } Why Develop Portlets with Java Server Faces ? Enforces good structuring of code Backing Beans are POJO’s with no dependency on container. Beans define logic. Display values of bean attributes in jsp view. Call bean methods to perform logic (actions, value change events, validators)

<!-- One shared DB Util object in application scope (creates single JPA EntityManagerFactory and serves ThreadLocal EntityManager instances ) --> J2seEntityManagerUtil org.davemeredith.J2seEntityManagerUtil application persistenceUnitName NgsJobProfileDbHibernateJ2SE JobProfileBO uk.ac.escience.ngs.portal.jobSubmit.dbBO.JobProfileBO application entityManagerUtil #{J2seEntityManagerUtil} ActiveJobProfile uk.ac.escience.ngs.portal.jobSubmit.ActiveJobProfileBean session jobProfileBO #{JobProfileBO} Why Develop Portlets with Java Server Faces ? JSF Dependency Injection (can ‘order’ the injection sequence, - no need for listeners !) (In faces-config.xml)

Overview Why develop portlets with Java Server Faces Required Steps to Deploy a JSF Web Application as a Portlet Some Development Issues Summary / Useful Links

Required Steps to Deploy a JSF Web Application as a Portlet 1) Make necessary modifications to your code: a) Use JSF navigation rules only b) Use abstracted ExternalContext in web application logic 2) Create portlet.xml deployment descriptor for your JSF application 3) Add jsf-portlet.jar to WEB-INF/lib of your application (JSF RI only, not necessary when using Apache MyFaces) 4) Package JSF portlet into a deployable.war file 4) Deploy JSF portlet application to your portal container and register it with the portal so it can be viewed within the portal interface (specifics vary according to the portal container you are using)

a) Ensure page navigation in web application is implemented by JSF navigation rules only (remove any re-direct links). JSF components are rendered so that URL processing is delegated to a ViewHandler which can either create portlet URLs if hosted in a portal, or a FacesServlet URLs if a regular JSF app. Remove links/re-directs: Back With JSF navigation rules: (In faces-config.xml) goActiveJobProfile /ActiveJobProfile.jsp (In Jsp) 1) Make Some Necessary Modifications to Your Code

b) A JSF portlet application must not rely on any servlet-specific APIs Use abstracted 'ExternalContext' class to get access to methods and objects that you would normally get from HttpServletRequest, HttpServletResponse, ServletContext. /** to get the ExternalContext */ FacesContext fc = FacesContext.getCurrentInstance(); ExternalContext ec = fc.getExternalContext(); /** wrong ! */ HttpServletRequest req = (HttpServletRequest) ec.getRequest(); Map paramMap = req.getParameterMap(); String cp = req.getContextPath(); Cookies[] cookies = req.getCookies(); /** right ! */ Map paramMap = ec.getRequestParameterMap(); String cp = ec.getRequestContextPath(); Map cookies = ec.getRequestCookieMap(); /** useful functions for portlet deployment */ String remoteUserUUID = ec.getRemoteUser(); boolean inRole = ec.isUserInRole("userA"); c) Ensure 3 rd party libs / packages / dependencies can be deployed to target container (some issues with shared libs and web-app/WEB-INF/libs and security) 1) Make Some Necessary Modifications to Your Code

2) Create a portlet.xml Deployment Descriptor for JSF web application (using JSF Reference Implementation) NgsJobSubmit_Portlet com.sun.faces.portlet.FacesPortlet com.sun.faces.portlet.INIT_VIEW /index.jsp 0 text/html VIEW en NgsJobSubmit_Portlet NGS, HPC, Job Submission JSF RI does not have a concept of modes, so you (usually) need to disable EDIT and HELP modes in portlet.xml.

NgsJobSubmit_Portlet org.apache.myfaces.portlet.MyFacesGenericPortlet default-view /ActiveJobProfile.jsp 0 text/html VIEW en NgsJobSubmit_Portlet NGS, HPC, Job Submission MyFaces can support EDIT and HELP modes by subclassing MyFacesGenericPortlet. Only supported with MyFaces ) Create a portlet.xml Deployment Descriptor for JSF web application (using Apache MyFaces)

jsf-portlet.jar is the portlet integration library that must reside with your application in the WEB-INF/lib subdirectory. That way, your application can run as a portlet. javaserverfaces_portlet.class Go to and download javaserverfaces_portlet.class (look under Documents & Files menu item) Use"java -cp. javaserverfaces_portlet.class" to install. Based on JSF 1.x release This generates jsf-portlet.jar or, use jsf-portlet.jar that comes with Sun Studio Creator (free download). Also has a project template for creating a JSF portlet using the JSF RI. 3) Add jsf-portlet.jar to WEB-INF/lib of your application (JSF Reference Implementation)

4) Deploy JSF portlet application to your portal container and register it with the portal This is different according to the portlet container you are using. For Pluto (Reference Implementation of JSR 168 portlet container), modify 3 Pluto files and add some Pluto boilerplate code to web.xml: Pluto Files to Modify: /webapps/pluto/WEB-INF/data/ portletcontext.txt portletentityregistry.xml pageregistry.xml a) portletcontext.txt (lists the context path of each portlet application) /testsuite /pluto /SimpleMyFacesPortletsMixed /SimpleRIPortlet /chapter04 /chapter05 /NgsJobSubmissionPortlet1

b) portletentityregistry.xml (registers the portlet with the portal container) NgsJobSubmissionPortlet1. ” --> NgsJobSubmissionPortlet1.NgsJobSubmit_Portlet

c) pageregistry.xml (defines the layout of the portlets in the portal) NgsJobSubmit NGS Job Submission / JSDL Job Profiles Portlet. -->

NgsJobSubmit_PortletServlet NgsJobSubmit_Portlet Wrapper Automated generated Portlet Wrapper org.apache.pluto.core.PortletServlet portlet-guid. --> NgsJobSubmissionPortlet1.NgsJobSubmit_Portlet portlet-class org.apache.myfaces.portlet.MyFacesGenericPortlet NgsJobSubmit_PortletServlet /NgsJobSubmit_PortletServlet/* Add Pluto boilerplate code to web.xml Define a new servlet mapping that wraps the JSF portlet. Note, this code is added when you use Pluto hot-deploy page

Overview Why develop portlets with Java Server Faces Required Steps to Deploy a JSF Web Application as a Portlet Some Development Issues Summary / Useful Links

Some Development Issues 1) Mixing JSF portlets with other portlets in the same portlet application A portal container can host multiple JSF and 168 portlets in the same portal. portal |_ webapps/ |_ 168 portlet application (.war) Portlet applications must communicate |_ JSF portlet application (.war) by an external mechanism (e.g. db, |_ JSF portlet application (.war) Web services) |_ 168 portlet application (.war) However, only one JSF portlet can be integrated into a single portlet application. The problem of inter-portlet communication still exists – (wait for JSR 286).war |_ WEB-INF/ |_ |_ Can write a single portlet application |_ with one JSF portlet and multiple 168 |_ portlets (all share same portlet application |_ session and share data)..war |_ WEB-INF/ |_ |_ Cant write a single portlet application |_ with more than one JSF portlet |_

Some Development Issues 2) web.xml Versioning In Pluto, I could only deploy a JSF portlet application if web.xml is based on web app version 2.3.dtd, not version 2.4.xsd (may be resolved with later releases of pluto) <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" " <web-app xmlns=" xmlns:xsi=" xsi:schemaLocation=" version="2.4">.... 3) Have not yet tried JSF 1.2 JSF 1.2 provides new unified expression language (unified EL), which is essentially an amalgamation of the JSP EL and the JavaServer Faces 1.1_01 EL.

Turn off MyFaces AutoScroll org.apache.myfaces.AUTO_SCROLL false Client State Saving Method, not as Server <!-- Specify where the state should be saved. If state is saved on client, the state of the entire view is rendered to a hidden field on the page. JSR-168 independent but seems buggy when "server" specified (makes sense as are depending more on the portlet container ??) --> javax.faces.STATE_SAVING_METHOD client

Apache MyFaces / Trinidad JSF home Good talk on portlet development with JSF (Building Killer Portlets with JSF – Stan Silvert, Java One Online, 2005) Summary JSF (in my opinion), is a viable framework for the development of powerful web-application like portlets (and standalone web apps). Can deploy existing JSF Web apps as a single portlet. JSF is a standard – always best for future support. There are a few ‘gotchas’ that developers need to be aware of. Intra-portlet communication the main problem, (believe this will be addressed in JSR 286).

A portlet is a piece of Java code that manages the content of one section of a web portal’s HTML. It can do anything else that a Java web application can do.  You can connect a portlet to a database, invoke a web service, download an RSS feed, etc. It lives in a portlet container, which creates, manages, and destroys all the portlets of the portal. Portlet containers are part of portals.  Portals must do other things like manage login, users, groups, layouts, etc. JSR 168 standardizes two main things:  How the portlet container manages portlet lifecycles  How the portlets are programmed.