aspose file tools*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: s:select and data conversion
 
Similar Threads
Struts 2 and Hibernate
Data loading problem in select tag using ajax in struts2
Reset the collection content in bean:define
How to retreive multiple select in s:select
Strut-Ajax - display states when Country selected