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 2003/06/13 19:39:12 UTC
DO NOT REPLY [Bug 20754] New: -
Validating all Fields.
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=20754>.
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=20754
Validating all Fields.
Summary: Validating all Fields.
Product: Struts
Version: 1.1 RC1
Platform: All
OS/Version: All
Status: NEW
Severity: Enhancement
Priority: Other
Component: Custom Tags
AssignedTo: struts-dev@jakarta.apache.org
ReportedBy: mscaldas2001@yahoo.com
CC: mscaldas2001@yahoo.com
One enhancement I added is to be able to validate all Rules instead of stopping
at the first error found. This is very useful, depending on how you want to
present the error handling to the user - Alert pop-ups are not the most
efficient way. So, I created a Parameter on the ValidatorPlugIn.java, to
receive a boolean wheter it should stop validating at the first error
encountered (default behavior) or if it should validate all the way - no matter
what.
Files modified for this enhancement:
org.apache.struts.validator.ValidatorPlugIn
org.apache.struts.taglib.html.JavascriptValidatorTag
Diffs (From RC2):
ValidatorPlugIn.java:
===========================Init ValidatorPlugIn.java Diff =====================
112a113,116> /**
> * Application scope key that <code>StopOnError</code> is stored under.
> */
> public final static String STOP_ON_ERROR_KEY
= "org.apache.commons.validator.STOP_ON_ERROR";
142a147,168> /**
> * Informs the Validators if it has to stop validation when finding the
first Error
> * or if it should continue.
> * Default to true to keep backwards compatibility.
> */
> private boolean stopOnFirstError = true;
> /**
> * Gets the value for stopOnFirstError.
> * @return a boolean indicating whether validator should stop when
finds the first error
> * or continue validation.
> */
> public boolean isStopOnFirstError() {
> return stopOnFirstError;
> }
> /**
> * Sets the value for stopOnFirstError.
> * @param newValue a boolean indicating whether validator should stop
when finds the first error
> * or continue validation.
> */
> public void setStopOnFirstError(boolean newValue) {
> this.stopOnFirstError = newValue;
> }
164a191,193> servlet.getServletContext().setAttribute(
> STOP_ON_ERROR_KEY + config.getPrefix(),
> new Boolean(stopOnFirstError));
====================== End ValidatorPlugIn diff ===============================
JavascriptValidatorTag:
===================== Init JavascriptValidatorTag.java diff ===================
315a316,322> Object stopOnErrorObj = pageContext.getAttribute
(ValidatorPlugIn.STOP_ON_ERROR_KEY + config.getPrefix(),
> PageContext.APPLICATION_SCOPE);
> boolean stopOnError = true;
> if (stopOnErrorObj != null && (stopOnErrorObj instanceof Boolean)) {
> stopOnError = ((Boolean)stopOnErrorObj).booleanValue();
> }
>
390a398> if (stopOnError) {
391a400,402> } else {
> methods += " & " + va.getMethod() + "(form)";
> }
==================== End JavascripValidatorTag diff ===========================
Usage:
If you want the normal behavior provided by struts today - you don't have to
worry about any configuration - The default is to behave as of today - the
Javascript will stop when the first error is encountered.
If you want to validate all the way, you can set a new property on the
validator plug in tag on your struts-config.xml as follow:
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validation.xml,/WEB-INF/validator-
rules.xml"/>
<set-property property="stopOnFirstError" value="true"/>
</plug-in>
If there's any questions or concerns, please send an e-mail to
mscaldas2001@yahoo.com
Regards,
Marcelo Caldas
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org