SlideShare a Scribd company logo
Session Number:  D22 Jump START your Portlet development with Open Source Frameworks! Sean Newby, Perficient Sunil Patil, Ascendant Technology LLC Peter Blinstrubas, IBM
Agenda IBM Portlet Development Perspective Struts 2.0  Spring 2.0
 IBM Portlet Development Perspective Email: peteblin@us.ibm.com
Why Use a Framework for Portlet Development? Starts off small and later is enhanced. Model View Controller well established. Provides separation between different layers Frameworks force developers into using a standard approach when building applications Shield some of the underlying complexity of developing an application.  Provides interfaces or abstract classes to speed and structure your development effort. Options Write the portlet in portal api Develop a custom framework for portlet development. Port servlet world framework to the portlet world Use an existing framework!
Frameworks for Portlet Development IBM  Frameworks Just the Portlet API WebSphere Portlet Factory AJAX based on DOJO JSF V1.1 on Portal 6.x  with  JWL 3.0 JSF 1.2 for Portal running on WAS 7  (plans subject to change) AJAX Struts Apache Bridge for JSR 168 Container on WAS 6.1 Currently Struts Portlet Framework supports Struts 1.1 and 1.29 Alternative Frameworks Custom MVC Spring 2.0 Struts 2.0 Many More… (i.e. Shale, Wicket,…)
What is the Struts Portlet Framework? Runtime  A package that supports Struts application in Portal. Includes a level of Struts (1.1 and 1.29) A portlet controller and a request processor. Implementations of some of the Struts tags  Tool Set Flow Editor for creating and wiring pages and actions together A full Struts-Config editor Link validation and re-factoring for Struts specific links Wizards for creating Actions, Struts JSPs and Form Beans Page Designer Visualizations for some Struts-html tags Full Page Designer Palette for Struts Tags
What is the Struts Portlet Framework? Support for writing/migrating Struts applications that can be deployed in WebSphere Portal  Also provides samples to show how portal features can be incorporated by Struts applications
Struts 1.x in General Struts is: Controller based framework Struts does not have: A built-in UI component model A built-in event model for UI components A built-in state management for UI components A built-in support of multiple renderers (Struts is more or less tied up with HTML) Struts is Not a standard (despite its popularity) IBM has no plans to continue SPF Development. Recommended for Legacy Struts Applications. Also consider Apache Bridge
IBM and JSF Part of Java EE 5 Participation in JSR Expert Group J2EE-based Web UI and application framework WPLC Underlying technology in Composite Application Designer Used in Portal Workflow portlets Being incorporated into Lotus Expeditor Widgets in Portlet Factory Recommended for new portlet development Note: Refer to session D12 for JSF details
JSF General Benefits Reusable UI Components Custom Tag Libraries API for managing UI components, events, input navigation, page navigation Addresses complex navigation requirements Extensible - Everything is pluggable Rich tooling support Flexible Actions: different navigations for multiple components on a single page Supports Expression  Built in state management Concerns Complexity Still relatively new Out of the box capability to meet requirements Availability of skills
Plug-in to Eclipse & Rational Application Developer Multi-page custom portlets/applications without coding Integration capabilities (SAP, Domino, PeopleSoft, Siebel, Web Services, Databases, Portal Content Repository) Service-oriented development Support for Portal features such as portlet communication, business user configuration, auto-deploy, single sign-on “ Dynamic profiling” capability, to create multiple variations from a single set of source portlets WebSphere Portlet Factory  Rapid Portlet Creation and Customization Tooling IBM WebSphere Portlet Factory  simplifies  &  accelerates  the development, deployment, maintenance, and reuse of custom portlets and applications.
Portlet Factory General Benefits DataCentric Applications Expand Portlet Creation to developers of all skill level Captures Design Patterns/Standardize Development Model Lots of adapters Strong XML/Web Service support Code generation technology protects investment Protecting against backend product upgrades Concerns New vocabulary (learning curve) Complex application, process intensive
There are so many choices? Portlet API JSF Framework Struts Portlet Framework Struts 2.0 My Servlet Framework There may be many valid and not so valid reasons to consider. Portlet Factory Spring 2.0 Apache Bridge
 Apache Struts 2.0: Sunil Patil, Senior Consultant, Ascendant Technology LLC Email: spatil@atech.com
Struts 2.0 Introduction Action Framework, allows you to map URL to Action Class Missing features of Apache Struts 1.0 will be ported to Struts 2.0 OpenSymphony’s WebWorks framework will cease to exists WebWorks will only release patches for existing versions. The WebWorks framework has built-in support for JSR-168 portlet development Architecture based on OpenSymphony’s WebWorks Framework Command pattern implementation Actions are command objects
Client Selection Example At previous client using Apache Struts 2.0 framework Reasons Struts 2.0 framework is considered Customer wanted precise control on the Portlet Screens Customer wanted to use common look and feel across all portlets Has considered JSF, but developing custom components in JSF requires lot of work Developers already had experience on Apache Struts 1.0, easy migration Provides clear separation between Action and Render phase
Key Struts 2.0 objects/concepts Jsr168Dispatcher: The Controller portlet that handles all requests to the portlet application. Similar to ActionServlet in Struts 1.0 framework Action Jsr168Dispatcher passed request to configured Action to handle request. Combines ActionForm, Action and Model class Location in framework where you write you business logic. Results Different view technologies are supported JSP Velocity Freemarker
Key Struts 2.0 objects/concepts Cont. Interceptor Interceptors are one of the most powerful features of Struts 2.0 framework Interceptors are similar to Filters in servlet environment, they allow you to execute your code before and after Action. Common functionality is implemented as interceptor Setting parameters Validation workflow Value Stack Used for carrying data from action class to JSP page Value Stack, Stack of objects Temporary Objects Action Object Named object
Struts : Forward to JSP request flow
Struts : Forward to Action request flow
Main Artifacts
Additions to portlet.xml Jsr168Dispatcher is portlet dispatcher class viewNameSpace defines default namespace for view mode defaultViewAction defines default action for view mode
Additions to web.xml Configure to setup PreparatorServlet Configure to setup spring integration
Struts Configuration Import default configuration from struts-portlet-default.xml Divide configuration in different namespaces
Struts Action Optionally extend from ActionSupport class Combines Action, ActionForm and Model class The execute() method does not take PortletRequest and PortletResponse object
Struts Action contd. Setting form values in Contact class No need for contactList, model class
Struts JSP OGNL expressions for reading values from Value stack Read i18n messages from <ActionClass>.properties file Struts tags use Freemarker Template for generating markup You can extend tag by overriding template XHTML Theme - No HTML Markup in the JSP
Struts Tags The form field tag is responsible for Generating two column layout Generating form elements as well as surrounding table element Every form field tag is responsible for generating one row in table Display label on the left side of the form field Display actual form field on the right side Display the field error above the form field <s:textfield label=&quot;Name&quot; name=&quot;contact.firstName&quot;/>   rendered as (with error message)
Struts Tags contd. This is how datepicker form field and popup look like <s:datetimepicker label=&quot;DOB&quot; name=&quot;contact.dateOfBirth&quot;/> rendered as
Support for Different View Technologies Same tag library available in JSP, Freemarker and Velocity Insert.ftl insert.vm
Form Validation in Struts 2.0 Can be use several different types Programmatically by implementing validate() method in Action class Declaratively using XWork’s Validation framework Client side validation Create <ActionClass>-validation.xml Sample uses of XWork validation
Type Conversion Routine type conversion in the framework is transparent Boolean, boolean, Integrer, int, Float, float, Long, log, Double, double Date with the locale associated with current request Register custom type conversion class <ActionClass>-conversion.properties for class specific conversion Point=com.ascendant.converter.PointConverter Xwork-conversion-properties for global conversion Custom type conversion for more complex objects Create class extending StrutsTypeConverter class convertFromString() convertToString()
Struts Plug-ins Many popular optional features of the framework are distributed as plug-ins Spring Tiles File upload Plug-ins are used for Introducing new Extension point implementation class ObjectFactory : Spring plug-in implements StrutsSpringObjectFactory Mutlipart parser: Allows using Pell’s multi part parser for parsing multi-part request Define new packages with results, interceptors or actions Results: Tiles plug-in introduces Tiles Results type Override framework constants
Spring Integration Allows Actions, Interceptors and Results to be created by Spring Struts created object can be auto wired by spring after creation Provides two interceptors that auto wire actions if not using the Spring Objectfactory  Add entry for StrutsSpringObjectFactory in struts.properties struts.objectFactory = org.apache.struts2.spring.StrutsSpringObjectFactory
 Spring 2.0: Sean Newby, Senior Consultant, Perficient Inc. Email: sean.newby@perficient.com
