*
The moose likes Struts and the fly likes s:select and data conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "s:select and data conversion" Watch "s:select and data conversion" New topic
Author

s:select and data conversion

Fedor Smirnoff
Ranch Hand

Joined: Apr 21, 2003
Posts: 45
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

Joined: Aug 29, 2008
Posts: 349
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?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: s:select and data conversion