PDA

View Full Version : Trying to get InitBinder to work with custom date format



wdragon
Nov 18th, 2008, 11:43 PM
Hi guys - I'm trying to use a specific date format for Spring. The default as most of you know is yyyy-MM-dd and I want it to be dd-MM-yyyy.

I've been around on the web for 2 days looking at solutions and trying to understand the mechanics of it all. But now I've seem to hit a brick wall.

The issue is I know it is quite easy to write my own initBinder method in a controller to do all this. However, our system is not designed with a normal controller. We are using a flowcontroller which would be fine if we were using formActions but again it has been designed without formActions.

How it is strung together is with the StereoType Annotation: Service (org.springframework.stereotype.Service)

So the start of the code looks something like this:


..
@Service("companyAction")
public class CompanyAction
..


I'm don't fully understand the StereoType annotation: Service but from what I can gather it does most of the default auto binding for you and behaves much like a component.

So my problem is I can't find a way to start injecting code in that will help me change the default date format that spring expects. Some thing on the lines of initBinder.

Thanks!

cmelgar
Nov 18th, 2008, 11:58 PM
See the webflow manual http://static.springframework.org/spring-webflow/docs/2.0.x/reference/html/ch04s07.html

wdragon
Nov 19th, 2008, 09:43 PM
Thanks for the pointer cmelgar. That cleared up a lot. Although it doesn't talk about changing the expression-parser which is brought up in this thread: http://forum.springframework.org/showthread.php?t=59042

But thanks again it really helped!


See the webflow manual http://static.springframework.org/spring-webflow/docs/2.0.x/reference/html/ch04s07.html

wdragon
Nov 23rd, 2008, 07:19 PM
I swear I posted a thanks to you cmelgar, I mustn't have hit submit. Anyways my success was short lived.

I had it all working properly.

To do this I had to specify the expression-parser to use my custom conversion service as well (they don't completely tell you in the example). Everything was working fine as we didn't use flowscope.Model to specify the model in a view state. We simply used just the model.

However, a workmate is now using a flowScope.Model as the model of the view state (so that navigating back will give you back the values before hitting the submit button) - this turns up with a strange bug in that the dates are formatted with "Mon Nov 24 00:00:00 EST 2008" instead of dd/MM/yyyy.

It seems to be skipping over my custom conversion service. Anyone know a solution to this?