1 / 54

Developing Rich Web Applications with Spring

Agenda. A little bit about your speakerDeveloping rich web applicationsProgramming modelConvention-over-configurationAjaxFlowSecurityJavaServerFacesBetter modularity with OSGi. My Background. SpringSource Co-FounderBased in Melbourne FloridaApplication DeveloperSpring Project LeadAuthorSeveral Spring booksSpring Training CurriculumConference Director, The Spring ExperienceJavaOne and NFJS SpeakerJCP Expert Group Member.

talasi
Download Presentation

Developing Rich Web Applications with Spring

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


    1. Developing Rich Web Applications with Spring Keith Donald

    2. Agenda A little bit about your speaker Developing rich web applications Programming model Convention-over-configuration Ajax Flow Security JavaServerFaces Better modularity with OSGi

    3. My Background SpringSource Co-Founder Based in Melbourne Florida Application Developer Spring Project Lead Author Several Spring books Spring Training Curriculum Conference Director, The Spring Experience JavaOne and NFJS Speaker JCP Expert Group Member

    4. Where I Work

    5. Our Open Source Projects

    6. Our Commercial Products

    7. SpringSource Enterprise

    8. SpringSource dm Server™

    9. Agenda A little bit about your speakers Developing rich web applications Programming model Convention-over-configuration Ajax Flow Security JavaServerFaces

    10. Modules Covered Spring Web MVC foundation for all other web modules Spring JavaScript Ajax support Spring Web Flow framework for stateful interactions Spring Faces JavaServer Faces support

    11. Layered Web Modules

    12. Obtaining Code See www.springframework.org/download Web MVC Download Spring Framework 2.5.x JavaScript, Web Flow, and Faces Download Spring Web Flow 2.0.x Sample Application See www.springframework.org/webflow-samples

    13. Spring Web MVC Popular web framework Foundation for all other web modules Significantly enhanced in Spring 2.5 Annotated controller model Convention-over-configuration

    14. Annotated Controller Model Annotate a plain Java™ class as a Controller Map HTTP requests to methods Bind request parameters to method arguments Populate Model to export data to the view Return a String to select a view

    15. Example @Controller to manage hotels GET /hotels/list List hotels available for booking

    16. Example @Controller @Controller public class HotelsController { @RequestMapping(“/hotels/list”, method=GET) public String list(Model model) { model.add(“hotels”, hotelService.findAll()); return “/hotels/list”; } }

    17. Example Request Lifecycle

    18. Before Spring Web MVC 2.5 public class HotelsController extends MultiActionController { public ModelAndView list( HttpServletRequest request, HttpServletResponse response) { ModelAndView mv = new ModelAndView(); mv.add(“hotels”, hotelService.findAll()); mv.setViewName(“/hotels/list”); return mv; } } + External XML URL Mapping Configuration

    19. Convention over configuration Write less code, get consistency Conventions available for Request mapping View name selection Model population Can always override when needed

    20. With Conventions @Controller public class HotelsController { @RequestMapping public void list(Model model) { model.add(hotelService.findAll()); } }

    21. Simplest Signature Possible @Controller public class HotelsController { @RequestMapping public List<Hotel> list() { return hotelService.findAll(); } }

    22. Multi-Action Convention Example @Controller public class HotelsController { @RequestMapping public void index(…) {…} @RequestMapping public void show(…) {…} @RequestMapping public void update(…) {…} }

    23. Data Binding @Controller public class HotelsController { @RequestMapping public void list(Criteria c, Model m) { model.add(hotelService.find(c)); } @RequestMapping public void show(@RequestParam Long id, Model m) { model.add(hotelService.get(id)); } }

    24. @Controller Deployment Found in classpath Auto-wired as Spring beans <!-- Scan for components to deploy as beans --> <context:component-scan base-package=”example.hotels”/>

    25. Autowiring Hints @Controller public class HotelsController { @Autowired public HotelsController(HotelService service) { } }

    26. Mixing Annotations and XML <beans> <context:component-scan base-package=”example.hotels”/> <jee:jndi-lookup id=”dataSource” jndi-name=”eis/jdbc/travelDataSource”/> </beans>

    27. Demo Essential Spring MVC Features

    28. Web MVC Summary Favor @Controller model over old styles Favor convention-over-configuration Favor strongly typed handler methods Consider grouping control logic by Resource e.g. “HotelsController” for acting on Hotel resources

    29. Spring JavaScript

    30. Spring JavaScript JavaScript abstraction framework Use to enhance HTML elements with behavior Integrates the Dojo Toolkit In Web Flow 2 distribution

    31. Goals of Spring JavaScript Simplify use of Dojo for common enterprise use cases Ajax Client-side validation Promote progressive enhancement Graceful degradation Accessibility

    32. Other Spring JavaScript Value Adds ResourceServlet Efficient serving of static resources Meets Yahoo performance guidelines CSS Framework Structure for common page layouts

    33. Using Spring JavaScript Include public API, Dojo, and API implementation in your pages

    34. Working with the API Use API to apply decorations to HTML elements Different types of decorations WidgetDecoration AjaxEventDecoration ValidateAllDecoration

    35. Adding Hover Effect <form:input id="searchString" path="searchString"/> <script type="text/javascript"> Spring.addDecoration(new Spring.ElementDecoration({ elementId : "searchString", widgetType : "dijit.form.ValidationTextBox", widgetAttrs : { promptMessage : "Search hotels by name or location.” } })); </script>

    36. Ajax with Partial Rendering <a id="moreResultsLink” href="search?q=${criteria.q}&page=${criteria.page+1}"> More Results </a> <script type="text/javascript"> Spring.addDecoration(new Spring.AjaxEventDecoration({ elementId: "moreResultsLink", event: "onclick", params: { fragments: "searchResults” } })); </script>

    37. Form Validation <form:input path="creditCard"/> <script type="text/javascript"> Spring.addDecoration(new Spring.ElementDecoration({ elementId : "creditCard", widgetType : "dijit.form.ValidationTextBox", widgetAttrs : { required : true, invalidMessage : "A 16-digit number is required.", regExp : "[0-9]{16}” } })); </script>

    38. Combining with Dojo Query dojo.query('.spring-titlePane-open > h2'). forEach(function(titleElement) { Spring.addDecoration(new Spring.ElementDecoration({ elementId : titleElement.parentNode.id, widgetType : 'dijit.TitlePane', widgetAttrs : { title : titleElement.innerHTML, open : true }} )); }).style('display','none');

    39. Demo Progressive Enhancement with Spring JavaScript

    40. Summary Simple yet powerful API Write consistent JavaScript Promote progressive enhancement Manage partial update complexities Full-power of underlying toolkit available

    41. Spring Web Flow

    42. Spring Web Flow Overview For implementing stateful flows Reusable multi-step user dialogs Plugs into Spring MVC Spring Web Flow 2 available now Incorporates lessons learned from 1.0 Offers many new features

    43. Web Flow Sweet Spot

    44. New Web Flow 2 Features Ajax support Partial page re-rendering in flow DSL Spring security integration Flow-managed persistence Convention-over-configuration View rendering Data binding and validation

    45. Demo Essential Web Flow 2 features

    46. Summary Use Web Flow for stateful use cases Wizards are a good example Run flows alongside stateless Controllers Web Flow 2 is a big step forward Most sophisticated flow engine available

    47. Spring Faces

    48. Spring Faces Makes JSF a view technology in Spring Render JSF views from Spring MVC Controllers and Web Flows Drives JSF lifecycle from within Spring environment

    49. Spring Faces All native Spring MVC features available All phases of the JSF lifecycle implemented Stateless MVC views execute render lifecycle Stateful web flows execute render and postback lifecycles

    50. Key Benefits Action-oriented (Spring MVC) Flexible URL mapping REST-ful controller programming model Model binding and validation Request interception Exception handling Web Flow Component-oriented (JSF) Composite views (Facelets) Ecosystem of available component libraries Ability to create new components to enable reuse

    51. Demo Spring Faces Combining the best of action-oriented and component-oriented development

    52. Summary Spring Faces enables the best of action-oriented and component-oriented development Work with Spring MVC and JSF in the same application Stateless Spring MVC Controllers can render transient JSF views Stateful Spring Web Flows can render JSF views and process view post backs Major JSF component libraries supported

    53. Spring 3.0 Roadmap REST support URI templates Content negotiation JSON, Flex remoting Declarative Validation @Flow, as an alternative to XML Improved packaging Optimized for Java 5 and >

    54. Presentation Summary Spring offers a lot for rich web application development Get involved at www.springframework.org Get enterprise support and tools at www.springsource.com Join us for a rich web training workshop at www.springsource.com/training

    55. Questions?

More Related