• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Populate multiple pojo's.

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi All,

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.

Any help would be grateful.

thanks.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just name your parameters appropriately; address.addr1, address.state, person.firstName, whatever.
 
Shane Hanswyk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David for your reply.

I don't have control over the jsp. Is there any way of doing it in the Action?

ie. Maybe an intercept somewhere??
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Shane Hanswyk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

cheers.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's possible, using the "alias" interceptor.
 
Shane Hanswyk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hmmm....interesting.

How would I go about coding this or, can you point me to somewhere that has this documented. I couldn't find any good examples.

Thanks.
 
Sheriff
Posts: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you checkout the apache's documentation??
 
Shane Hanswyk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Yes. That does not explain how to do it without "referencing every property individually".
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

I still don't think it's worth it, though.
 
Shane Hanswyk
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree.

Thanks for all your help, David.
 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic