org.melati.servlet
Class Form

Package class diagram package Form
java.lang.Object
  extended by org.melati.servlet.Form

public final class Form
extends Object

An object to hold useful static methods for manipulation of a Form in a ServletTemplateContext.


Method Summary
static void extractFields(ServletTemplateContext context, Persistent object)
          Retrieve updated persistent fields from a context modified in a template.
static Boolean getBooleanField(ServletTemplateContext context, String field)
          A utility method that tests whether a field is present in a Form, returning a Boolean.
static String getField(ServletTemplateContext context, String field, String defaultValue)
          A utility method that gets a value from the Form.
static String getFieldNulled(ServletTemplateContext context, String field)
          A utility method that gets a value from the Form.
static Integer getIntegerField(ServletTemplateContext context, String field)
          A utility method that gets a value from the Form as an Integer.
static Integer getIntegerField(ServletTemplateContext context, String field, Integer defaultValue)
          A utility method that gets a value from the Form as an Integer.
static String sameQueryWith(String qs, String field, String value)
          Modify or add a form parameter setting (query string component) in a query string.
static String sameURLWith(javax.servlet.http.HttpServletRequest request, String field, String value)
          Modify or add a form parameter setting (query string component) in the URL for a servlet request.
static String sameURLWith(String uri, String query, String field, String value)
          Modify or add a form parameter setting (query string component) in a URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

extractFields

public static void extractFields(ServletTemplateContext context,
                                 Persistent object)
Retrieve updated persistent fields from a context modified in a template.

The context can specify an adaptor for each field using another HTML field with name suffix "-adaptor" and value the classname of a TempletAdaptor. Hence the templet that renders the field can specify how the result is parsed. This is currently used for dates.

Parameters:
context - the current ServletTemplateContext to get values from
persistent - the Persistent to update

getFieldNulled

public static String getFieldNulled(ServletTemplateContext context,
                                    String field)
A utility method that gets a value from the Form. It will return null if the value is "" or not present.

Parameters:
context - - a template context
field - - the name of the field to get
Returns:
- the value of the field requested

getField

public static String getField(ServletTemplateContext context,
                              String field,
                              String defaultValue)
A utility method that gets a value from the Form. It will return the default if the value is "" or not present.

Parameters:
context - - a template context
field - - the name of the field to get
defaultValue - - the default value if the field is "" or not present
Returns:
- the value of the field requested

getIntegerField

public static Integer getIntegerField(ServletTemplateContext context,
                                      String field,
                                      Integer defaultValue)
A utility method that gets a value from the Form as an Integer. It will return null if the value is "" or not present.

Parameters:
context - - a template context
field - - the name of the field to get
defaultValue - - the default value if the field is "" or not present
Returns:
- the value of the field requested

getIntegerField

public static Integer getIntegerField(ServletTemplateContext context,
                                      String field)
A utility method that gets a value from the Form as an Integer. It will return null if the value is "" or not present.

Parameters:
context - - a template context
field - - the name of the field to get
Returns:
- the value of the field requested

getBooleanField

public static Boolean getBooleanField(ServletTemplateContext context,
                                      String field)
A utility method that tests whether a field is present in a Form, returning a Boolean.

Parameters:
context - - a template context
field - - the name of the field to get
Returns:
- TRUE or FALSE depending if the field is present

sameURLWith

public static String sameURLWith(String uri,
                                 String query,
                                 String field,
                                 String value)
Modify or add a form parameter setting (query string component) in a URL.

Parameters:
uri - A URI
query - A query string
field - The parameter's name
value - The new value for the parameter (unencoded)
Returns:
uri?query with field=value. If there is already a binding for field in the query string it is replaced, not duplicated.

sameURLWith

public static String sameURLWith(javax.servlet.http.HttpServletRequest request,
                                 String field,
                                 String value)
Modify or add a form parameter setting (query string component) in the URL for a servlet request.

Parameters:
request - A servlet request
field - The parameter's name
value - The new value for the parameter (unencoded)
Returns:
The request's URL with field=value. If there is already a binding for field in the query string it is replaced, not duplicated. If there is no query string, one is added.

sameQueryWith

public static String sameQueryWith(String qs,
                                   String field,
                                   String value)
Modify or add a form parameter setting (query string component) in a query string. Note this uses the default encoding.

Parameters:
qs - A query string
field - The parameter's name
value - The new value for the parameter (unencoded)
Returns:
qs with field=value. If there is already a binding for field in the query string it is replaced, not duplicated.


Copyright © 2000-2010 PanEris. All Rights Reserved.