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
This commit is contained in:
mdb
2001-03-04 08:18:28 +00:00
parent 21305787af
commit ea9f65f24f
@@ -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; package com.samskivert.webmacro;
@@ -61,8 +61,32 @@ public class FormUtil
public static Date requireDateParameter (WebContext context, String name, public static Date requireDateParameter (WebContext context, String name,
String invalidDataMessage) String invalidDataMessage)
throws DataValidationException 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); 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; Date date = null;
try { try {