• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

populating dropdowns/collections in DynaValidatorForm after Validation failure

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to sort out how to re-populate collections after validation has failed using the struts validator with a DynaValidatorForm.
If my form just has standard text inputs, struts maintains state on the forms fine during validation failures with the action mapping set to use request scope.
But if there are drop downs that are dynamically populated (say countries from a database) and validation fails, struts can not find the collection unless I put it into session scope. Boo yuk. Then I have to clean up manually or have stuff lying around in session scope.
I've done a bit of .NET programming and in the code behind pages there is a PageLoad() method that gets fired any time a page is loaded or posted back to it self. This is the method I reloaded collections for dynamic lists or drop downs.
Is there any way to mimic this functionality within the existing Struts framework or am I going to have to extend something and add in my own functionality?
Thanks!
Justin
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm... my hunch is that you'll have to put it in session. Cleaning up manually isn't that bad. Just put a dealy at the end of your validate method that does something like:
if(errors.isEmpty()){
request.getSession(false).removeAttribute("myCollection");
}
 
Justin Tilson
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With the DynaValidatorForm's there isn't a validate method in my Action and DispatchAction classes. The validation happens internally in the struts framework and the request gets forwarded back to the input page if validation fails (that is my current understanding anyway). The collections don't get initialized this way.
I am trying to avoid putting my collections in to session scope because some of the lists are 30,000+ item large and it just seems like a poor solution. Perhaps I am being too anal though.
Any other idea?
Cheers
 
Marc Peabody
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not 100% up on DynaForms but I think you can extend the class and write your own validate method. For some reason, most people using DynaForms refuse to write java classes.
The DynaValForm's validate method being generated is probably nothing but:
ActionErrors errors = super.validate(mapping, request); //Val Framework
return errors;
which calls the Validate Framework and returns the errors. The snippet I posted would be inserted just before the return errors;
I don't think there is a way to pass an object from one request to the next without first placing it into a wider scope or passing it into another object with wider scope.
Placing it in session for that short while won't hurt you any more than any other solution. The object needs exist in memory during the first request and all subsequent request from failed validations. Whether the object is placed repeatedly across each request, in session temporarily, or even application scope for that temporary period of time... they all have pretty much the same performance.
Now if you'll excuse me, I need to change pants after seeing the possible list size.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic