Added requireFloatParameter().
git-svn-id: https://samskivert.googlecode.com/svn/trunk@575 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: ParameterUtil.java,v 1.2 2002/02/13 19:35:50 shaper Exp $
|
// $Id: ParameterUtil.java,v 1.3 2002/02/16 01:14:56 shaper Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -51,6 +51,32 @@ public class ParameterUtil
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the supplied parameter from the request and converts it to
|
||||||
|
* a float. If the parameter does not exist or is not a well-formed
|
||||||
|
* float, a data validation exception is thrown with the supplied
|
||||||
|
* message.
|
||||||
|
*/
|
||||||
|
public static float requireFloatParameter (
|
||||||
|
HttpServletRequest req, String name, String invalidDataMessage)
|
||||||
|
throws DataValidationException
|
||||||
|
{
|
||||||
|
return parseFloatParameter(
|
||||||
|
getParameter(req, name, false), invalidDataMessage);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static float parseFloatParameter (
|
||||||
|
String value, String invalidDataMessage)
|
||||||
|
throws DataValidationException
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return Float.parseFloat(value);
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
throw new DataValidationException(invalidDataMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the supplied parameter from the request and converts it to
|
* Fetches the supplied parameter from the request and converts it to
|
||||||
* an integer. If the parameter does not exist or is not a well-formed
|
* an integer. If the parameter does not exist or is not a well-formed
|
||||||
|
|||||||
Reference in New Issue
Block a user