• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to save select tag's list attribute

 
Andrei Antonescu
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this faq...
 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to javaranch Andrei
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The solution was excellent.
Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic