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?
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 ]
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.