org.enhydra.barracuda.core.forms
Class FormUtil

java.lang.Object
  |
  +--org.enhydra.barracuda.core.forms.FormUtil

public class FormUtil
extends java.lang.Object

Simple Form related utilities

Since:
1.0
Version:
%I%, %G%
Author:
Christian Cryder

Constructor Summary
FormUtil()
           
 
Method Summary
static java.lang.String assertMinMax(java.lang.String field, java.lang.String fieldDescr, int min, int max)
          This method allows you to assert that a String value falls within a given min/max length range.
static void assertTrue(java.lang.String errmsg, boolean expression)
          This function simply evaluates a given boolean expression and throws a ValidationException using the specified error message if its not valid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormUtil

public FormUtil()
Method Detail

assertMinMax

public static java.lang.String assertMinMax(java.lang.String field,
                                            java.lang.String fieldDescr,
                                            int min,
                                            int max)
                                     throws ValidationException

This method allows you to assert that a String value falls within a given min/max length range. If min or max is -1, that particular aspect will not be evaluated.

Example usage:
String user = assertMinMax((String) map.get(USER), "User Name", 5, 30);

This would retrieve a username from a map, validate it to ensure that its between 5 and 30 characters in length, and then return the adjusted value (if it was null in the map, it will come back as "", which is convenient for further custom evaluation)

Todo:

Parameters:
field - the field to be evaluated
fieldDescr - a description of the field to be included in any error messages
min - the minimum length of the String, or -1 if there is no min
max - the maximum length of the String, or -1 if there is no max
Returns:
the field value (non-null, adjusted and trimmed for further custom evaluation)
Throws:
a - ValidationException if the field is not valid
ValidationException

assertTrue

public static void assertTrue(java.lang.String errmsg,
                              boolean expression)
                       throws ValidationException
This function simply evaluates a given boolean expression and throws a ValidationException using the specified error message if its not valid

Parameters:
errmsg - the error message to be used if the expression is invalid
expression - the expression to be evaluated
Throws:
ValidationException - if the expression is not true


Copyright © 2001 Enhydra.org