|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Binding multiple values to a single immutable objectHi,
This is actually a repost of a stackoverflow question that I've been unable to get an answer for: http://stackoverflow.com/questions/1644340/multiple-field-ognl-type-converter My problem is that I have an immutable object that is captured in multiple fields on the UI. The http post looks like: capture.id = 213 capture.description = DescriptionText Capture is a property of my new Value type and I have a TypeConverter set-up and ready to convert the field 'capture'. The converter is setup up such that it gets called if the input is: capture = foo Since my value object is immutable I need to be able to construct it with the value of 'id' and 'description'. I had the bright idea over the weekend that the following would work: capture[id] = 213 capture[description] = DescriptionText This actually does a bit better in that my converter gets called, but instead of being called with a map of values it gets called multiple times once for each parameter. The more I look at the Ognl stuff and the ParametersIntercepter the more I've convincing my self that this is just not possible with the framework, can anybody confirm this? A similar problem I that I'm sure somebody must have looked at before is having a separate input fields for day, month and year and have them bound to a single Date instance on the action. I've been looking for some references for this sort of thing, but haven't found the right search term yet. Gareth --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Binding multiple values to a single immutable objectGareth Davis schrieb:
> The more I look at the Ognl stuff and the ParametersIntercepter the > more I've convincing my self that this is just not possible with the > framework, can anybody confirm this? > Others may have a deeper knowledge of the framework, but i would approach your issue differently. Since setters for your html form fields are called independently of each other and in an unpredictable order, you should code your action to have separate members for each of the getters/setters and have your Date instance created properly in your action method. Or you implement a weaker form of immutability that allows an object to shortly exist in an non-immutable state (so you can new it with empty members and have it being accessed directly from your setters) and then "petrify" the object in your action method. We in our project have invented such a pattern ten years ago and are using it ever since without looking back :-) Robert --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Binding multiple values to a single immutable objectThanks, their is a further complexity in my system, in that the exact type
of the Value isn't actually known at compile time it is actually a kinda urber configurable form display, hence the desire to use a TypeConverter, but I think you are right and a different approach is inevitable. Currently looking at binding to a Map of strings and doing the type conversation my self. Thanks Gareth 2009/11/3 Robert Graf-Waczenski <rgw@...> > Gareth Davis schrieb: > > The more I look at the Ognl stuff and the ParametersIntercepter the >> more I've convincing my self that this is just not possible with the >> framework, can anybody confirm this? >> >> > > Others may have a deeper knowledge of the framework, but i would approach > your issue differently. Since setters for your html form fields are called > independently of each other and in an unpredictable order, you should code > your action to have separate members for each of the getters/setters and > have your Date instance created properly in your action method. Or you > implement a weaker form of immutability that allows an object to shortly > exist in an non-immutable state (so you can new it with empty members and > have it being accessed directly from your setters) and then "petrify" the > object in your action method. We in our project have invented such a pattern > ten years ago and are using it ever since without looking back :-) > > Robert > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > > |
| Free embeddable forum powered by Nabble | Forum Help |