Posts

Showing posts from July, 2010

Request Object and Spring DataBinders

I am fan of spring framework and I love to use it all the times. In this post I am going to show you how you can bind the data from ServletRequest object to any Java Bean (POJO). Let’s say you have a spring web application and you are working on piece of code which is not directly interacting with Web layer (i.e. don’t have direct access of Request and Response Objects), so 2 questions rises here are: 1) How can I get access of my current request object in plain java class which is not a web component? 2) How can I bind the parameters in request object to my POJO bean? Request Object access in non web classes There are ways with which you can make you springs beans aware of ServletRequest object by implementing the interface ServletRequestAware (interface from opensymphony-webwork). But, there is another easier way of doing it with the help of spring Utility classes.         ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder. getRequest