Download presentation
Presentation is loading. Please wait.
Published byOlivia Powers Modified over 9 years ago
1
© 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
2
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 2 2 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
3
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 3 3 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
4
© 2008 IBM Portal and Portlets 4
5
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 5 5 Portal Anatomy - External 5
6
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 6 6 Portlet Anatomy - Internal These interfaces shape your role in the container and resources available from the container Portlet PortletConfig PortletContext PortalContext
7
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 7 7 Portlet Interface 7
8
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 8 8 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
9
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 9 9 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)
10
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 10 Portlet Modes View mode doView(…) Normal Display Edit mode doEdit(…) Configuration mode of the portlet Location details Personal preferences Help mode doHelp(…)
11
© 2008 IBM Simple HelloWorld Portlet Example 11
12
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 12 Portal Tool Features v7.x Streamlined Portlet Wizard Co-operative Wizard Usability improvement. Enhanced Credential Vault Support. JSR 168 and JSR 286
13
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 13 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”); }
14
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 14 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
15
© 2008 IBM Spring Spring MVC Portal 15
16
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 16 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
17
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 17 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
18
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 18 Spring Portlet XML File Defines Controller and other Spring Beans Maps Controller for each mode
19
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 19 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"); }
20
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 20 Spring View Mapping <bean id="viewResolver“ class= "org.springframework.web.servlet.view.InternalResourceViewResolver"> org.springframework.web.servlet.view.JstlView /WEB-INF/jsp/.jsp
21
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 21 Changes to Web.xml ContextLoaderListener Listener to bootstap spring ViewRendererServlet Front Controller for Spring Portlet MVC
22
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 22 Spring applicationContent.xml Required by ViewRendererServlet Provides Shared Spring beans across portlets
23
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 23 Spring Portlet MVC Setup Jars: Spring Spring.jar, spring-webmvc-portlet.jar Logging Commons-logging.jar, log4j-1.2.14.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
24
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 24 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
25
© 2008 IBM Spring 2.5 Annotations 25
26
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 26 Java 5+ Annotations Java 5 Introduces Annotations New Type of Interface Provides Metadata for: Compile time Runtime Language Provides Built-in Annotations @Override Ability to Define Custom Annotations Annotation Creation @Retention(RetentionPolicy.RUNTIME) public @interface Author { String name(); } Annotation Use @Author ( name = "John Doe" ) public class OrderDAO { // class code goes here } 26
27
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 27 Spring 2.5 Annotations JSR 250 - @PostConstruct, @Resource… JAX-WS 2.0’s - @WebServiceRef EJB 3.0 - @EJB Test Enhancements - Junit 4.4 and TestNG Stereotypes - @Component, @Controller… Spring enhancements - @Autowired, AOP - @Configurable MVC annotations - @RequestParam, @RequestMapping… 27
28
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 28 Spring 2.5 Context Annotations @Scope Indicates the scope to use for annotated class instances Default == “singleton” Options: Singleton Prototype Web Options: Request Session Global session
29
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 29 Spring 2.5 Stereotypes @Component ** Indicates that a class is a component Class is a candidate for auto-detection Custom component extensions @Controller Specialized Component Typically used with RequestMapping annotation Discussed in section on web mvc @Repository 2.0 stereotype… previously mentioned Now an extension of @Component @Service Intended to be a business service facade
30
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 30 Spring 2.5 Factory Annotations @Autowired Marks a constructor, field, setter or config method for injection. Fields are injected After construction Before config methods @Autowired(required=false) Config: AutowiredAnnotationBeanPostProcessor @Configurable Marks class as being eligible for Spring-driven configuration Used with AspectJ @Qualifier Qualifies a bean for autowiring May be customized @Required Marks a method as being injection required
31
© 2008 IBM A World with No Editor Support 31
32
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 32 Spring 2.5 MVC Annotations @Controller Stereotype used to “Controller” of MVC Scanned for RequestMappings @RequestMapping Annotates a handler method for a request Very flexible @RequestParam Annotates that a method parameter should be bound to a web request parameter SessionAttributes Marks session attributes that a handler uses
33
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 33 @RequestMapping - Extreme Flexibility Parameters can be Request / response / session WebRequest InputStream OutputStream @RequestParam +++ 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
34
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 34 Spring 2.5 Controller Example @Controller public class ConfController { @Autowired private confDB confDB; @RequestMapping("/sessionList") public String showSessionList(ModelMap model) { model.addAttribute("sessions", this.confDB.getSessions()); return "sessionList"; } @RequestMapping("speakerImage") public void streamSpeakerImage(@RequestParam("name") String name, OutputStream outputStream) throws IOException { this.confDB.getSpeakerImage(name,outputStream); } @RequestMapping("/clearDatabase") public String clearDB() { this.confDB.clear(); return "redirect:sessionList"; }
35
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 35 Compare Controllers Spring w/o annotations Spring w/ annotations
36
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 36 Testing – Here is your Portlet Any Problems testing this code? 36
37
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 37 Spring 3.X – What’s Coming? JSR-286 Portlet Support Java 5+ Only Remove all pre-JDK 5 Dependencies 37
38
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 38 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
39
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 39 Additional Information and Resources WebSphere Portal – IBM Site http://www-3.ibm.com/software/genservers/portal/ WebSphere Portal Business Solutions Catalog: http://catalog.lotus.com/wps/portal/portal Websphere Portal Developer’s Zone http://www-106.ibm.com/developerworks/websphere/zones/portal/ Product Documentation and WebSphere Portal Wiki http://www-3.ibm.com/software/genservers/portal/library/ http://www-10.lotus.com/ldd/portalwiki.nsf http://springsource.com/ Education http://www-3.ibm.com/software/genservers/portal/education/ WebSphere Portal 6.0 DemoNet http://docs.dfw.ibm.com/wp6/?DDSPageRequest=/
40
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 40 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
41
STORY TITLE WebSphere Portal Technical Conference U.S. 2008 41 © 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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.