I am using Struts 2 to perform servlet processing but am having trouble determining how to populate multiple pojo's with the parameter values.
My Action class looks as follows:
Address and Person are pojo's.
I would like to populate the fields in the Address and Person pojo's with the parameter values passed to this action.
I know that I can implement ModelDriven to return (and populate) address but of course, nothing will be populated into person.
I am also aware that I can implement ParameterAware which gives me a Map of parameters but I assume I would then have to individally populate the member fields of each pojo. Is there any easier way and/or am I missing something? My jsp pages are not using struts tags.
There's a property mapping interceptor somewhere, um... "alias" interceptor.
Another less "mysterious" option would be to create action properties for what you *are* getting and do the conversion in the action. I'm a big fan of interceptors, but quit frankly, not a huge fan of things like the "alias" interceptor.
Joined: Jan 12, 2010
Thanks again David.
I was hoping for a solution that wouldn't involve me referencing the properties individually. It appears this is not possible.
I think the best option is to create the action properties and do the conversion - as you suggested.
The "alias" interceptor docs explain how to set up the mapping. Yes, you'd (most likely--check the underlying implementation to see if there are shortcuts available) need to map each property separately in the interceptor config for that action.