Shaun Abram
Technology and Leadership Blog
Handsontable ‘Spreadsheet’ talking to SpringMVC
Handsontable is an Excel-like data grid utilizing JQuery. For example, it provides the ability to copy and paste directly to & from Excel. Handsontable itself if very easy to setup. The part I struggled with was passing the data to SpringMVC. So, this post shows how to send data from a Handsontable data grid on the client to a SpringMVC server.
Tags: excel, handsontable, JavaScript, jQuery, jsp, spreadsheet, spring, springmvc
SpringMVC file download
This post shows how to download a file using Spring MVC. For example, you have a SpringMVC web app and you want to include a link on a page that downloads a file to be opened on the user’s machine (e.g. a Microsoft Excel).
Read more
MyMoney – A simple SpringMVC app
I created a small, open source web app called MyMoney for entering and tracking spending details. It allows you to create accounts (for example Cash or Checking) and enter transactions associated with those accounts.
(Previously I had the code deployed on a CloudBees instance at http://mymoney.shaunabram.cloudbees.net, but CloudBees have since unfortunately shut down their free tier). Read more
Tags: Hibernate, spring, springmvc
415 ‘Unsupported Media Type’ error when submitting JSON from a JSP
I’ve been experimenting with submitting JSON data from a JSP to a Spring MVC Controller, using the Spring MVC Ajax example as my guide.
But after setting everything up, I continually ran into this error:
NetworkError: 415 Unsupported Media Type
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method().
After much googling, I found a plethora of solutions, none of which worked for me. In the end, I found it was because I had omitted this line from my JSP:
">
Hope that helps someone else…
Tags: json, jsp, spring, springmvc
Spring MVC Hello World with Continuous Deployment
Oh dear, yet another ‘Hello World!’. But although the functionality is trivial, this little SpringMVC project is complete enough for me to use as a template to bootstrap more complex projects. It consists of:
- HTML/JSP client
- SpringMVC server using a Controller/Service/DAO design
- Maven for build and dependency management
This is an updated version of an older project I created, with the following enhancements:
- Added a full suite of automated tests (unit, integration and browser based)
- Added placeholders for JavaScript and images (both can be a little tricky to put in the correct place with SpringMVC)
- Incorporated into a continuous deployment environment
More details below, but you can find the full source code on this GitHub repository
(Previously I had the code deployed on a CloudBees instance at http://springmvc.shaunabram.cloudbees.net, but CloudBees have since unfortunately shut down their free tier).
Tags: cloud, cloudbees, continuousdeployment, continuousintegration, easymock, fest, helloworld, jenkins, spring, springmvc, Testing, unittesting
Spring MVC Hello World
There is a good Getting Started with Spring MVC blog post over on the Spring team blog.
I have created several Spring MVC projects for both work and play, and am attaching my own simple version of the HelloWorld example here, based on the Spring blog example.
Find my maven ready source here.
Like my previous JSP/Servlet example, I find these templates useful for getting prototypes up and running.
Tags: helloworld, jsp, servlet, spring, springmvc, webapp, webframework
Spring Enterprise Recipes
I recently found out that this book has just been published:
“Spring Enterprise Recipes: A Problem-Solution Approach”
It is written by Josh Long and Gary Mak. I have heard Josh speak at several conferences, followed his articles on TheServerSide (as well as on his blog) and recently got to hang out with him at the SoCal Code Camp. He is very knowledgeable about Spring and enterprise integration and since Gary is already an author of one of the leading Spring books (Spring recipes), this should be a great book. I have just ordered my copy and will try to post a review when I am done with it.
‘An Introduction to Spring’ at LA Code Camp
I gave my ‘An Introduction to Spring’ talk today at the LA code camp. It went fairly well I think. I had very little time to go through the Spring MVC module at the end, but perhaps I will give that as a separate talk another day.
I have posted the presentation slides here.
Tags: codecamp, mytalks, spring
Speaking at LA Code Camp
I am very pleased to say I will be speaking at the LA Code Camp this weekend. My topic is An Introduction to Spring. I will try to post a report from the code camp this weekend…
This is the same talk I had planned to present at the Silicon Valley Code Camp, so great to be finally giving it…
Data binding in Spring MVC
Two of the most important tasks carried out by Spring MVC when you submit a form are Data binding and validation.
The following article discusses data binding, including the use of custom PropertyEditors, and some of the options available for registering such editors. Most of the information discussed applies to Spring in general, but its application in Spring MVC is my primary interest.
In a future article I would like to discuss validation including the use of custom error messages.
Note that these notes relate to version 2.5.6 of Spring, the latest production code at time of writing, and depend heavily on the corresponding Spring reference docs.
JavaBeans vs Spring beans vs POJOs
The terms JavaBeans, “Spring beans” and POJOs are in widespread use and this article discusses each and the differences between them.
JavaBeans
At a basic level, JavaBeans are simply Java classes which adhere to certain coding conventions. For example, classes that
- Have a public default (no argument) constructor
- allows access to properties using accessor (getter and setter) methods
- Implement java.io.Serializable
More accurately, JavaBeans are classes that adhere to Sun’s JavaBeans spec, first published way back in 1996. A JavaBean was defined as a “software component model” for Java. The idea was that JavaBeans would be reusable software components that could be manipulated visually in a builder tool and that vendors would create and sell JavaBeans that could be composed together into applications by end users. The three most important features of a Java Bean are
- the set of properties (named attributes) it exposes
- the set of methods it allows other components to call
- the set of events it fires (to notify registered listeners of changes)
POJO
POJO is an acronym for Plain Old Java Object. The term was coined by Martin Fowler et. al., as a ‘fancy’ way to describe ordinary Java Objects that do not require a framework to use, nor need to be run in a application server environment. It is often used to distinguish simpler, lightweight Java objects from ‘heavyweight’ code like EJBs. The use of these kind of lightweight objects in programming is described in books such as “POJOs in Action” and advocated by frameworks like Spring.
Spring beans
A Spring bean is basically an object managed by Spring. More specifically, it is an object that is instantiated, configured and otherwise managed by a Spring Framework container. Spring beans are defined in a Spring configuration file (or, more recently, by using annotations), instantiated by the Spring container, and then injected into your application.
The reason Spring managed objects are referred to as beans is because in the very early versions, Spring was intended only for use with JavaBeans. That is no longer the case of course: Spring can manage just about any object, even if it doesn’t have JavaBean type characteristics such as default constructors or mutator methods (getters and setters). None the less, the term ‘Spring beans’ has stuck.
Can Spring beans be POJOs? Yes, and they usually are (although they don’t have to be – e.g. Spring can be used with ‘heavyweight’ Java objects, such as EJBs).
Can Spring beans be JavaBeans? As I have said, yes and again they often are but don’t have to be.
Summary
Although it have been well over 10 years since the JavaBeans spec was first published, it still carries weight and has influence the development of modern frameworks such as Spring. But while Java objects that have default constructor and use accessor methods for private fields may legitimately be called JavaBeans, the whole “reusable software component that can be manipulated visually in a builder tool” concept isn’t particularly popular anymore.
POJOs, however, are everywhere and the a backlash against the complexities for EJBs has resulted in widespread use of ‘lightweight’ Java programming.
Spring beans are objects created and managed by the Spring framework.
None of the 3 terms discussed are mutually exclusive. A Java object can be a JavaBean, a POJO and a Spring bean all at the same time.
Tags: JavaBeans, POJO, spring, Sun
Spring talk canceled
With much reluctance, I have had to cancel my planned Spring presentation at Silicon Valley Code Camp this weekend. I have been knocked out with flu all week and I am still hoarse, so giving a one hour talk is, unfortunately, not an option.
It is a shame as there was a lot of interest in the talk but in this instance can’t be helped.
CodeCamp 2009: An Introduction to Spring
As I posted about earlier, the Silicon Valley Code Camp 2009 is coming up and this year, I am planning on presenting a session on the Spring framework.
You can find my session details here: An Introduction to Spring.
Spring and EJB 3 Integration
I attended another excellent SF JUG meeting earlier this month. It was a double billing with Talip Ozturk talking about Hazelcast, an opensource clustering and data distribution platform, and Reza Rehman speaking about EJB3 and Spring Integration.
Reza is the author of EJB3 in Action and an accomplished speaker whom I had the chance to meet at The Server Side Symposium earlier this year, so I was particularly interested in his talk.
Reza gave some background on EJBs and how they have been completely reinvented as part of the latest (EJB3) release, including using 100% annotations (no xml) and making heavy use intelligent defaulting. He also talked about how Spring became popular as an alternative to the heavyweigth approach of the older EJB releases and has thrived through its focus on integration with standards like JPA, JMS, JDBC and JAX-WS.
He then went on to his main point, which was that EJB3 and Spring can now be viewed as complimentary, rather than competing, technologies and he went on to back this up by discussing the integration strategies that can be used, including
- Embedding Spring inside a Java EE app server
- Embedding an EJB3 embeddable container withing Tomcat with Spring
- Enabling Spring @Autowired annotation in EJBs via Interceptors
- Using EJB3 natively inside Spring using Spring Pitchfork
Reza finished by reiterating the benefits of using Spring and EJBs together to increase ease of coding and vendor neutrality.
Overall, I thought it was an insightful presentation from Reza. I had studied EJBs back in the v2 release as part of the my SCEA certification, and have used Spring in several projects, but this was the first time I had a chance to hear how they can be used together.
I have made Reza’s presentation notes available here, as well as his demo source code available here. You can also follow him on his web site and blog at: www.rahmannet.net.
TheServerSide Java Symposium – Day 2
Day 2 at TSS Java Symposium.
The highlights of the second day at TSSJS2009 were a couple of interesting talks from Rod Johnson (Mr Spring) and a talk on Groovy from Scott Davis (Groovy.com).
I have included links to some of my (limited) notes below, which includes links to the actual presentation slides (PDFs) where available.
Keynote: How Spring Fits into the Java Landscape – Rod Johnson
Spring for the advanced developer – Rod Johnson
The Amazing Grrovy Weight Loss Plan – Scott Davis
Tags: groovy, spring, theserverside, tss