• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

s:select and data conversion

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanted to know if with struts 2 you can submit a key from <s:select and have it converted to an object, for example:

I have a state select box populated with:

List<State> stateList;
... stateList populated........

State is a class with:
int id;
String name;

Action has:

State state;
State getState() { return state; }
void setState(State state) { this.state = state; }

when I submit to Action
<s:select name="state" list='stateList' listValue="name" listKey="id" />

My state is NULL. I quess here state is submitted here as a String and not being converted to State object using a key lookup. Any way to select from list of States and receive a State without doing what we have to do with Struts 1, looking up the value to match to Object? Thanks a lot, hope it makes sense
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would think what you are doing should work. If you look at the html source generated for your jsp, are the option tags in the drop down getting the "id"s you have for them?
 
reply
    Bookmark Topic Watch Topic
  • New Topic