© 2008 IBM Session ID: D19 Session Title: Annotated Portal Development with RAD and Spring Speaker(s): Ken Sipe, Technology Director, Perficient Peter Blinstrubas, IBM Americas Portal Leader WebSphere Portal Technical Conference U.S. 2008
STORY TITLE WebSphere Portal Technical Conference U.S Abstract This session will show off the paradigm shift in portlet development which comes with Spring annotations. The session will also demonstrate how to unit test the portlets without a portal server running. This session is intended for developers already familiar with portlet development who want to improve their productivity and test their work 2
STORY TITLE WebSphere Portal Technical Conference U.S Agenda Portlets Anatomy of a Portlet Productivity Pain Points Annotations What are Annotations? Spring What is Spring Spring 2.5 Annotations Portlet + Spring Annotation Development Better Development Paradigm Better Testing Paradigm 3
© 2008 IBM Portal and Portlets 4
STORY TITLE WebSphere Portal Technical Conference U.S Portal Anatomy - External 5
STORY TITLE WebSphere Portal Technical Conference U.S Portlet Anatomy - Internal These interfaces shape your role in the container and resources available from the container Portlet PortletConfig PortletContext PortalContext
STORY TITLE WebSphere Portal Technical Conference U.S Portlet Interface 7
STORY TITLE WebSphere Portal Technical Conference U.S Portlet Functionality Similar to Servlets Managed by container Generate dynamic content Life-cycle managed Differences from Servlets Generate Markup fragments Not Directly addressable Persistence storage for preferences Request Processing Portlet Modes Window State Minimized, etc. User Information 8
STORY TITLE WebSphere Portal Technical Conference U.S Portlet Coding Difference 1: Request Processing Request processing comes in two forms: Action Requests Render Requests Each client request invokes at most one action request Each client request may invoke any number of render requests, depending on layout, caching, and other factors A portlet may be rendered many times between action requests Unlike servlets, portlets are not bound to a logical location (URL)
STORY TITLE WebSphere Portal Technical Conference U.S Portlet Modes View mode doView(…) Normal Display Edit mode doEdit(…) Configuration mode of the portlet Location details Personal preferences Help mode doHelp(…)
© 2008 IBM Simple HelloWorld Portlet Example 11
STORY TITLE WebSphere Portal Technical Conference U.S Portal Tool Features v7.x Streamlined Portlet Wizard Co-operative Wizard Usability improvement. Enhanced Credential Vault Support. JSR 168 and JSR 286
STORY TITLE WebSphere Portal Technical Conference U.S Hello World Portlet public class HelloWorld extends GenericPortlet { protected void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException { response.setContentType(“text/html”); response.getWriter().println(“Hello Portlet”); }
STORY TITLE WebSphere Portal Technical Conference U.S Pain Points Code Dependency on Portlet Not POJO Management and Dependency on the View Technology Execution Model Action Request Render Request Portlet Modes View Edit Help
© 2008 IBM Spring Spring MVC Portal 15
STORY TITLE WebSphere Portal Technical Conference U.S What is Spring? IoC Generic Bean Factory Abstraction from other frameworks Removes croft from developer code Provides typology freedom Develop on Tomcat, deploy to WebSphere Provides Testability No need for in the container testing Framework ties are in the spring framework 16
STORY TITLE WebSphere Portal Technical Conference U.S Heart of Spring MVC DispatcherPortlet Defined in the portlet.xml file Controller for portlet Multiple may be defined in a single portlet.xml file Name of defined portlet is the key to the configuration file (by default) springportlet-portlet.xml
STORY TITLE WebSphere Portal Technical Conference U.S Spring Portlet XML File Defines Controller and other Spring Beans Maps Controller for each mode
STORY TITLE WebSphere Portal Technical Conference U.S Spring Portlet Controller import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import org.springframework.web.portlet.ModelAndView; import org.springframework.web.portlet.mvc.AbstractController; public class ViewController extends AbstractController { protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception { return new ModelAndView("View"); }
STORY TITLE WebSphere Portal Technical Conference U.S Spring View Mapping <bean id="viewResolver“ class= "org.springframework.web.servlet.view.InternalResourceViewResolver"> org.springframework.web.servlet.view.JstlView /WEB-INF/jsp/.jsp
STORY TITLE WebSphere Portal Technical Conference U.S Changes to Web.xml ContextLoaderListener Listener to bootstap spring ViewRendererServlet Front Controller for Spring Portlet MVC
STORY TITLE WebSphere Portal Technical Conference U.S Spring applicationContent.xml Required by ViewRendererServlet Provides Shared Spring beans across portlets
STORY TITLE WebSphere Portal Technical Conference U.S Spring Portlet MVC Setup Jars: Spring Spring.jar, spring-webmvc-portlet.jar Logging Commons-logging.jar, log4j jar Web Jstl.jar, standard.jar Create portlet Configuration Configure for Spring Portlet.xml with DispatcherPortlet Spring xml *-portlet.xml applicationContext.xml Configure web.xml Create Controller Create Views
STORY TITLE WebSphere Portal Technical Conference U.S Spring Portlet Benefits Separates Portlet from View Technology Spring Enables the Portlet After Spring Wiring Simple Code Model Controller for multiple portlet modes Controller for each portlet mode 24
© 2008 IBM Spring 2.5 Annotations 25
STORY TITLE WebSphere Portal Technical Conference U.S Java 5+ Annotations Java 5 Introduces Annotations New Type of Interface Provides Metadata for: Compile time Runtime Language Provides Built-in Ability to Define Custom Annotations Annotation Author { String name(); } Annotation ( name = "John Doe" ) public class OrderDAO { // class code goes here } 26
STORY TITLE WebSphere Portal Technical Conference U.S Spring 2.5 Annotations JSR JAX-WS 2.0’s EJB 3.0 Test Enhancements - Junit 4.4 and TestNG Spring enhancements AOP MVC 27
STORY TITLE WebSphere Portal Technical Conference U.S Spring 2.5 Context Annotations Indicates the scope to use for annotated class instances Default == “singleton” Options: Singleton Prototype Web Options: Request Session Global session
STORY TITLE WebSphere Portal Technical Conference U.S Spring 2.5 Stereotypes ** Indicates that a class is a component Class is a candidate for auto-detection Custom component extensions Specialized Component Typically used with RequestMapping annotation Discussed in section on web mvc 2.0 stereotype… previously mentioned Now an extension Intended to be a business service facade
STORY TITLE WebSphere Portal Technical Conference U.S Spring 2.5 Factory Annotations Marks a constructor, field, setter or config method for injection. Fields are injected After construction Before config methods Config: AutowiredAnnotationBeanPostProcessor Marks class as being eligible for Spring-driven configuration Used with AspectJ Qualifies a bean for autowiring May be customized Marks a method as being injection required
© 2008 IBM A World with No Editor Support 31
STORY TITLE WebSphere Portal Technical Conference U.S Spring 2.5 MVC Annotations Stereotype used to “Controller” of MVC Scanned for RequestMappings Annotates a handler method for a request Very flexible Annotates that a method parameter should be bound to a web request parameter SessionAttributes Marks session attributes that a handler uses
STORY TITLE WebSphere Portal Technical Conference U.S Extreme Flexibility Parameters can be Request / response / session WebRequest InputStream OutputStream +++ Return types ModelAndView Object Model Object Map for exposing model View Object String which is a view name Void… if method wrote the response content directly
STORY TITLE WebSphere Portal Technical Conference U.S Spring 2.5 Controller public class ConfController private confDB public String showSessionList(ModelMap model) { model.addAttribute("sessions", this.confDB.getSessions()); return "sessionList"; public void String name, OutputStream outputStream) throws IOException { this.confDB.getSpeakerImage(name,outputStream); public String clearDB() { this.confDB.clear(); return "redirect:sessionList"; }
STORY TITLE WebSphere Portal Technical Conference U.S Compare Controllers Spring w/o annotations Spring w/ annotations
STORY TITLE WebSphere Portal Technical Conference U.S Testing – Here is your Portlet Any Problems testing this code? 36
STORY TITLE WebSphere Portal Technical Conference U.S Spring 3.X – What’s Coming? JSR-286 Portlet Support Java 5+ Only Remove all pre-JDK 5 Dependencies 37
STORY TITLE WebSphere Portal Technical Conference U.S Summary IBM WebSphere Portal Server #1 portal container in the enterprise Spring #1 IoC container and glue of architecture Enables continuous integration Future of Development Annotations Code by convention instead of configuration 38
STORY TITLE WebSphere Portal Technical Conference U.S Additional Information and Resources WebSphere Portal – IBM Site WebSphere Portal Business Solutions Catalog: Websphere Portal Developer’s Zone Product Documentation and WebSphere Portal Wiki Education WebSphere Portal 6.0 DemoNet
STORY TITLE WebSphere Portal Technical Conference U.S Session ID:D19 Session:Annotated Portal Development with RAD and Spring Presenter(s):Ken Sipe, Technology Director, Perficient, Inc. Peter Blinstrubas, IBM Americas Portal Leader Please take a few minutes to fill out the session survey. Thank you Mark your calendars! 2009 U.S. WebSphere Portal Technical Conference October 12-15, 2009, Sheraton San Diego Hotel and Marina WebSphere Portal Technical Conference U.S. 2008
STORY TITLE WebSphere Portal Technical Conference U.S © IBM Corporation 2008 All Rights Reserved. The information contained in this publication is provided for informational purposes only. While efforts were made to verify the completeness and accuracy of the information contained in this publication, it is provided AS IS without warranty of any kind, express or implied. In addition, this information is based on IBM’s current product plans and strategy, which are subject to change by IBM without notice. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, this publication or any other materials. Nothing contained in this publication is intended to, nor shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the use of IBM software. References in this presentation to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates and/or capabilities referenced in this presentation may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to future product or feature availability in any way. Nothing contained in these materials is intended to, nor shall have the effect of, stating or implying that any activities undertaken by you will result in any specific sales, revenue growth or other results. All customer examples described are presented as illustrations of how those customers have used IBM products and the results they may have achieved. Actual environmental costs and performance characteristics may vary by customer. IBM, the IBM logo, WebSphere, Lotus, Lotus Notes, Domino, Quickplace, Sametime, Workplace and Quickr are trademarks of International Business Machines Corporation in the United States, other countries, or both. Java and all Java-based trademarks are trademarks of Sun Microsystems, Inc. in the United States, other countries, or both. Microsoft and Windows are trademarks of Microsoft Corporation in the United States, other countries, or both. Linux is a registered trademark of Linus Torvalds in the United States, other countries, or both. Other company, product, or service names may be trademarks or service marks of others. All references to Renovations Inc. refer to a fictitious company and are used for illustration purposes only.