• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Struts validation design question

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have an action called CreateNewUserPrepareAction. The jsp has a User form to capture the data. In adition to this, the JSP has a list box whose items are retrieved from the database. The values for the list box are stored as a List in the request as an attribute and are then displayed as part of the form.

When the user submits the form the request gets sent to CreateNewUserAction. I validate the contents using the Validate method. If the user has entered some invalid entry I return to the page displaying an error message. However, the items for the list box are no longer in the request(which is correct). I do not want to store them in the session as I dont think they belong there.

Has anyone come across this problem before and can the recommend some pattern that provides a nice solution. I dont think it is correct either if the Validate method sends a call to the database either.

Thank you
David
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a very common issue. Here are some possible solutions:

1. Put the list in session (worst idea)

2. Put the list in application scope (not a horrible idea if the list is static)

3. Repopulate the list in the form's reset() method. (Violates MVC and is not a place where another developer would look to see where a list is populated)

4. On error, forward to the initial read action with an error flag, making sure to only populate the list in the read action if the error flag is set. (It is not a best practice to forward to an action)

5. Extend Action and have a populateList(ActionForm form) method and abstract ActionForward doAction(). Make sure all of your actions extend this new class and all of the logic is in the doAction method. In the execute() method of this class, call populateList(form) before calling the doAction() method. Overwrite populateList in the actions that have a list. That is the best solution that I can come up with.


Let me know if you have any other questions.
[ June 29, 2006: Message edited by: Dom Lassy ]
 
david allen
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply.
Regarding your last solution. When there is an error where do I forward the request to?
 
Dom Lassy
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It depends on how you set it up, but you can have it forward to the initial read action.
 
Good night. Drive safely. Here's a tiny ad for the road:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic