org.barracudamvc.core.forms
Class FormUtil

java.lang.Object
  extended byorg.barracudamvc.core.forms.FormUtil

public class FormUtil
extends Object

Simple Form related utilities

Author:
Christian Cryder [christianc@granitepeaks.com]

Field Summary
protected static org.apache.log4j.Logger logger
           
 
Constructor Summary
FormUtil()
           
 
Method Summary
static String assertMinMax(String field, 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(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
static void flagErrors(BComponent bcomp)
          Convenience method to have the ErrorManager flag a component for errors (if they exist).
static String formatForOutput(Object val, FormElement el)
          Convenience method to format form values in a friendly manner (based on their data type) that will allow for later reparsing
static void repopulate(FormMap fm, BComponent bcomp)
          Given a BComponent and a reference to a FormMap, this method will automatically repopulate the form value into the component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.log4j.Logger logger
Constructor Detail

FormUtil

public FormUtil()
Method Detail

repopulate

public static void repopulate(FormMap fm,
                              BComponent bcomp)
Given a BComponent and a reference to a FormMap, this method will automatically repopulate the form value into the component. The way it works is fairly simply: you create the appropriate component and name it - the component name will be used to locate the appropriate form element and repopulate the component based on the form element value.

Parameters:
fm - the backing form map
bcomp - the component to be repopulated
Since:
csc_110304_1

formatForOutput

public static String formatForOutput(Object val,
                                     FormElement el)
Convenience method to format form values in a friendly manner (based on their data type) that will allow for later reparsing


flagErrors

public static void flagErrors(BComponent bcomp)
Convenience method to have the ErrorManager flag a component for errors (if they exist).

Parameters:
bcomp - the component to be flagged
Since:
csc_110304_1
See Also:
ErrorManager.apply(BComponent)

assertMinMax

public static String assertMinMax(String field,
                                  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(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 © 2004 BarracudaMVC.org All Rights Reserved.