Spring Intro Spring is a popular Java Application Framework that has gained significant momentum in the past few years. Made up of several modules that can be used independently Inversion of Control Container (Core) AOP module  DAO module MVC module  Portlet MVC became a part of the general Spring 2.0 release in November of 2006.
Client Selection Example At a previous client that decided to Spring MVC. Reasons Spring MVC was selected. Similar in design to IBM Struts implementation.  Had considered JSF, but no developers had any experience.  JSF seemed to be more of a paradigm shift. Developers already had experience with other elements of Spring. Confident that would be able to find answers to issues in the Spring community. Addressed use case we needed to solve (Wizard Portlet). Designed around portlet api, addressed Render and Action separately.
Key Portlet MVC objects / concepts  DispatcherPortlet The controller portlet that handles all requests to the portlet application.  Similar to ActionPortlet or ActionServlet in the Struts framework. Controller Location in Framework where your code begins.  Similar to Struts Action class. DispatcherPortlet passed request to configured Controller to handle request.  Separate methods for render and action phases. Several default implementations to handle common use cases: ParameterizableViewController – Simple controller that passes to a view. SimpleFormController – Controller to handle form submissions. AbstractWizardController – Controller to implement wizard like form.  Form that extends over several pages. HandlerMapping Determines which Controller will be called. Several out of the box implementations.
Key Portlet MVC objects / concepts cont. ModelAndView Object that is returned by Controllers to DispatcherPortlet. Contains the Model that needs to be displayed by the view.  Also contains the “name” of the view. Behavior is similar to a regular Map object. ViewResolver Maintains a clean separation of View technology. Several Default ViewResolvers JSP Velocity XSLT Command Objects JavaBean type objects.  Object is bound to request parameters, usually from form submission.  Similar to Struts ActionForm, except is does not extend framework specific class.
Simplified Render Sequence Diagram Some steps have been omitted for clarity.
Simplified Action Sequence Diagram Some steps have been omitted for clarity.
Getting Started setting up a Spring Portlet WEB-INF/web.xml and WEB-INF/portlet.xml WEB-INF/context/applicationContext.xml – main application wide config file.  Values can be overridden in portlet config. WEB-INF/<PORTLETNAME>-portlet.xml – individual config file for each portlet. WEB-INF/lib/spring.jar – main spring file.* WEB-INF/lib/spring-portlet.jar – additions for Spring Portlet MVC WEB-INF/lib/spring-modules-validation.jar – additions for validation of forms. *could pick out specific Spring jar’s to reduce size of application.
Main Artifacts
Additions to Web.xml Configuration to set up Spring MVC servlet. Portlet MVC leverages Servlet base code.
Portlet.xml portlet-class is Portlet MVC class portlet-name = <PortletName>-portlet.xml Spring MVC config file.
Spring IoC Core (Dependency Injection) Don’t really need to understand to use Portlet MVC, but it is helpful. From Spring Documentation:  The basic principle behind  Dependency Injection  (DI) is that objects define their dependencies (that is to say the other objects they work with) only through constructor arguments, arguments to a factory method, or properties which are set on the object instance after it has been constructed or returned from a factory method. Then, it is the job of the container to actually  inject  those dependencies when it creates the bean. This is fundamentally the inverse, hence the name  Inversion of Control  (IoC), of the bean itself being in control of instantiating or locating its dependencies on its own using direct construction of classes, or something like the  Service Locator  pattern.  It becomes evident upon usage that code gets much cleaner when the DI principle is applied, and reaching a higher grade of decoupling is much easier when beans do not look up their dependencies, but are provided with them (and additionally do not even know where the dependencies are located and of what actual class they are).  Really enables “Programming to the interface”
Spring config basics Everything is defined as a bean. Container will call methods on defined beans. Passes in a String Passes in a reference to another bean
Spring Config Basics - inject another bean Creates two beans locationDao = new LocationDaoHardCodedImpl() locationService = new LocationServiceImpl() locationService has a locationDao “injected” into it. “name” is method to call (setLocationDao) “ref” indicates pass in reference to another defined bean
Spring Config Basics – inject a String Creates a bean referred to as “displayIndexController” “value” indicates pass in String Injects a String in the first property Injects a bean in the second property
Portlet MVC application.xml entries - View Defines where named “views” are located. Defines what view technology to use. Sample uses jsp’s located in /WEB-INF/jsp/ directory
Portlet MVC application.xml entries - Messages Defines message bundle to use for i18n.
Portlet MVC application.xml entries - Exception Define default views for exceptions. PortletSecurityException goes to notAuthorized view. UnavailableException goes to notAvailable view.
Sample Portlets Spring Display Example of a ParameterizableViewController Displays dynamic data Spring Form Example of a SimpleFormController Handles a form submission Spring Wizard Example of an AbstractWizardFormController Presents a form over several pages Assists with navigating back and forth
SpringDisplay-portlet.xml – ParameterDispatchController Declares controller used, referred to as displayIndexController. Property viewName corresponds to jsp that will be displayed.
PortletModeParameterHandlerMapping Allows you to call other controller from the view.
DisplayIndexController ParameterizedViewController implementation
SpringForm-portlet.xml - SimpleFormController formView – view to display form initially successView – confirmation page once form submitted commandClass – form backing object, like ActionForm commandName – how to refer to commandClass in view validator – validation to use
FormIndexController SimpleFormController implementation.
formIndex.jsp Uses Spring 2.0 style form tags commandName is form backing object errors path=“*”, show validation errors for all fields path=“name”, binds to name property of location object
Form Validation in Spring MVC Can use several different types Programmatically through Validator interface Declaratively using Apache Commons Validation Framework Declaratively using Valang Sample uses Valang validation
SpringWizard-portlet.xml pages – List of view that are available through the wizard. Order is significant. wizardBasicInfo is page 0. wizardContactInfo is page 1. wizardBillingInfo is page 2.
WizardIndexController
wizardContactInfo.jsp Middle step in wizard JSP wizard navigation code, _target[PAGEINDEX] Uses older Spring 1.0 form tags _page1, pageAttribute from configuration file
Spring MVC Pros / Cons Pros Easy for experienced Struts Developers to transition. Strong community, should be viable solution for some time. Modular, pick and choose features.  Entry point to use more of the Spring framework. Design goal of the framework is to be non-evasive, your code does not depend on the framework. Class extension or Interface implementation. Good documentation for open source project. Cons Can be xml config intensive. Can not call IBM and create a PMR for support.
Additional Information and Resources Websphere Portal Business Solutions Catalog :  http://catalog.lotus.com/wps/portal/portal Webspere Portal Product Information: http://www-306.ibm.com/software/genservers/portal WebSphere Portal Information Center Documentation: http://www.ibm.com/developerworks/websphere/zones/portal/proddoc.html
Summary IBM Perspective Struts 2.0 Spring 2.0
Avoid Boring People: Lessons from a Life in Science (Hardcover) by  James D. Watson  (Author)
Programming  Portlets : From JSR 168 to IBM  WebSphere  Portal Extensions   Ron Lynn ,  Joey Bernal ,  Peter  Blinstrubas ,  Stefan  Hepper ,  Usman   Memon ,  Varadarajan  ( Varad )  Ramamoorthy

More Related Content

What's hot (19)

Tu1 1 5l
Tu1 1 5lTu1 1 5l
Tu1 1 5l
shibli009
 
Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)
Steve Lange
 
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVCAnnotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
John Lewis
 
WCF (Windows Communication Foundation_Unit_01)
WCF (Windows Communication Foundation_Unit_01)WCF (Windows Communication Foundation_Unit_01)
WCF (Windows Communication Foundation_Unit_01)
Prashanth Shivakumar
 
Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSF
SoftServe
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
Carles Farré
 
XML Unit 01
XML Unit 01XML Unit 01
XML Unit 01
Prashanth Shivakumar
 
Identifying and managing change
Identifying and managing changeIdentifying and managing change
Identifying and managing change
IBM Rational software
 
Establishing and analyzing traceability between artifacts
Establishing and analyzing traceability between artifactsEstablishing and analyzing traceability between artifacts
Establishing and analyzing traceability between artifacts
IBM Rational software
 
JEE Course - JEE Overview
JEE Course - JEE  OverviewJEE Course - JEE  Overview
JEE Course - JEE Overview
odedns
 
JSF 2.2
JSF 2.2JSF 2.2
JSF 2.2
Edward Burns
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
Preetam Palwe
 
J2ee seminar
J2ee seminarJ2ee seminar
J2ee seminar
Sahil Kukreja
 
dot NET Framework
dot NET Frameworkdot NET Framework
dot NET Framework
Roy Antony Arnold G
 
Creating an artifact at the project level
Creating an artifact at the project levelCreating an artifact at the project level
Creating an artifact at the project level
IBM Rational software
 
Java Enterprise Edition 6 Overview
Java Enterprise Edition 6 OverviewJava Enterprise Edition 6 Overview
Java Enterprise Edition 6 Overview
Eugene Bogaart
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
Syed Shahul
 
Java J2EE
Java J2EEJava J2EE
Java J2EE
Sandeep Rawat
 
Basic concepts and terminology for the Requirements Management application
Basic concepts and terminology for the Requirements Management applicationBasic concepts and terminology for the Requirements Management application
Basic concepts and terminology for the Requirements Management application
IBM Rational software
 
Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)
Steve Lange
 
Annotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVCAnnotation-Based Spring Portlet MVC
Annotation-Based Spring Portlet MVC
John Lewis
 
WCF (Windows Communication Foundation_Unit_01)
WCF (Windows Communication Foundation_Unit_01)WCF (Windows Communication Foundation_Unit_01)
WCF (Windows Communication Foundation_Unit_01)
Prashanth Shivakumar
 
Introduction to JSF
Introduction toJSFIntroduction toJSF
Introduction to JSF
SoftServe
 
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
[DSBW Spring 2009] Unit 07: WebApp Design Patterns & Frameworks (1/3)
Carles Farré
 
Establishing and analyzing traceability between artifacts
Establishing and analyzing traceability between artifactsEstablishing and analyzing traceability between artifacts
Establishing and analyzing traceability between artifacts
IBM Rational software
 
JEE Course - JEE Overview
JEE Course - JEE  OverviewJEE Course - JEE  Overview
JEE Course - JEE Overview
odedns
 
Creating an artifact at the project level
Creating an artifact at the project levelCreating an artifact at the project level
Creating an artifact at the project level
IBM Rational software
 
Java Enterprise Edition 6 Overview
Java Enterprise Edition 6 OverviewJava Enterprise Edition 6 Overview
Java Enterprise Edition 6 Overview
Eugene Bogaart
 
Hibernate Interview Questions
Hibernate Interview QuestionsHibernate Interview Questions
Hibernate Interview Questions
Syed Shahul
 
Basic concepts and terminology for the Requirements Management application
Basic concepts and terminology for the Requirements Management applicationBasic concepts and terminology for the Requirements Management application
Basic concepts and terminology for the Requirements Management application
IBM Rational software
 

Viewers also liked (7)

Web site optimization
Web site optimizationWeb site optimization
Web site optimization
Sunil Patil
 
Flex In Portal Final
Flex In Portal   FinalFlex In Portal   Final
Flex In Portal Final
Sunil Patil
 
Exposicion Tarjetas Madre Grupo 1
Exposicion Tarjetas Madre Grupo 1Exposicion Tarjetas Madre Grupo 1
Exposicion Tarjetas Madre Grupo 1
wilmer92
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
Sunil Patil
 
The Consistency and Controversy of Gender: Egalitarian Educational Norms and ...
The Consistency and Controversy of Gender: Egalitarian Educational Norms and ...The Consistency and Controversy of Gender: Egalitarian Educational Norms and ...
The Consistency and Controversy of Gender: Egalitarian Educational Norms and ...
Alexander Wiseman
 
Comparing National and Non-national Student Achievement in Saudi Arabia:
Comparing National and Non-national Student Achievement in Saudi Arabia: Comparing National and Non-national Student Achievement in Saudi Arabia:
Comparing National and Non-national Student Achievement in Saudi Arabia:
Alexander Wiseman
 
Wiseman, A. W. (2013, May). The Global “Crisis” in Education and the US Polic...
Wiseman, A. W. (2013, May). The Global “Crisis” in Education and the US Polic...Wiseman, A. W. (2013, May). The Global “Crisis” in Education and the US Polic...
Wiseman, A. W. (2013, May). The Global “Crisis” in Education and the US Polic...
Alexander Wiseman
 
Web site optimization
Web site optimizationWeb site optimization
Web site optimization
Sunil Patil
 
Flex In Portal Final
Flex In Portal   FinalFlex In Portal   Final
Flex In Portal Final
Sunil Patil
 
Exposicion Tarjetas Madre Grupo 1
Exposicion Tarjetas Madre Grupo 1Exposicion Tarjetas Madre Grupo 1
Exposicion Tarjetas Madre Grupo 1
wilmer92
 
D22 portlet development with open source frameworks
D22 portlet development with open source frameworksD22 portlet development with open source frameworks
D22 portlet development with open source frameworks
Sunil Patil
 
The Consistency and Controversy of Gender: Egalitarian Educational Norms and ...
The Consistency and Controversy of Gender: Egalitarian Educational Norms and ...The Consistency and Controversy of Gender: Egalitarian Educational Norms and ...
The Consistency and Controversy of Gender: Egalitarian Educational Norms and ...
Alexander Wiseman
 
Comparing National and Non-national Student Achievement in Saudi Arabia:
Comparing National and Non-national Student Achievement in Saudi Arabia: Comparing National and Non-national Student Achievement in Saudi Arabia:
Comparing National and Non-national Student Achievement in Saudi Arabia:
Alexander Wiseman
 
Wiseman, A. W. (2013, May). The Global “Crisis” in Education and the US Polic...
Wiseman, A. W. (2013, May). The Global “Crisis” in Education and the US Polic...Wiseman, A. W. (2013, May). The Global “Crisis” in Education and the US Polic...
Wiseman, A. W. (2013, May). The Global “Crisis” in Education and the US Polic...
Alexander Wiseman
 

Similar to D22 Portlet Development With Open Source Frameworks (20)

Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overview
skill-guru
 
Struts Interceptors
Struts InterceptorsStruts Interceptors
Struts Interceptors
Onkar Deshpande
 
Widgets - the Wookie project
Widgets - the Wookie projectWidgets - the Wookie project
Widgets - the Wookie project
scottw
 
What's New for Presentation in Visual Studio 2008 SP1
What's New for Presentation in Visual Studio 2008 SP1What's New for Presentation in Visual Studio 2008 SP1
What's New for Presentation in Visual Studio 2008 SP1
ukdpe
 
struts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptxstruts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptx
ozakamal8
 
struts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptxstruts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptx
ozakamal8
 
IBM WebSphere Portal 6.1 Preview - What's New
IBM WebSphere Portal 6.1 Preview - What's NewIBM WebSphere Portal 6.1 Preview - What's New
IBM WebSphere Portal 6.1 Preview - What's New
Dvir Reznik
 
Struts Ppt 1
Struts Ppt 1Struts Ppt 1
Struts Ppt 1
JayaPrakash.m
 
Ajax toolkit framework
Ajax toolkit frameworkAjax toolkit framework
Ajax toolkit framework
Sunil Kumar
 
Krishnagopal Thogiti_Java
Krishnagopal Thogiti_JavaKrishnagopal Thogiti_Java
Krishnagopal Thogiti_Java
Krishnagopal Thogiti
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
divzi1913
 
Ibm
IbmIbm
Ibm
techbed
 
MVC
MVCMVC
MVC
akshin
 
Vijay Oscon
Vijay OsconVijay Oscon
Vijay Oscon
vijayrvr
 
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008
Jonas Follesø
 
Ajax toolkit-framework
Ajax toolkit-frameworkAjax toolkit-framework
Ajax toolkit-framework
WBUTTUTORIALS
 
SilverStripe Meetup Presentation 03/03/2011
SilverStripe Meetup Presentation 03/03/2011SilverStripe Meetup Presentation 03/03/2011
SilverStripe Meetup Presentation 03/03/2011
Paul Rogers
 
SilverStripe Meetup 03/03/2011
SilverStripe Meetup 03/03/2011SilverStripe Meetup 03/03/2011
SilverStripe Meetup 03/03/2011
Paul Rogers
 
Struts course material
Struts course materialStruts course material
Struts course material
Vibrant Technologies & Computers
 
Ram Prasad P.S.S
Ram Prasad P.S.SRam Prasad P.S.S
Ram Prasad P.S.S
Ram Prasad S S Panuganti
 
Struts 2 Overview
Struts 2 OverviewStruts 2 Overview
Struts 2 Overview
skill-guru
 
Widgets - the Wookie project
Widgets - the Wookie projectWidgets - the Wookie project
Widgets - the Wookie project
scottw
 
What's New for Presentation in Visual Studio 2008 SP1
What's New for Presentation in Visual Studio 2008 SP1What's New for Presentation in Visual Studio 2008 SP1
What's New for Presentation in Visual Studio 2008 SP1
ukdpe
 
struts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptxstruts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptx
ozakamal8
 
struts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptxstruts unit best pdf for struts java.pptx
struts unit best pdf for struts java.pptx
ozakamal8
 
IBM WebSphere Portal 6.1 Preview - What's New
IBM WebSphere Portal 6.1 Preview - What's NewIBM WebSphere Portal 6.1 Preview - What's New
IBM WebSphere Portal 6.1 Preview - What's New
Dvir Reznik
 
Ajax toolkit framework
Ajax toolkit frameworkAjax toolkit framework
Ajax toolkit framework
Sunil Kumar
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
divzi1913
 
Vijay Oscon
Vijay OsconVijay Oscon
Vijay Oscon
vijayrvr
 
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008
Jonas Follesø
 
Ajax toolkit-framework
Ajax toolkit-frameworkAjax toolkit-framework
Ajax toolkit-framework
WBUTTUTORIALS
 
SilverStripe Meetup Presentation 03/03/2011
SilverStripe Meetup Presentation 03/03/2011SilverStripe Meetup Presentation 03/03/2011
SilverStripe Meetup Presentation 03/03/2011
Paul Rogers
 
SilverStripe Meetup 03/03/2011
SilverStripe Meetup 03/03/2011SilverStripe Meetup 03/03/2011
SilverStripe Meetup 03/03/2011
Paul Rogers
 

D22 Portlet Development With Open Source Frameworks

  • 1. Session Number: D22 Jump START your Portlet development with Open Source Frameworks! Sean Newby, Perficient Sunil Patil, Ascendant Technology LLC Peter Blinstrubas, IBM
  • 2. Agenda IBM Portlet Development Perspective Struts 2.0 Spring 2.0
  • 3.  IBM Portlet Development Perspective Email: [email protected]
  • 4. Why Use a Framework for Portlet Development? Starts off small and later is enhanced. Model View Controller well established. Provides separation between different layers Frameworks force developers into using a standard approach when building applications Shield some of the underlying complexity of developing an application. Provides interfaces or abstract classes to speed and structure your development effort. Options Write the portlet in portal api Develop a custom framework for portlet development. Port servlet world framework to the portlet world Use an existing framework!
  • 5. Frameworks for Portlet Development IBM Frameworks Just the Portlet API WebSphere Portlet Factory AJAX based on DOJO JSF V1.1 on Portal 6.x with JWL 3.0 JSF 1.2 for Portal running on WAS 7 (plans subject to change) AJAX Struts Apache Bridge for JSR 168 Container on WAS 6.1 Currently Struts Portlet Framework supports Struts 1.1 and 1.29 Alternative Frameworks Custom MVC Spring 2.0 Struts 2.0 Many More… (i.e. Shale, Wicket,…)
  • 6. What is the Struts Portlet Framework? Runtime A package that supports Struts application in Portal. Includes a level of Struts (1.1 and 1.29) A portlet controller and a request processor. Implementations of some of the Struts tags Tool Set Flow Editor for creating and wiring pages and actions together A full Struts-Config editor Link validation and re-factoring for Struts specific links Wizards for creating Actions, Struts JSPs and Form Beans Page Designer Visualizations for some Struts-html tags Full Page Designer Palette for Struts Tags
  • 7. What is the Struts Portlet Framework? Support for writing/migrating Struts applications that can be deployed in WebSphere Portal Also provides samples to show how portal features can be incorporated by Struts applications
  • 8. Struts 1.x in General Struts is: Controller based framework Struts does not have: A built-in UI component model A built-in event model for UI components A built-in state management for UI components A built-in support of multiple renderers (Struts is more or less tied up with HTML) Struts is Not a standard (despite its popularity) IBM has no plans to continue SPF Development. Recommended for Legacy Struts Applications. Also consider Apache Bridge
  • 9. IBM and JSF Part of Java EE 5 Participation in JSR Expert Group J2EE-based Web UI and application framework WPLC Underlying technology in Composite Application Designer Used in Portal Workflow portlets Being incorporated into Lotus Expeditor Widgets in Portlet Factory Recommended for new portlet development Note: Refer to session D12 for JSF details
  • 10. JSF General Benefits Reusable UI Components Custom Tag Libraries API for managing UI components, events, input navigation, page navigation Addresses complex navigation requirements Extensible - Everything is pluggable Rich tooling support Flexible Actions: different navigations for multiple components on a single page Supports Expression Built in state management Concerns Complexity Still relatively new Out of the box capability to meet requirements Availability of skills
  • 11. Plug-in to Eclipse & Rational Application Developer Multi-page custom portlets/applications without coding Integration capabilities (SAP, Domino, PeopleSoft, Siebel, Web Services, Databases, Portal Content Repository) Service-oriented development Support for Portal features such as portlet communication, business user configuration, auto-deploy, single sign-on “ Dynamic profiling” capability, to create multiple variations from a single set of source portlets WebSphere Portlet Factory Rapid Portlet Creation and Customization Tooling IBM WebSphere Portlet Factory simplifies & accelerates the development, deployment, maintenance, and reuse of custom portlets and applications.
  • 12. Portlet Factory General Benefits DataCentric Applications Expand Portlet Creation to developers of all skill level Captures Design Patterns/Standardize Development Model Lots of adapters Strong XML/Web Service support Code generation technology protects investment Protecting against backend product upgrades Concerns New vocabulary (learning curve) Complex application, process intensive
  • 13. There are so many choices? Portlet API JSF Framework Struts Portlet Framework Struts 2.0 My Servlet Framework There may be many valid and not so valid reasons to consider. Portlet Factory Spring 2.0 Apache Bridge
  • 14.  Apache Struts 2.0: Sunil Patil, Senior Consultant, Ascendant Technology LLC Email: [email protected]
  • 15. Struts 2.0 Introduction Action Framework, allows you to map URL to Action Class Missing features of Apache Struts 1.0 will be ported to Struts 2.0 OpenSymphony’s WebWorks framework will cease to exists WebWorks will only release patches for existing versions. The WebWorks framework has built-in support for JSR-168 portlet development Architecture based on OpenSymphony’s WebWorks Framework Command pattern implementation Actions are command objects
  • 16. Client Selection Example At previous client using Apache Struts 2.0 framework Reasons Struts 2.0 framework is considered Customer wanted precise control on the Portlet Screens Customer wanted to use common look and feel across all portlets Has considered JSF, but developing custom components in JSF requires lot of work Developers already had experience on Apache Struts 1.0, easy migration Provides clear separation between Action and Render phase
  • 17. Key Struts 2.0 objects/concepts Jsr168Dispatcher: The Controller portlet that handles all requests to the portlet application. Similar to ActionServlet in Struts 1.0 framework Action Jsr168Dispatcher passed request to configured Action to handle request. Combines ActionForm, Action and Model class Location in framework where you write you business logic. Results Different view technologies are supported JSP Velocity Freemarker
  • 18. Key Struts 2.0 objects/concepts Cont. Interceptor Interceptors are one of the most powerful features of Struts 2.0 framework Interceptors are similar to Filters in servlet environment, they allow you to execute your code before and after Action. Common functionality is implemented as interceptor Setting parameters Validation workflow Value Stack Used for carrying data from action class to JSP page Value Stack, Stack of objects Temporary Objects Action Object Named object
  • 19. Struts : Forward to JSP request flow
  • 20. Struts : Forward to Action request flow
  • 22. Additions to portlet.xml Jsr168Dispatcher is portlet dispatcher class viewNameSpace defines default namespace for view mode defaultViewAction defines default action for view mode
  • 23. Additions to web.xml Configure to setup PreparatorServlet Configure to setup spring integration
  • 24. Struts Configuration Import default configuration from struts-portlet-default.xml Divide configuration in different namespaces
  • 25. Struts Action Optionally extend from ActionSupport class Combines Action, ActionForm and Model class The execute() method does not take PortletRequest and PortletResponse object
  • 26. Struts Action contd. Setting form values in Contact class No need for contactList, model class
  • 27. Struts JSP OGNL expressions for reading values from Value stack Read i18n messages from <ActionClass>.properties file Struts tags use Freemarker Template for generating markup You can extend tag by overriding template XHTML Theme - No HTML Markup in the JSP
  • 28. Struts Tags The form field tag is responsible for Generating two column layout Generating form elements as well as surrounding table element Every form field tag is responsible for generating one row in table Display label on the left side of the form field Display actual form field on the right side Display the field error above the form field <s:textfield label=&quot;Name&quot; name=&quot;contact.firstName&quot;/> rendered as (with error message)
  • 29. Struts Tags contd. This is how datepicker form field and popup look like <s:datetimepicker label=&quot;DOB&quot; name=&quot;contact.dateOfBirth&quot;/> rendered as
  • 30. Support for Different View Technologies Same tag library available in JSP, Freemarker and Velocity Insert.ftl insert.vm
  • 31. Form Validation in Struts 2.0 Can be use several different types Programmatically by implementing validate() method in Action class Declaratively using XWork’s Validation framework Client side validation Create <ActionClass>-validation.xml Sample uses of XWork validation
  • 32. Type Conversion Routine type conversion in the framework is transparent Boolean, boolean, Integrer, int, Float, float, Long, log, Double, double Date with the locale associated with current request Register custom type conversion class <ActionClass>-conversion.properties for class specific conversion Point=com.ascendant.converter.PointConverter Xwork-conversion-properties for global conversion Custom type conversion for more complex objects Create class extending StrutsTypeConverter class convertFromString() convertToString()
  • 33. Struts Plug-ins Many popular optional features of the framework are distributed as plug-ins Spring Tiles File upload Plug-ins are used for Introducing new Extension point implementation class ObjectFactory : Spring plug-in implements StrutsSpringObjectFactory Mutlipart parser: Allows using Pell’s multi part parser for parsing multi-part request Define new packages with results, interceptors or actions Results: Tiles plug-in introduces Tiles Results type Override framework constants
  • 34. Spring Integration Allows Actions, Interceptors and Results to be created by Spring Struts created object can be auto wired by spring after creation Provides two interceptors that auto wire actions if not using the Spring Objectfactory Add entry for StrutsSpringObjectFactory in struts.properties struts.objectFactory = org.apache.struts2.spring.StrutsSpringObjectFactory
  • 35.  Spring 2.0: Sean Newby, Senior Consultant, Perficient Inc. Email: [email protected]
  • 36. Spring Intro Spring is a popular Java Application Framework that has gained significant momentum in the past few years. Made up of several modules that can be used independently Inversion of Control Container (Core) AOP module DAO module MVC module Portlet MVC became a part of the general Spring 2.0 release in November of 2006.
  • 37. Client Selection Example At a previous client that decided to Spring MVC. Reasons Spring MVC was selected. Similar in design to IBM Struts implementation. Had considered JSF, but no developers had any experience. JSF seemed to be more of a paradigm shift. Developers already had experience with other elements of Spring. Confident that would be able to find answers to issues in the Spring community. Addressed use case we needed to solve (Wizard Portlet). Designed around portlet api, addressed Render and Action separately.
  • 38. Key Portlet MVC objects / concepts DispatcherPortlet The controller portlet that handles all requests to the portlet application. Similar to ActionPortlet or ActionServlet in the Struts framework. Controller Location in Framework where your code begins. Similar to Struts Action class. DispatcherPortlet passed request to configured Controller to handle request. Separate methods for render and action phases. Several default implementations to handle common use cases: ParameterizableViewController – Simple controller that passes to a view. SimpleFormController – Controller to handle form submissions. AbstractWizardController – Controller to implement wizard like form. Form that extends over several pages. HandlerMapping Determines which Controller will be called. Several out of the box implementations.
  • 39. Key Portlet MVC objects / concepts cont. ModelAndView Object that is returned by Controllers to DispatcherPortlet. Contains the Model that needs to be displayed by the view. Also contains the “name” of the view. Behavior is similar to a regular Map object. ViewResolver Maintains a clean separation of View technology. Several Default ViewResolvers JSP Velocity XSLT Command Objects JavaBean type objects. Object is bound to request parameters, usually from form submission. Similar to Struts ActionForm, except is does not extend framework specific class.
  • 40. Simplified Render Sequence Diagram Some steps have been omitted for clarity.
  • 41. Simplified Action Sequence Diagram Some steps have been omitted for clarity.
  • 42. Getting Started setting up a Spring Portlet WEB-INF/web.xml and WEB-INF/portlet.xml WEB-INF/context/applicationContext.xml – main application wide config file. Values can be overridden in portlet config. WEB-INF/<PORTLETNAME>-portlet.xml – individual config file for each portlet. WEB-INF/lib/spring.jar – main spring file.* WEB-INF/lib/spring-portlet.jar – additions for Spring Portlet MVC WEB-INF/lib/spring-modules-validation.jar – additions for validation of forms. *could pick out specific Spring jar’s to reduce size of application.
  • 44. Additions to Web.xml Configuration to set up Spring MVC servlet. Portlet MVC leverages Servlet base code.
  • 45. Portlet.xml portlet-class is Portlet MVC class portlet-name = <PortletName>-portlet.xml Spring MVC config file.
  • 46. Spring IoC Core (Dependency Injection) Don’t really need to understand to use Portlet MVC, but it is helpful. From Spring Documentation: The basic principle behind Dependency Injection (DI) is that objects define their dependencies (that is to say the other objects they work with) only through constructor arguments, arguments to a factory method, or properties which are set on the object instance after it has been constructed or returned from a factory method. Then, it is the job of the container to actually inject those dependencies when it creates the bean. This is fundamentally the inverse, hence the name Inversion of Control (IoC), of the bean itself being in control of instantiating or locating its dependencies on its own using direct construction of classes, or something like the Service Locator pattern. It becomes evident upon usage that code gets much cleaner when the DI principle is applied, and reaching a higher grade of decoupling is much easier when beans do not look up their dependencies, but are provided with them (and additionally do not even know where the dependencies are located and of what actual class they are). Really enables “Programming to the interface”
  • 47. Spring config basics Everything is defined as a bean. Container will call methods on defined beans. Passes in a String Passes in a reference to another bean
  • 48. Spring Config Basics - inject another bean Creates two beans locationDao = new LocationDaoHardCodedImpl() locationService = new LocationServiceImpl() locationService has a locationDao “injected” into it. “name” is method to call (setLocationDao) “ref” indicates pass in reference to another defined bean
  • 49. Spring Config Basics – inject a String Creates a bean referred to as “displayIndexController” “value” indicates pass in String Injects a String in the first property Injects a bean in the second property
  • 50. Portlet MVC application.xml entries - View Defines where named “views” are located. Defines what view technology to use. Sample uses jsp’s located in /WEB-INF/jsp/ directory
  • 51. Portlet MVC application.xml entries - Messages Defines message bundle to use for i18n.
  • 52. Portlet MVC application.xml entries - Exception Define default views for exceptions. PortletSecurityException goes to notAuthorized view. UnavailableException goes to notAvailable view.
  • 53. Sample Portlets Spring Display Example of a ParameterizableViewController Displays dynamic data Spring Form Example of a SimpleFormController Handles a form submission Spring Wizard Example of an AbstractWizardFormController Presents a form over several pages Assists with navigating back and forth
  • 54. SpringDisplay-portlet.xml – ParameterDispatchController Declares controller used, referred to as displayIndexController. Property viewName corresponds to jsp that will be displayed.
  • 55. PortletModeParameterHandlerMapping Allows you to call other controller from the view.
  • 57. SpringForm-portlet.xml - SimpleFormController formView – view to display form initially successView – confirmation page once form submitted commandClass – form backing object, like ActionForm commandName – how to refer to commandClass in view validator – validation to use
  • 59. formIndex.jsp Uses Spring 2.0 style form tags commandName is form backing object errors path=“*”, show validation errors for all fields path=“name”, binds to name property of location object
  • 60. Form Validation in Spring MVC Can use several different types Programmatically through Validator interface Declaratively using Apache Commons Validation Framework Declaratively using Valang Sample uses Valang validation
  • 61. SpringWizard-portlet.xml pages – List of view that are available through the wizard. Order is significant. wizardBasicInfo is page 0. wizardContactInfo is page 1. wizardBillingInfo is page 2.
  • 63. wizardContactInfo.jsp Middle step in wizard JSP wizard navigation code, _target[PAGEINDEX] Uses older Spring 1.0 form tags _page1, pageAttribute from configuration file
  • 64. Spring MVC Pros / Cons Pros Easy for experienced Struts Developers to transition. Strong community, should be viable solution for some time. Modular, pick and choose features. Entry point to use more of the Spring framework. Design goal of the framework is to be non-evasive, your code does not depend on the framework. Class extension or Interface implementation. Good documentation for open source project. Cons Can be xml config intensive. Can not call IBM and create a PMR for support.
  • 65. Additional Information and Resources Websphere Portal Business Solutions Catalog : http://catalog.lotus.com/wps/portal/portal Webspere Portal Product Information: http://www-306.ibm.com/software/genservers/portal WebSphere Portal Information Center Documentation: http://www.ibm.com/developerworks/websphere/zones/portal/proddoc.html
  • 66. Summary IBM Perspective Struts 2.0 Spring 2.0
  • 67. Avoid Boring People: Lessons from a Life in Science (Hardcover) by James D. Watson (Author)
  • 68. Programming Portlets : From JSR 168 to IBM WebSphere Portal Extensions Ron Lynn , Joey Bernal , Peter Blinstrubas , Stefan Hepper , Usman Memon , Varadarajan ( Varad ) Ramamoorthy

Editor's Notes

  • #4: Mention that planned availability for Lotus Quickr is late 2Q. Therefore, some of the details in this presentation might change before then.
  • #5: The typical portlet starts off small and later is enhanced. The business logic is distributed throughout the portlet. The business logic then changes over time causing a rewrite of the portlet. Model View Controller design pattern has been around a long time. This design pattern advocates separating the view aspect from the model and using a controller to orchestrate the flow. Portlet development adds some unique features over the servlet world. Portlet supports modes Portlet must be able to redisplay a view. ( if a user is interacting with other portlets, each portlet on the page must save the state so the view can be redisplayed. ) Options Write the portlet in portal api, but be careful to design the application correctly Develop a custom framework for portlet development. Some customers have done this in the servlet world and have ported it to the portlet world Use an existing framework!
  • #12: There are numerous features of Portlet Factory specifically intended to ensure the unsurpassed competitive differentiation of WebSphere Portal, as well as contributing to increased customer success and satisfaction. With its tight WebSphere Portal integration and automation via Builders it dramatically simplifies the development of complex portlets – including multi-page transactional composite portlets via integrations to existing applications and systems like SAP and Domino, among others. In addition, Portlet Factory’s patented Profiling technology generates multiple portlet variations from one code base. This feature enables developers to quickly vary portlets across any number of multiple user dimensions (roles, geography, brands) and greatly simplifies code maintenance, by automatically propagating changes. Finally, developers can target multiple computing environments (portal, web, rich-client, phone, PDA) from a single application, which means developers can repurpose applications with minimal development effort. It is also important to understand that Portlet Factory extensible and not limited to the capabilities provided out of the box. For example, J2EE developers can capture an organization’s proprietary APIs as a custom function that they can then add to the tool’s palette so other developers may use it. In doing this, they can ensure all developers are accessing and using the API the same way, enforcing consistent design patterns and architecture.
  • #15: Mention that planned availability for Lotus Quickr is late 2Q. Therefore, some of the details in this presentation might change before then.
  • #18: The Jsr168Dispatcher is a controller portlet that is responsible for handling all the client request. You can think about it as something similar to ActionServlet in Struts 1.0 framework. Actions in struts framework are combination of Actions, ActionForm and Model classes. What i meant by that is, Lets say if you want to handle simple form submission, then in Struts 1.0 framework you will have to create 3 different classes. First is ActionForm class which is simple Java Bean with properties matching to your html form. Second is Action class which is a place where you write your business logic and third is Model class that is used for carrying data from Action class to JSP. In case of struts framework your Action class is combination of all three classes. First it will have java bean properties matching your html form, then it will have execute() method where you write your business logic and same Action class object is available to JSP page at the time of markup generation so it also plays the role of Model class. The basic concept of Results is same as that of Struts 1.0 framework, which is that execute() method of your Action class will return result code and based on that framework will dispatch control to JSP for final markup generation. Only difference is that Struts framework wraps request dispatching functionality in separate class in order to maintain clear separation of view layer
  • #19: Interceptors is this basic concept that allows you to execute some code before or after execute method of your action class. In fact most of the struts framework logic such as setting action properties with values submitted by user or exception handling is implemented in interceptors. The Struts framework also allows you to group set of interceptors together into stack and define the order in which they are executed. Every application will have a default interceptor stack and then your allowed to override that value at individual action level. For example if your application does not need ability to handle file upload then you can remove that interceptor from your applications default interceptor stack. Value stack as name suggests is simply stack of object that is used for carrying data from your action class to JSP page. When using the value stack there is no need to keep track of which scope the target object is in. If you want the attribute “firstname”, then you query the value stack for this attribute. Each stack element, in the provided order, is asked whether it has the property. If it does, then the value is returned and we are done. If not, then the next element down is queried. This continues until the end of the stack is reached. This is a great feature, as you don’t care where the value is – the action, the model, or the request object – you just know that if the value exists it will be returned.
  • #20: Take a look at this sequence diagram that describes sequence of events that happen when Dispatcher portlet gets request. First thing that dispatcher portlet does is that it finds out action class that should be used to handle this request along with interceptor stack that should be applied to the action. Once the interceptor stack is decided, it starts calling all the interceptors in the stack one by one followed by call to execute method of your action class. Inside the execute method you will execute your business logic, populate model class and based on the outcome of business logic return a result code. Struts framework will use return code of your execute method to find out the location of JSP that should be used to generate final markup Before ending action phase struts framework will store both your action object as well as final location of the JSP in the portlet session. After that whenever dispatcher portlet gets render request instead of re executing action class, it will read location of JSP from the session and forward control to it for markup generation.
  • #21: But the question is, What if your developing say Stock Ticker portlet and want to query stock service every time for latest update. If that&apos;s the case then first you should create a separate action class and add render phase logic in it. Then you should change your struts.xml file so that success code for first action maps to action URL of the second action. Once you do that your action phase request processing will remain same. But in the render phase Struts framework will forward control to your render action, which can execute render logic and then forward control to JSP page for final markup generation. I will show you an example of how to do this on the later slide.
  • #22: Lets walk through steps that are required to build Struts portlet. You can download sample code for this session from Conference web site. In order to build struts portlet, you will have to create 3 set of files First is I18n and validation related resources. The actual struts configuration is stored in couple of files first is struts.properties and second is struts.xml And since we want to use spring integration, we will have to create applicationContext.xml file. Now lets start taking closer look at each of these files
  • #23: The Jsr168Dispatcher is main dispatcher portlet so you should set it as portlet class. Value of viewNameSpace initialization parameter defines default namespace for the view mode Value of defaultViewAction defines, default action for view mode. If you want to support any other portlet mode then you need to set parameters for that.
  • #24: The web.xml file will have two section, in the spring setup configuration first set contextConfigLocation parameter pointing to location of spring context file and then define ContextLoaderListerner which will be responsible for loading your spring configuration. The Struts portlet community wanted to use same tag library as that of servlet environment but problem was that struts tag library has dependency on ServletContext, httpServletrequest and HttpServletResponse object. But these objects are not available in Portlet environment. In order to solve this problem they introduced PreparatorServlet. The way it works is before forwarding control to actual JSP for markup generation, Struts framework will forward control to PreparatorServlet. This servlet will store object of HttpServletRequest, Response and ServletContext in thread local variable. Since the JSP page is called in the same thread as that of the the preparatorServlet, custom tag library will get access to these objects.
  • #25: This is how your struts configuration file would look like The Struts framework allows you to break your configuration in multiple namespaces to facilitate parallel development. It uses combination of packagename and actionname to uniquely identify action class that will be used to handle particular request. For example in our sample code selectAction class will be used only for handling selectAction in the view mode. If you have more than one developers working on one portlet, you can break your configuration into multiple files and then import those files into your struts.xml. In fact most of the struts framework configuration such as definitions for built-in interceptors and result classes is defined in struts-portlet-default.xml. You should always import struts-portlet-default.xml in your configuration file and extend your packages from struts-portlet-default to take advantage of built in functionality. Take a look at Forward Control to JSP block, in this we are saying that whenever it gets request for deleteAction it should forward control deleteAction class. Since we are using Spring integration actual action class name is defined in spring configuration file. Then we are saying that if delete action returns success framework should forward control to list.jsp. Success is default value for result code so you can omit it if you want. The forward control to action block is example of how you can forward control to some other action class for handling render phase. The interceptor-ref element is example of how you can apply particular interceptor stack to your action class.
  • #26: In our struts.xml file we have mapped deleteAction url to DelteAction class. So the way it works is when you go to contact spread sheet, select a contact and say delete then struts framework will create new object of DeleteAction, set its contactId property and call its execute() method. In the execute method first we delete that contact then query database to get updated contactList and store it in contactList variable that list.jsp will use to display contact spreadsheet. Did you notice that the execute() method does not get object of either PortletRequest or PortletResponse, this is because one of the design goals of Struts frameworks was to make unit testing easy. In the unit test case of DeleteAction, you can create its object set contactId and call execute() method, and there is no need to mock portletrequest, response objects. The way portlet containers work is that they use separate thread for handling every request. The Struts framework tries to take advantage of this fact by storing all the objects related to the request such as portlet request, response or session in ThreadLocal object and the PortletActionContext class provides static methods to access these object anywhere you want in current request. But as we know static methods make unit testing difficult so Struts framework defines one more way to access portlet specific object. Lets say your interested in PortletPreferences object, if that&apos;s the case then first you should implement PortletPreferencesAware interface in your action and then define portletPreferences as bean property in your action class along with setter method. If you do that then at runtime framework will inject portletpreferences object in your action class.
  • #27: This is another example of action class. Now if your HTML form has more than 4-5 parameters then instead of adding each of these parameter as property in your action class you may want to create separate JavaBeans and add those input parameters as properties into it. In our sample code contact form has 5 fields so we had created contact bean with 5 properties. You will have to change your JSP page to use contact.propertyname expression for getting or setting properties from contact bean, Also we want to delegate control to SelectAction for actual markup generation. So we don’t need model class related functionality in our Action class. Only thing that our execute method does is insert contact then return SUCCESS return code. The Struts framework will forward control to SelectAction for handling render phase and it will take care of populating contactList variable before forwarding control to list.jsp for actual markup generation.
  • #28: This is how typical JSP page looks like. The Struts JSPs use OGNL as expression language for getting and setting properties from beans. OGNL does everything that JSP expression language does and in addition to that it has some advanced features such as projections, filters Projection is this cool feature that allows you to set project particular property of bean into temporary collection. For example, Lets say you have this list of contact objects and you want to display first names of all the contacts in combo box, in normal case you will have to write some JSP scriplet for this. But In OGNL you can use projections to project firstName property of every contact objects into another collection and then use that collection for displaying firstName combo. Developers of the struts tag library had couple of design goals. First they wanted to provide consistent look and feel through out the application and second they wanted to provide extendible tags. So the way struts tag library works is every custom tag has one Java file and one template file associated with it. For example when you use texfield tag first control will go to TextField.java which will perform some basic logic such as reading value of the java bean property from value stack and then it will forward control to TextField.ftl which is freemarker template file for actual markup generation of input tag. In addition to this Struts tag library has concept of theme which allows you to group set of template files that provide similar look and feel. Did you notice that our JSP page does not use any HTML markup elements such as &lt;table&gt;,&lt;tr&gt; or td that is because we are using XHTML theme and it takes care of displaying forms in two column layout.
  • #29: The XHTML implementation of The form tag is responsible for creating the form element as well as the surrounding table. The rest of the form element tags are responsible for creating one row each in the table. In which label is displayed on the left and actual form element is displayed on the right. In addition to being responsible for creating a single row, each tag is also responsible for displaying any validation or type conversion errors that may be associated with that field. If you don&apos;t want Struts tag library to create two column layout for you, you can change your theme to simple and take complete control on markup.
  • #30: In addition to simple form tags struts tag library also provides few out of box widgets such as date picker. In our sample code we are using datetimepicker tag for date of birth input The datetimepicker tag generates 3 things first a label on the left hand side, after that input box, followed by button. When you click on the button it will open a calendar control like this that you can use for selecting date.
  • #31: In addition to powerful tag library struts framework also has support for different view technologies such as Freemarker and Velocity. Take a look at how you can create insert.jsp page using either Velocity or Freemarker templating language. Good thing about struts is that it provides native access to struts tags from both Freemarker and Velocity.
  • #32: Ability to validate user input is another common requirements and Struts framework provides quite few choices for how you want to implement your validation rules.. If you decide to use programmatic validation then you can implement validate() method in your Action class and add your validation rules there. But if you decide to use declarative validation then you will have to create ActionClassName-validation.xml file in the same package as that of your action class. For example take a look at how validation.xml file for our Insert Action As you can see the concept is very much similar to Apache Commons validation framework but it is bit more flexible. If you decide to implement your custom validation rules then you can create class implementing Validation interface and register it with validation framework.
  • #33: Other common problem in web applications is that web is type agnostic i.e. everything is string but java is strictly typed language. So you need some mechanism to convert string data into specific type and other way round. In Struts routine type conversion such as int, double, date is transparent. For example, in our sample code date of birth field is date of type. So only thing that you should do is declare it as date type while creating contact java bean and struts framework will take care of converting string to date when setting form values and converting from date to string when displaying data to user. Another good thing about type conversion is that struts framework also takes care of locale specific formatting of date type.
  • #34: Struts framework provides simple plug-in architecture so that developers can extend the framework by just adding a simple JAR to web applications class path. In fact most of the optional features such as Spring and Tiles integration are implemented as plug-in. If you remember even struts 1.0 has concept of plug-in, that allowed you to execute some code at application startup and shutdown. But in Struts 2.0 plug-ins are much more powerful. Struts framework defines 12 different extension points that you can extend in your plug-in. For example Spring plug-in provides its own object factory that allows you to use Spring framework for actual object creation
  • #35: In our sample code we are using Spring framework as object factory. What that means is whenever Struts framework wants to create new object for either Action or Result class it will ask Spring framework for that. You can configure this by adding entry for struts.objectFactory in struts.properties file. For example when Struts framework gets selectAction request it will ask Spring framework for object of SelectContac class. Now we have defined selectContact as bean in spring configuration file and it has dependency on contactDAO. So Spring framework will first create object of selectAction class inject contactDAO object in it and then return that object to struts for further processing. In our sample code we talked about how you can use Spring framework for integration between View and data access layer. But Spring framework also has its own implementation of Portlet MVC framework, my friend Sean is going to talk about it in detail.
  • #36: Mention that planned availability for Lotus Quickr is late 2Q. Therefore, some of the details in this presentation might change before then.