husted 2002/11/13 11:16:41 Modified: contrib/scaffold/src/java/org/apache/struts/scaffold BaseForm.java Log: + BaseForm: Add convenience methods for testing for required fields and if a field representing a value is zero or blank. Revision Changes Path 1.10 +54 -2 jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/BaseForm.java Index: BaseForm.java =================================================================== RCS file: /home/cvs/jakarta-struts/contrib/scaffold/src/java/org/apache/struts/scaffold/BaseForm.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- BaseForm.java 11 Nov 2002 21:25:53 -0000 1.9 +++ BaseForm.java 13 Nov 2002 19:16:41 -0000 1.10 @@ -20,6 +20,8 @@ import com.wintecinc.struts.action.ValidatorForm; // Struts 1.0.x import org.apache.commons.scaffold.lang.ChainedException; +import org.apache.commons.scaffold.text.ConvertUtils; +import org.apache.commons.scaffold.lang.Tokens; /** @@ -150,6 +152,38 @@ // --------------------------------------------------------- Public Methods /** + * Convenience method to test for a required field + * and setup the error message. + */ + protected void required( + ActionErrors errors, + String field, + String name, + String arg) { + if ((null==field) || (0==field.length())) { + errors.add(name, + new ActionError(Tokens.ERRORS_REQUIRED,arg)); + } + } + + + /** + * Convenience method to test for a required array + * and setup the error message. + */ + protected void required( + ActionErrors errors, + String[] field, + String name, + String arg) { + if ((null==field) || (0==field.length)) { + errors.add(name, + new ActionError(Tokens.ERRORS_REQUIRED,arg)); + } + } + + + /** * If bean is set to mutable, calls <code>resetSessionLocale</code> * and <code>setRemoteAddr</code>. * @@ -254,8 +288,26 @@ * * @param s The sting to check */ + protected boolean blank(String s) { + return ConvertUtils.blank(s); + } + + + /** + * Convenience method to check for a null, empty, or "0" String. + * + * @param s The sting to check + */ + protected boolean blankValue(String s) { + return ConvertUtils.blankValue(s); + } + + + /** + * @deprecated Use blank instead. + */ protected boolean isBlank(String s) { - return ((s==null) || (EMPTY.equals(s))); + return blank(s); }
-- To unsubscribe, e-mail: <mailto:struts-dev-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:struts-dev-help@;jakarta.apache.org>