• 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

Validation of Struts Forms

 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Form which holds all data of a database record, I will do some updates, like add some elements into it, and it will back to the same edit page for users to continue to change the data.

When I click submit, if the data is incorrect, the validator prompts me the errors, BUT, all newly changed data are gone!

Let say, if I provide a description "x@xxxxx", and in validate.xml, I set the rule that the description cannot contain "@" character, this will then be an ActionError.

But, the description "x@xxxxx" disappear after the checking!

So, what should I do? How can I preserve the data in the forms, even it is incorrect?

Nick
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nicholas Cheung:
I have a Form which holds all data of a database record, I will do some updates, like add some elements into it, and it will back to the same edit page for users to continue to change the data.

When I click submit, if the data is incorrect, the validator prompts me the errors, BUT, all newly changed data are gone!

Let say, if I provide a description "x@xxxxx", and in validate.xml, I set the rule that the description cannot contain "@" character, this will then be an ActionError.

But, the description "x@xxxxx" disappear after the checking!

So, what should I do? How can I preserve the data in the forms, even it is incorrect?

Nick



You can take two approaches :
1. Define your Bean with Session scope and don't reset the values. It usually works but not the best approach.

2. Define and action mapping to display (e.g. /displayPage)the page that contains the validated fields. Make validate = "false" for this action mapping and specify it as input attribute for the action mappings for which validate = "true". This way, whenever an error is detected by the validator framework it will forward to the "/displayPage.do" action which can then populate the required parameters and make any other adjustments if need be.

Hope this helps.
[ June 04, 2004: Message edited by: Swarn Dhaliwal ]
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had that problem myself.

I essentially did a simple work around and coded all the needed validation myself into the jsp page with javascript.

I'm not sure what causes the error though, any code anywhere that removes the formBean?
 
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've seen this problem posted a few times on javaranch but I've never been able to recreate it.

If you're using struts tags (not just plain html) for your inputs and you're not clearing everything out in your ActionForm's reset method, everything SHOULD work fine. You should also be able to keep the ActionForm in request scope.
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
I have posted for the similar issue("Dynavalidator"),but while using Dynavalidator and am still looking for the answer.





Thanks,
Sahil.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic