Posts Tagged ‘spring mvc’

Guess what?

Thursday, June 17th, 2010

With the fantastic weather outside, I needed to take a break in my training. My legs felt very tired this morning and my heart rate just would not go above 155 bpm: all the signs to take a rest day. Now, rest day for the legs does not mean rest day for the brain! And so, I put some more pages to the Beginning MVC chapter. Download here.

Oh, and one more thing. I spoke to Gregory from Mulesoft today and we had an interesting chat about OSGi. I will add my thoughts about this soon, in the meantime read Ross’s post at http://rossmason.blogspot.com/2008/04/osgi-is-irrelevant.html.

More Open Spring 3 MVC goodies

Tuesday, June 15th, 2010

I have been very busy indeed, but managed to find some time to add more text to the Beginning Spring MVC chapter of Open Spring 3. Get downloadin’!

Open Spring 3 updated

Wednesday, April 28th, 2010

Good news everyone! I’ve added a few pages to the Beginning Spring MVC chapter of the Open Spring 3 book. Download here for your reading pleasure!

Open Spring 3

Saturday, April 3rd, 2010

Chapters for download are:
Beginning Spring MVC


I was thinking about the name of our new “unbook”. The “Pro” series are in the domain of Apress, the “In Action” books are published by Manning; I don’t know what O’Reilly call their books, but I wanted to make sure I don’t step on anyone’s toes.
In line with our advocacy of the open source, I decided to call the book Open Spring 3. I wanted to emphasise that it is a continuation of our Pro Spring series (in terms of scope and, I hope, quality and popularity), but that is is fundamentally different from the traditional printed books. And so, we give you Open Spring 3.
Open Spring 3 is just the first one in what we hope will become a series of other books, all covering various open source technologies and all available for free (both as in speech and beer) online.

Spring MVC on the iPhone

Thursday, March 25th, 2010

…and, as we discovered at the Open Source User Group meeting on 24th March, also on the iPod Touch!
If you’d like to explore in detail the application I used yesterday, download it from GitHub. The webapp uses, as the headline suggests, Spring MVC (with particular focus on ViewResolvers), and alongside the bog-standard JSP code, exploits jQTouch to make the iPhone/iPod Touch interface look very native app-like.
Alternatively, if you don’t want to get messy with the source code, you can just download the Spring MVC iPhone Slides.

Spring and iPhone

Monday, March 15th, 2010

The talk for next week’s open source user group is ready. I will give brief overview of Spring 3 MVC and explain how to create native-looking iPhone web application using as little code as possible.
It would not be a proper user group talk without a live demo, so bring your good selves with your iPhones and we’ll create a Spring MVC application that looks just amazing on the iPhone, all within about 25 minutes!
Figure 1 shows what we will achieve: the iPhone will send a request through the Internet to our Tomcat, where our Spring-driven MVC application is going to process it.
smvci
Figure 1. Spring MVC & iPhone

Spring MVC and iPhone

Tuesday, February 23rd, 2010

I have exciting new talk ready for the next open source user group meeting. We will implement a very friendly iPhone web application using Spring MVC 3.0 in about 30 minutes’ time while keeping the controllers and models completely intact.
I don’t want to spoil the show; come along and don’t forget to bring your iPhones for testing.

Custom arguments for @RequestMapping methods

Friday, October 23rd, 2009

So, Spring MVC fans, let’s say you have a @RequestMapping-annotated method in your controller, but you would like to include a custom argument, in addition to the standard ones like Model, HttpServletRequest, and HttpServletResponse.
The solution is to implement a WebArgumentResolver. As an example, we’ll create a CurrentDateWebArgumentResolver; as its name suggests, this resolver will be able to set any Date argument in the controller method to current date.
We have to write

public class ContextExtractingWebArgumentResolver
    implements WebArgumentResolver {

    @Override
    public Object resolveArgument(MethodParameter methodParameter,
        NativeWebRequest webRequest) throws Exception {
        if (Date.class == methodParameter.getParameterType()) {
            return new Date();
        }
        return UNRESOLVED;
    }
}

We then wire-in the argument resolver in our Spring application context configuration file:

<bean class="org.springframework.web.servlet.mvc.annotation.
      AnnotationMethodHandlerAdapter"
    <property name="customArgumentResolver">
        <bean class="package.ContextExtractingWebArgumentResolver"/>
    </property>
</bean>

Once done, we can create a @RequestMapping-annotated method in our controller and include the Date argument; that argument will now receive the current date. For example, we can have

@Controller
public class HomeController {
    @RequestMapping(value="/index", method=RequestMethod.GET)
    public void index(Date date, Model m) {
        m.addAttribute("now", date);
    }
}

The model that will be passed to the view after making a GET request to the /index URL will include attribute named now; the value of the attribute will be the current time.
Naturally, this is just a simple example and injecting current date is not very enterprisey thing to do, but using the approach I have outlined, you can now set much more useful argument types. Do not forget that the implementation of the WebArgumentResolver is a Spring bean, thus having access to all features available in the Spring application context.

Spring MVC Volume II

Wednesday, October 21st, 2009

It was my pleasure to deliver my Spring MVC talk at the Java User Group meeting in London yesterday. I loved the audience–they asked the right questions at the right time; at times they were paying too much attention and spotted a bug! Mea maxima culpa, all is corrected now.

The slides and the source code are available at http://github.com/janm399/smvc/tree/master.

I’d love to hear suggestions for the next talk–I am thinking about advanced Spring MVC, where we take a look under the hood of the AnnotationMethodHandlerAdapter and its friends. Alternatively, we could leave the cushy OO world behind and dive into AOP, with focus on [Spring|Dynamic] AOP.

Please comment or tweet to @honzam399.

Spring MVC at London JUG

Friday, September 4th, 2009

I had the privilege of giving a talk on Spring MVC at yesterday’s London JUG meeting. I had a full room of Java programmers keen to find out about how to write Spring MVC web applications. I hope that all attendees went away with good understanding of just how easy it is to write the Ms, Vs and Cs in Spring MVC.
You can download the source code of the talk from http://github.com/janm399/smvc/tree/master; the PDF version of the talk is available here.

I’d be happy to give a repeat of the talk at another JUG meeting or, if you prefer, give another talk on Spring-related topic. Spring AOP seemed to be quite popular!