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

Check this faq...


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

Joined: Aug 03, 2008
Posts: 9313
    
  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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to save select tag's list attribute