Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

s:select and data conversion

 
Fedor Smirnoff
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • 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
 
Tom Rispoli
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic