File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Validation of Struts Forms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation of Struts Forms" Watch "Validation of Struts Forms" New topic
Author

Validation of Struts Forms

Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Swarn Dhaliwal
Greenhorn

Joined: Jan 14, 2004
Posts: 4
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

Joined: May 31, 2004
Posts: 130
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

Joined: Feb 05, 2003
Posts: 4727

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.


A good workman is known by his tools.
Sahil Singh
Ranch Hand

Joined: Sep 03, 2003
Posts: 41
Hi Guys,
I have posted for the similar issue("Dynavalidator"),but while using Dynavalidator and am still looking for the answer.





Thanks,
Sahil.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validation of Struts Forms
 
Similar Threads
Etch-a-Sketch Analytic Geometry
Can�t get SSL redirection to work for root application context.
Adding 1 row to specific section of a struts table using iterate tag
questions regarding regular expressions
How to implement the wall follower algorithm in java?