views:

23

answers:

1

I have an Object who's internal representation is not conducive to data entry. I have a class with multiple custom components, one of which is a Range class. The Range class is easiest to input using two text field inputs rather than as one text field that uses a custom PropertyEditor.

I have a fully functional constructor that could handle the multiple field option but I don't believe there's anyway to get Spring to use the constructor rather than setter injection. Am I wrong about that? If I'm not, is it possible to bind two form elements to a single object member using a custom PropertyEditor or some related method?

Thanks!

+2  A: 

I don't quite see the problem, assuming your Range object has 'rangeStart' and 'rangeEnd' properties. With one of the fields use <spring:bind path="yourObject.rangeStart"> and with the second field use <spring:bind path="yourObject.rangeEnd">.

Bozho
Sorry. I wasn't at all clear. The problem (as seen in the edits above) is that the Range class is nested inside of the class the form is actually bound to. I hear that in Grails I could say `<spring:bind path="food.range.start">` but I couldn't figure out if that's possible in Spring.
Tim Visher
you can. try it.
Bozho
You can, IFF range is non-null. A NPE will be thrown otherwise, the binder will not construct the range instance for you if it is null.
MetroidFan2002