This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes how to save select tag's list attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to save select tag Watch "how to save select tag New topic
Author

how to save select tag's list attribute

Andrei Antonescu
Ranch Hand

Joined: Jul 08, 2010
Posts: 75
Hello,

I am having a form that contains <s:select list='persons' name='selectedPerson'.... where persons is a collection of objects of type 'Person' (Id, name, address etc) and it's taken from the database. I want to use validate() to validate the selectedPerson. However if validate() says that it's not ok (by using addFieldError("selectedPerson","required field")), I noticed that the collection "persons" becomes empty. However this is not the case for the values written in textfields & other "simple" stuff.
I don't want to repopulate the list in validate() because I'll be making unnecesary SQL querys to the database.

Can you please tell me how to make this work?


Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Check this faq...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

And welcome to javaranch Andrei
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You could also just keep the list in session or application context, depending on your usecase.

Note that using the <s:action> tag has occasional "gotchas"; Preparable would be preferred over using the tag (in my opinion).
Andrei Antonescu
Ranch Hand

Joined: Jul 08, 2010
Posts: 75
The solution was excellent.
Thanks a lot.
 
Don't get me started about those stupid light bulbs.
 
subject: how to save select tag's list attribute
 
Similar Threads
Problem with 2 collection
html:options in struts
Putting Tokens into an Array
Iterate over an arraylist of beans ?
where to validate username password in struts