background preloader

Spring 3.0

Facebook Twitter

Spring MVC form handling annotation example. In this tutorial, we show you how to do form handling by using annotation in Spring MVC web application. 1. SimpleFormController vs @Controller In XML-based Spring MVC web application, you create a form controller by extending the SimpleFormController class. In annotation-based, you can use @Controller instead. SimpleFormController public class CustomerController extends SimpleFormController{ //...} Annotation @Controller @RequestMapping("/customer.htm")public class CustomerController{ //...} 2. formBackingObject() vs RequestMethod.GET In SimpleFormController, you can initialize the command object for binding in the formBackingObject() method.

@Override protected Object formBackingObject(HttpServletRequest request) throws Exception { Customer cust = new Customer(); //Make "Spring MVC" as default checked value cust.setFavFramework(new String []{"Spring MVC"}); return cust; } 3. onSubmit() vs RequestMethod.POST In SimpleFormController, the form submission is handle by the onSubmit() method. Bean Validation: Integrating JSR-303 with Spring « JTeam Blog / JTeam: Enterprise Java, Open Source, software solutions, Amsterdam. I recently had a chance to actually use the new Bean Validation spec. in one of my projects. As the developer of the Bean Validation Framework for Spring (part of the springmodules project) it of course feels a bit weird to ditch all the work I've done, but at the same time, it also feels good to use a standard spec that very soon will be finalized.

As a member of the JSR-303 expert group (although quite a quiet member) I can assure you that the guys (special kudo's to Emmanuel Bernard) worked really hard to come up with a specification that will fit in many of the different programming models and technologies we all use (e.g. JPA, JSF, Swing, etc..). In this writing, I'd like to show you a how you can integrate Bean Validation in your Spring based application, especially if you're using Spring MVC. JSR-303 is a specification for Bean Validation.

The work on it started around one and a half years ago as an attempt to come up with a standard declarative validation framework. Done! Spring 3 MVC and Hibernate 3 Example Part 2. Spring 3 Type Conversion and Validation. The Spring 3 final release is right around the corner, and it's going to be a great release. In this blog entry, I will take you through some of Spring 3's type conversion and validation enhancements. Whether you are developing a traditional web application, a desktop application, or a "next-generation" RIA, data binding, type conversion, and validation are important areas. As you'll see in this entry, Spring 3 gives you a significant upgrade in each of these areas while preserving backwards compatibility with previous releases.

New System Goals Before I get into features, I'd first like to highlight the goals we had when we set out to improve Spring 3's data binding system: As Spring 3 final approaches, I believe we have delivered on each of the goals. Features The first environment that takes full advantage of the new type conversion system is Spring MVC, which I'll pull from to demonstrate the new features. ... printed on a form for users in the US and DE Locales: Parameter Annotations. Spring Web Flow Portal. 15. Web MVC framework. 15.1 Introduction to Spring Web MVC framework The Spring Web model-view-controller (MVC) framework is designed around a DispatcherServlet that dispatches requests to handlers, with configurable handler mappings, view resolution, locale and theme resolution as well as support for uploading files.

The default handler is based on the @Controller and @RequestMapping annotations, offering a wide range of flexible handling methods. With the introduction of Spring 3.0, the @Controller mechanism also allows you to create RESTful Web sites and applications, through the @PathVariable annotation and other features. In Spring Web MVC you can use any object as a command or form-backing object; you do not need to implement a framework-specific interface or base class. Spring's data binding is highly flexible: for example, it treats type mismatches as validation errors that can be evaluated by the application, not as system errors. Spring's view resolution is extremely flexible. Table 15.1. <? REST in Spring 3: @MVC. In the last couple of years, REST has emerged as a compelling alternative to SOAP/WSDL/WS-*-based distributed architectures. So when we started to plan our work on the next major release of Spring - version 3.0, it was quite clear to us that we had to focus on making the development of 'RESTful' Web services and applications easier.

Now, what is and isn't 'RESTful' could be the topic of a whole new post all together; in this post I'll take a more practical approach, and focus on the features that we added to the @Controller model of Spring MVC. A Bit of Background Ok, I lied: there is some background first. If you really want to learn about the new features, feel free to skip to the next section. For me, work on REST started about two years ago, shortly after reading the highly recommended book RESTful Web Services from O'Reilly, by Leonard Richardson and Sam Ruby. Around the same time we introduced the annotation-based model of Spring MVC. RESTful features in Spring MVC 3.0 URI Templates. Spring Security 3 (9781847199744): Peter Mularien. MVC Simplifications in Spring 3.0.

As Juergen and Arjen have mentioned, Java developers everywhere have a smooth upgrade with Spring 3.0. Now that Spring 3 is out, I'd like to take you through some of the new MVC features you may not know about. I hope you find these features useful and can start putting them to work in your web applications immediately. This is also the start of a series on "Spring 3 Simplifications", so expect more posts like these in the coming days and weeks. Configuration Simplification Spring 3 introduces a mvc namespace that greatly simplifies Spring MVC setup. Mvc-basic has been designed to illustrate a basic set of Spring MVC features. Inside the master servlet-context.xml, you'll find a typical setup.

This tag registers the HandlerMapping and HandlerAdapter required to dispatch requests to your @Controllers. Pretty cool, huh? Moving on, the next line demonstrates another new feature: Behind the scenes, mvc:view-controller registers a ParameterizableViewController that selects a view for rendering. Configuration Simplifications in Spring 3.0. Second in a series of posts on "Spring 3 Simplifications" started yesterday by Keith, I'd like to provide a very brief and hands-on introduction to Spring's new @Configuration annotation and related support. As those that followed the Spring JavaConfig project will know, a @Configuration-annotated class serves much the same role as a Spring XML file. It provides a code-centric way of declaring Spring bean definitions using nothing more than methods and annotations. You might call it Plain Old Configuration* :) This means that for simple situations, no XML will be required!

Let's get started. Svn co configuration-basic cd configuration-basic mvn clean test [...] Eclipse .classpath and .project metadata is also included in the checkout, so you can import the project using the SpringSource Tool Suite, or any recent version of Eclipse with the m2eclipse plugin installed. That's it! I look forward to your feedback. Ajax Simplifications in Spring 3.0. In my last entry, I walked you through several enhancements in Spring 3 for web application development. A number of you expressed interest in a follow-up entry focused on Ajax remoting.

Spring 3 provides a lot in this area to take advantage of. Read on, and I'll walk you through it. Spring and Ajax Overview For the purposes of this article, when I say Ajax, I'm talking about the web browser's ability to communicate with a web server asynchronously using JavaScript. Support for Ajax Clients Until version 3, Spring did not ship support for Ajax remoting. Now that Spring 3 is out, official support for Ajax remoting with JSON is provided as part of Spring MVC.

MVC Ajax Sample mvc-ajax has been designed to illustrate Spring MVC's JSON support. Start your review by deploying the project to your servlet container and accessing the welcome page at localhost:8080/mvc-ajax. Getting JSON from the Server From the welcome page, activate the "Ajax @Controller Example" link. Pretty cool, huh? Summary.