Capturing Property Changes with Spring, JPA and Hibernate

It's breathtaking!

Sometimes you need to capture changes to entities just before they get saved to the database. In some systems, a change to a person’s bank account or tax liability may trigger a lot of processing.
While you could be tracking these via DTOs – the process can be quite repetitive and error-prone. You could also use database triggers for that, but you shouldn’t really. Even if the entire extra-processing is inside your database, your application will have no visibility of that.
Continue reading

Add conversation support to Spring MVC

133/365  Cupid

Creative Commons License photo credit: martinak15

One thing I miss in Spring-MVC is the concept of a conversation-scoped attribute. It was supposed to be added in v3.2, but seems to have been pushed back – and I think it might not be done at all, as Spring Webflow currently supports it. However – using webflow just for the sake of enabling a conversation scope seems a bit harsh for my humble Spring-MVC applications. So I went in search of a solution, but ended up writing one myself.
Continue reading

Tabbed forms with Spring MVC and Bootstrap 2

NEC Motorcycle Show (110)

In the previous part of this mini-tutorial, we didn’t actually do much. We really just split a large form into tabs and put it under Twitter Bootstrap’s styles. In this part I’ll show how to implement a cool feature that make your tabbed forms so much more user-friendly: how to return to the active tab on submit.
Continue reading

Spring MVC and Twitter Bootstrap – customizing the input fields

LOL

Creative Commons License photo credit: ~chicchun~

So, in my latest project I am using Twitter Bootstrap together with Spring MVC 3.1. It’s sort of best of both worlds as Bootstrap takes away a lot of the pain on one hand, and Spring deals with the other hand (which works well for me).
Anyway – I am not going to say much more about these guys together – just that it’s been awesome so far, and without further ado here’s a little tag I put together to allow your Spring MVC views to use the Twitter Bootstrap layout, and also display errors in the Bootstrap way.
Continue reading

Pretty file input field in Bootstrap

Jackie Martinez (#31103)

Twitter Bootstrap is great, but there are places where it just stops short. One of those is the file input field, where the guys at bootstrap (and probably rightfully so) – just
left it as the browser default.
The problem is – it makes your pretty bootstrap forms ugly.
No worries – the following can help:
Continue reading

Spring MVC 3.x with STS Tutorial – Part III – Add some JPA

Michelle II

Creative Commons License photo credit: Shandi-lee

In the first version of this post, I showed how to do this using Roo. However, this seems to create too much pain, so I have updated the post to describe ‘normal’ usage of JPA (with the spring-data project). So – if you see comments below that seem irrelevant – this update is the reason.
In the previous part, we set up a little request flow that used Spring MVC to define a request mapping into our DOC system, and provide the user with a list of tramps retrieved from the a service. We also hooked it all up together nicely as components (using the @Controller and @Service Spring Stereotypes) – so they all play together seamlessly.
In this part we’ll get our tramps web application to read tramps information from the database. This is quite easy to do with Spring, using the spring-data project, particularly – spring-jpa.
Continue reading

Customize form:errors output on Spring-MVC

Rylee Brooks

Baa.. took a lot of searching in code, and I don’t particularly like the result – but it is what it is. The main issue is that my designer wanted us to get clever with how form validation error messages are displayed to the user. the <form:errors> tag is very useful for most cases – where you basically only want to display the errors to the users, perhaps with a specific class in mind. You can also ask it to change its default rendering of a <span> element to, say, a <div> element – but my designer wanted something else completely, and sent me on a wild goose chase.
Continue reading

Spring MVC 3.x with STS Tutorial – Part II

Studio_71a

Ok, I finally got around to do this. Sorry for the wait, but I was pre-occupied with, well – life, work and everything in between.

In the first part of this tutorial, I walked through setting STS up, and dealing with the default project you create with the Spring-MVC template. In this part – I want to try and go a bit deeper – so I’ll touch a bit on mapping requests and on displaying data to the user.

Continue reading