Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validation of Struts Forms

 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • 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
 
Swarn Dhaliwal
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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 ]
 
Karl Beowulph
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • 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?
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Sahil Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic