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
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
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
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)
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
The controller portlet that handles all requests to the portlet application. Similar to ActionPortlet or ActionServlet in the Struts framework.
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.
Determines which Controller will be called.
Several out of the box implementations.
Key Portlet MVC objects / concepts cont.
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.
Maintains a clean separation of View technology.
Several Default ViewResolvers
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.
Additions to Web.xml
Configuration to set up Spring MVC servlet.
Portlet MVC leverages Servlet base code.
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.