From ea9f65f24fa5fdcfffe132da32a0262a1a5ec3c3 Mon Sep 17 00:00:00 2001 From: mdb Date: Sun, 4 Mar 2001 08:18:28 +0000 Subject: [PATCH] Added getDateParameter() which doesn't freak out if the date isn't set in the form fields but does freak out if it's a bogus date. git-svn-id: https://samskivert.googlecode.com/svn/trunk@93 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../com/samskivert/webmacro/FormUtil.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/projects/samskivert/src/java/com/samskivert/webmacro/FormUtil.java b/projects/samskivert/src/java/com/samskivert/webmacro/FormUtil.java index 21e27068..421eec6c 100644 --- a/projects/samskivert/src/java/com/samskivert/webmacro/FormUtil.java +++ b/projects/samskivert/src/java/com/samskivert/webmacro/FormUtil.java @@ -1,5 +1,5 @@ // -// $Id: FormUtil.java,v 1.3 2001/03/02 01:22:07 mdb Exp $ +// $Id: FormUtil.java,v 1.4 2001/03/04 08:18:28 mdb Exp $ package com.samskivert.webmacro; @@ -61,8 +61,32 @@ public class FormUtil public static Date requireDateParameter (WebContext context, String name, String invalidDataMessage) throws DataValidationException + { + return parseDateParameter(context.getForm(name), invalidDataMessage); + } + + /** + * Fetches the supplied parameter from the request and converts it to + * a date. The value of the parameter should be a date formatted like + * so: 2001-12-25. If the parameter does not exist, null is + * returned. If the parameter is not a well-formed date, a data + * validation exception is thrown with the supplied message. + */ + public static Date getDateParameter (WebContext context, String name, + String invalidDataMessage) + throws DataValidationException { String value = context.getForm(name); + if (StringUtil.blank(value)) { + return null; + } + return parseDateParameter(value, invalidDataMessage); + } + + protected static + Date parseDateParameter (String value, String invalidDataMessage) + throws DataValidationException + { Date date = null; try {