You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2002/12/19 18:17:12 UTC
DO NOT REPLY [Bug 15540] New: -
You can't control validation from within a form
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15540>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15540
You can't control validation from within a form
Summary: You can't control validation from within a form
Product: Struts
Version: Nightly Build
Platform: Other
OS/Version: Other
Status: NEW
Severity: Normal
Priority: Other
Component: Controller
AssignedTo: struts-dev@jakarta.apache.org
ReportedBy: beskrowni@alumni.cmu.edu
It sure would be nice if ActionForm had a shouldValidate() method that would
control whether or not validate() was invoked.
I realize the I've gone for almost two years without realizing that i needed
this, so I figure I need to provide a use case in order to make my case more
compelling.
Say you have a standard wizard action. In general, the each step of your
wizard has three options: next, back, and cancel. All three are submit
buttons, and when you click anyone of them, your standard wizard action will
route to the appropriate ActionForward. The problem is, whenever I click on
the back or cancel buttons, I *never* want to do the validation logic. With a
shouldValidate method in my ActionForm, I could tell the RequestProcessor to
bypass validation for certain submissions. (I realize that there is already a
trap for cancelled operations, but what I'm proposing is more flexible.)
I also realize that the struts-config allows me to turn off validation for a
particular action mapping, but this is different. In my case, validation
should be invoked based on what was submitted in the form. I realize that I
could just always build this into my validate method, but a more elegant
solution would be add 3 lines to RequestProcessor.processValidate() and one
method to ActionForm. So little work, so much benefit (at least to me).
For what it's worth, here are the diffs with my proposed changes:
Index: RequestProcessor.java
===================================================================
RCS file: /home/cvspublic/jakarta-
struts/src/share/org/apache/struts/action/RequestProcessor.java,v
retrieving revision 1.22
diff -b -c -r1.22 RequestProcessor.java
*** RequestProcessor.java 12 Nov 2002 03:56:09 -0000 1.22
--- RequestProcessor.java 19 Dec 2002 17:08:42 -0000
***************
*** 905,910 ****
--- 905,914 ----
return (true);
}
+ if (!form.shouldValidate(mapping, request)) {
+ return (true);
+ }
+
// Call the form bean's validation method
if (log.isDebugEnabled()) {
log.debug(" Validating input form properties");
Index: ActionForm.java
===================================================================
RCS file: /home/cvspublic/jakarta-
struts/src/share/org/apache/struts/action/ActionForm.java,v
retrieving revision 1.13
diff -b -c -r1.13 ActionForm.java
*** ActionForm.java 20 Oct 2002 17:06:57 -0000 1.13
--- ActionForm.java 19 Dec 2002 17:11:38 -0000
***************
*** 268,272 ****
--- 268,279 ----
}
+ public boolean shouldValidate(ActionMapping mapping,
+ HttpServletRequest request) {
+
+ return (true);
+
+ }
+
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>