org.melati.servlet
Class Form

java.lang.Object
  extended by org.melati.servlet.Form

public final class Form
extends java.lang.Object

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


Method Summary
static java.lang.Object extractField(ServletTemplateContext context, java.lang.String fieldName)
          Fill in value of a Field from a ServletTemplateContext.
static void extractFields(ServletTemplateContext context, Persistent object)
          Retrieve updated persistent fields from a context modified in a template.
static java.lang.Boolean getBooleanField(ServletTemplateContext context, java.lang.String field)
          A utility method that tests whether a field is present in a Form, returning a Boolean.
static java.lang.String getField(ServletTemplateContext context, java.lang.String field, java.lang.String defaultValue)
          A utility method that gets a value from the Form.
static java.lang.String getFieldNulled(ServletTemplateContext context, java.lang.String field)
          A utility method that gets a value from the Form.
static java.lang.String getForm(ServletTemplateContext context, java.lang.String field, java.lang.String def)
          A utility method that gets a value from the Form.
static java.lang.String getFormNulled(ServletTemplateContext context, java.lang.String field)
          A utility method that gets a value from the Form.
static java.lang.Integer getIntegerField(ServletTemplateContext context, java.lang.String field)
          A utility method that gets a value from the Form as an Integer.
static java.lang.Integer getIntegerField(ServletTemplateContext context, java.lang.String field, java.lang.Integer defaultValue)
          A utility method that gets a value from the Form as an Integer.
static java.lang.String sameQueryWith(java.lang.String qs, java.lang.String field, java.lang.String value)
          Modify or add a form parameter setting (query string component) in a query string.
static java.lang.String sameURLWith(javax.servlet.http.HttpServletRequest request, java.lang.String field, java.lang.String value)
          Modify or add a form parameter setting (query string component) in the URL for a servlet request.
static java.lang.String sameURLWith(java.lang.String uri, java.lang.String query, java.lang.String field, java.lang.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
object - the Persistent to update

extractField

public static java.lang.Object extractField(ServletTemplateContext context,
                                            java.lang.String fieldName)
                                     throws TempletAdaptorConstructionMelatiException
Fill in value of a Field from a ServletTemplateContext.

Parameters:
context - the current ServletTemplateContext to get values from
fieldName - the name of the field to extract
Returns:
the value of the field
Throws:
TempletAdaptorConstructionMelatiException - if there is a problem, for example with the class name

getFieldNulled

public static java.lang.String getFieldNulled(ServletTemplateContext context,
                                              java.lang.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 java.lang.String getField(ServletTemplateContext context,
                                        java.lang.String field,
                                        java.lang.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 java.lang.Integer getIntegerField(ServletTemplateContext context,
                                                java.lang.String field,
                                                java.lang.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 java.lang.Integer getIntegerField(ServletTemplateContext context,
                                                java.lang.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 java.lang.Boolean getBooleanField(ServletTemplateContext context,
                                                java.lang.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 java.lang.String sameURLWith(java.lang.String uri,
                                           java.lang.String query,
                                           java.lang.String field,
                                           java.lang.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 java.lang.String sameURLWith(javax.servlet.http.HttpServletRequest request,
                                           java.lang.String field,
                                           java.lang.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 java.lang.String sameQueryWith(java.lang.String qs,
                                             java.lang.String field,
                                             java.lang.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.

getFormNulled

public static java.lang.String getFormNulled(ServletTemplateContext context,
                                             java.lang.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

getForm

public static java.lang.String getForm(ServletTemplateContext context,
                                       java.lang.String field,
                                       java.lang.String def)
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
def - - the default value if the field is "" or not present
Returns:
- the value of the field requested


Copyright © 2000-2008 PanEris. All Rights Reserved.