Expresso 5-6

com.jcorporate.expresso.services.controller.ui
Class DefaultAutoElement

java.lang.Object
  extended bycom.jcorporate.expresso.services.controller.ui.DefaultAutoElement
All Implemented Interfaces:
AutoControllerElement
Direct Known Subclasses:
CacheAutoElement

public class DefaultAutoElement
extends Object
implements AutoControllerElement

Default implementation of the AutoController Element. Provides a default unified method for rendering/parsing Inputs from DBObjects

Since:
Expresso 5.0
Author:
Michael Rimov, portions from Adam Rossi, Michael Nash, Shash Chatterjee

Field Summary
static String BLOCK_TITLE
           
static String CLASS_HANDLER_NAME
           
static String DBOBJECT_LABEL
           
static String DEFAULT_CLASS_HANDLER
           
static String DEFAULT_STYLE
           
static String ERROR_STYLE
           
protected static org.apache.log4j.Logger log
           
static String REQUIRED_STYLE
           
static String SESSION_KEY
           
protected static AutoControllerElement theDefault
          singleton instance
 
Constructor Summary
protected DefaultAutoElement()
          The constructor here is protected.
 
Method Summary
 Block createDBObjectBlock(ControllerRequest request, ControllerResponse response, DataObject dbobj)
          Creates a DBObject Block that contains all the non-secret fields for the DBObject.
 Block createDBObjectBlock(ControllerRequest request, ControllerResponse response, String title, DataObject dbobj)
          Creates a DBObject Block that contains all the non-secret fields for the DBObject.
protected  String displayValue(DataFieldMetaData metaData, Date dt, Locale l)
          Same as display value but for Date/DateTime types.
protected  String displayValue(DataFieldMetaData metaData, String fieldValue, String fieldName, Locale l)
          Format a value for display in the HTML being returned to the client
static AutoControllerElement getAutoControllerElement()
          Constructor.
 String getErrorStyle()
          Returns the style to be used if the Input field has an error with it.
 String getNormalStyle()
          Returns the style to be used if the input has normal non-required characteristics
 String getRequiredDecorator()
          Returns the string to append to a field label if it is required.
 String getRequiredStyle()
          Returns the style to be used if the Input is required
 DataObject parseBlock(ControllerRequest request, DataObject oneObject, ErrorCollection ec)
          Convienence method if you only expect one DBObject to be returned from a particular form.
 DataObject[] parseBlocks(ControllerRequest request, DataObject[] theObjects, ErrorCollection ec)
          Parses the appropriate DBObject from the block.
 DataObject parseDBObject(ControllerRequest request, DataObject oneObject, ErrorCollection ec)
          Convienence method if you only expect one DBObject to be returned from a particular form, and unlike the ParseBlock, there is no DBOBject name prefix attached to the parameter names.
 DataObject parseDBObject(ControllerRequest request, DataObject oneObject, ErrorCollection ec, boolean validate)
          Parses a dbobject
 String parseSingleInput(ControllerRequest request, DataObject dbobj, String fieldName, String parameterName, ErrorCollection ec)
          Takes the Controller Request and appropriately parses a string for a particular field.
 Input renderDBObjectField(ControllerResponse response, DataObject dbobj, String fieldName, String cachedValue, boolean readOnly)
          Renders a DBOBject Field as either an Input or an Output.
protected  Input renderReadOnlyInput(ControllerResponse response, Input oneField, DataObject dbobj, String fieldName, String oneFieldValue)
          Modifies an already instantiated Input to be a finished read only control.
protected  void renderReadWriteBlob(ControllerResponse response, Input oneField, DataObject dbobj, String fieldName, String oneFieldValue, String oneFieldSize)
          Modifies an already instantiated Input to be a finished Input control specifically for a blob field.
protected  Input renderReadWriteInput(ControllerResponse response, Input oneField, DataObject dbobj, String fieldName, String oneFieldValue, String oneFieldSize)
          Modifies an already instantiated Input to be a finished Input control
protected  void retrieveCachedValueInForm(ControllerResponse response, String oneFieldName, Input i)
          Used to set values in created db objects to the values found (if any) in the form cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theDefault

protected static AutoControllerElement theDefault
singleton instance


CLASS_HANDLER_NAME

public static final String CLASS_HANDLER_NAME
See Also:
Constant Field Values

DEFAULT_CLASS_HANDLER

public static final String DEFAULT_CLASS_HANDLER

DEFAULT_STYLE

public static final String DEFAULT_STYLE
See Also:
Constant Field Values

REQUIRED_STYLE

public static final String REQUIRED_STYLE
See Also:
Constant Field Values

ERROR_STYLE

public static final String ERROR_STYLE
See Also:
Constant Field Values

log

protected static org.apache.log4j.Logger log

SESSION_KEY

public static final String SESSION_KEY
See Also:
Constant Field Values

DBOBJECT_LABEL

public static final String DBOBJECT_LABEL
See Also:
Constant Field Values

BLOCK_TITLE

public static final String BLOCK_TITLE
See Also:
Constant Field Values
Constructor Detail

DefaultAutoElement

protected DefaultAutoElement()
The constructor here is protected. Use getAutoControllerElement() instead to get the instance of this class.

Method Detail

getAutoControllerElement

public static AutoControllerElement getAutoControllerElement()
                                                      throws ControllerException
Constructor. Allows for a classHandler to be used from the expresso-config.xml if you really need something completely different.

Returns:
an instantiated AutoControllerElement
Throws:
ControllerException - upon error

getErrorStyle

public String getErrorStyle()
Returns the style to be used if the Input field has an error with it.

Specified by:
getErrorStyle in interface AutoControllerElement
Returns:
java.lang.String a Stylesheet class to render to

getNormalStyle

public String getNormalStyle()
Returns the style to be used if the input has normal non-required characteristics

Specified by:
getNormalStyle in interface AutoControllerElement
Returns:
java.lang.String a Stylesheet class to render to

getRequiredDecorator

public String getRequiredDecorator()
Returns the string to append to a field label if it is required. Default is an ""

Returns:
java.lang.String a Stylesheet class to render to

getRequiredStyle

public String getRequiredStyle()
Returns the style to be used if the Input is required

Specified by:
getRequiredStyle in interface AutoControllerElement
Returns:
java.lang.String a Stylesheet class to render to

createDBObjectBlock

public Block createDBObjectBlock(ControllerRequest request,
                                 ControllerResponse response,
                                 DataObject dbobj)
                          throws ControllerException
Creates a DBObject Block that contains all the non-secret fields for the DBObject. The Block will have a nested Output that matches DBObject's description unless one is not supplied in which case the nested Output will have the title "Untitled"

Specified by:
createDBObjectBlock in interface AutoControllerElement
Parameters:
response - The ControllerResponse object
request - The ControllerRequest Object
dbobj - The dbObject to automatically render.
Returns:
a rendered block
Throws:
ControllerException - if there's an error rendering the DBObject

createDBObjectBlock

public Block createDBObjectBlock(ControllerRequest request,
                                 ControllerResponse response,
                                 String title,
                                 DataObject dbobj)
                          throws ControllerException
Creates a DBObject Block that contains all the non-secret fields for the DBObject.

Specified by:
createDBObjectBlock in interface AutoControllerElement
Parameters:
response - The ControllerResponse object
request - The ControllerRequest Object
title - The title to give this block. The system renders a nested Output called "block-title" for the block that contains this data.
dbobj - The dbObject to automatically render.
Returns:
a rendered Block object
Throws:
ControllerException - if there's an error rendering the DBObject

retrieveCachedValueInForm

protected void retrieveCachedValueInForm(ControllerResponse response,
                                         String oneFieldName,
                                         Input i)
                                  throws ControllerException
Used to set values in created db objects to the values found (if any) in the form cache. (the form cache is what people type into an HTML form, and if there is an error, we cache those values in order to send back the form (with error message) and have their typing preserved for the next try.)

Parameters:
response - ?
oneFieldName - ?
i - The Input to retrieve.
Throws:
ControllerException
See Also:
CacheAutoElement

parseBlock

public DataObject parseBlock(ControllerRequest request,
                             DataObject oneObject,
                             ErrorCollection ec)
                      throws ControllerException
Convienence method if you only expect one DBObject to be returned from a particular form.

Specified by:
parseBlock in interface AutoControllerElement
Parameters:
request - The ControllerRequest object handed down by the framework
oneObject - a single dbobject ro dumpt the parsed values into.
ec - An instantiated ErrorCollection that is filled in with any error
Returns:
a filled out DBObject
Throws:
ControllerException - if there's an error parsing the block or communicating with the underlying DBObject

parseBlocks

public DataObject[] parseBlocks(ControllerRequest request,
                                DataObject[] theObjects,
                                ErrorCollection ec)
                         throws ControllerException
Parses the appropriate DBObject from the block. Returns the fully constructed DBOBject including any errors in the DBObject

Specified by:
parseBlocks in interface AutoControllerElement
Parameters:
request - The ControllerRequest object handed down by the framework
theObjects - A pre-instantiated group of DBObjects in which you expect to have the fields overwritten/filled. By using instantiated DBObjects, you can pre-fill any potentially blank fields and thus remove any Errors.
ec - An instantiated ErrorCollection that is filled in with any error
Returns:
An array of parsed DBObjects
Throws:
ControllerException - if there's an error parsing the block or communicating with the underlying DBObject
IllegalArgumentException - if request, theObjects, or ec is null

parseDBObject

public DataObject parseDBObject(ControllerRequest request,
                                DataObject oneObject,
                                ErrorCollection ec,
                                boolean validate)
                         throws ControllerException
Parses a dbobject

Specified by:
parseDBObject in interface AutoControllerElement
Parameters:
request - The ControllerRequest that contains all the parameters for parsing.
oneObject - The DBObject to populate.
ec - An error Collection to send in for any parsing errors to be saved to.
validate - Set to true if you want the DBObject validated. Sometimes, like for the DBMaint search form, this is not a desired feature.
Returns:
The parsed DBObject [Although oneObject gets populated since no assignment takes place.] So you can ignore this return value if you desire.
Throws:
IllegalArgumentException - upon data exception.
ControllerException - upon controller-related error.

parseDBObject

public DataObject parseDBObject(ControllerRequest request,
                                DataObject oneObject,
                                ErrorCollection ec)
                         throws ControllerException
Convienence method if you only expect one DBObject to be returned from a particular form, and unlike the ParseBlock, there is no DBOBject name prefix attached to the parameter names. This is similar to the ControllerRequest validateDBObject functionality, but we're consolodating things here.

Specified by:
parseDBObject in interface AutoControllerElement
Parameters:
request - The ControllerRequest object handed down by the framework
oneObject - A DBObject to fill in.
ec - An instantiated ErrorCollection that is filled in with any error
Returns:
a parsed DBObject
Throws:
ControllerException - if there's an error parsing the block or communicating with the underlying DBObject

parseSingleInput

public String parseSingleInput(ControllerRequest request,
                               DataObject dbobj,
                               String fieldName,
                               String parameterName,
                               ErrorCollection ec)
                        throws ControllerException
Takes the Controller Request and appropriately parses a string for a particular field. If the field is a Date, then it parses it as such, if it is money, then it perses it as such. Etc.

As of Expresso 5.1, the system properly parses multi-part request data. If a parameter is a file parameter, then it sets the following field attributes that can be retrieved by:
DataObject.getFieldData(fieldName).getAttribute(attribName);

  • Attribute: fileName - The locally accessible file name to be used for most likely saving to the database. Use new File(fileName) to actually access the uploaded file
  • Attribute: origFileName - The original file name (without path) that was uploaded to the server through the web browser. This will be different from the attribute fileName since Expresso will rename the local file name to prevent naming collisions
  • Attribute: MimeType - The system will make a guess as to the mime type of the file that was uploaded based upon the file name.

Finally, if the target dbobj is of type MediaDBObject the fields: 'fieldName + "_mimeType"' and 'fieldName + "_fileName"' will be set with the corresponding mimeType and origFileName values

Specified by:
parseSingleInput in interface AutoControllerElement
Parameters:
request - The ControllerRequest object
dbobj - The DBObject for which we're going to put the field to
fieldName - The name of the field to parse
parameterName - The name of the http paramter to parse May be null in which case, the funciton will by default use the fieldName as the parameter name.
ec - An instantiated ErrorCollection object that will be filled with any parsing errors that may be encountered.
Returns:
java.lang.String for the value.
Throws:
ControllerException - upon parsing error
Since:
Expresso 5.0; Multipart Request Handling since Expresso 5.1


renderDBObjectField

public Input renderDBObjectField(ControllerResponse response,
                                 DataObject dbobj,
                                 String fieldName,
                                 String cachedValue,
                                 boolean readOnly)
                          throws ControllerException
Renders a DBOBject Field as either an Input or an Output. For example, if we're talking updating, then all key fields are outputs and not inputs. This function auto-detects whether we are dealing with a add() or update() situation by checking the DBObject's status. If it's NEW, then we treat this as an add form, if it is

Specified by:
renderDBObjectField in interface AutoControllerElement
Parameters:
response - The ControllerResponse object
dbobj - The parameter to render
fieldName - The name of the field to render
cachedValue - Any cached form value to put in the field.
readOnly - - If set to true, then this is automatically a read-only field... if set to false, this function might still render the field as read-only if, for example, it's a key field.
Returns:
a created Input
Throws:
ControllerException - if there's an error creating the Input Field

displayValue

protected String displayValue(DataFieldMetaData metaData,
                              Date dt,
                              Locale l)
Same as display value but for Date/DateTime types. Formats things appropriate to the user's locale

Parameters:
metaData - the Data Field's metadata
dt - The date value to format
l - the User's Locale gathered from the ControllerResponse object
Returns:
a properly formatted date

displayValue

protected String displayValue(DataFieldMetaData metaData,
                              String fieldValue,
                              String fieldName,
                              Locale l)
                       throws ControllerException
Format a value for display in the HTML being returned to the client

Parameters:
metaData - The Field Metadata
fieldValue - The value of the field
fieldName - the name of the field to render
l - The Locale to display the value for.
Returns:
String The formatted field
Throws:
ControllerException - If the field format information could not be determined

renderReadOnlyInput

protected Input renderReadOnlyInput(ControllerResponse response,
                                    Input oneField,
                                    DataObject dbobj,
                                    String fieldName,
                                    String oneFieldValue)
                             throws DBException,
                                    ControllerException
Modifies an already instantiated Input to be a finished read only control.

Parameters:
response - The ControllerResponse object
oneField - The input to flesh out.
dbobj - The data source object
fieldName - The field name in the dbobj to render.
oneFieldValue - The value to add to the input control.
Returns:
a read only input
Throws:
DBException - if there's an error communicating with the DBObject
ControllerException - if there's an error building the Input field.

renderReadWriteBlob

protected void renderReadWriteBlob(ControllerResponse response,
                                   Input oneField,
                                   DataObject dbobj,
                                   String fieldName,
                                   String oneFieldValue,
                                   String oneFieldSize)
                            throws DBException,
                                   ControllerException
Modifies an already instantiated Input to be a finished Input control specifically for a blob field. If the dbobject is a MediaObject, then it adds the abilities to view the fields and creates an appropriate icon.

Parameters:
response - The ControllerResponse object
oneField - The input to flesh out.
dbobj - The data source object
fieldName - The field name in the dbobj to render.
oneFieldValue - The value to add to the input control.
oneFieldSize - The size of the Input control when finished.
Throws:
DBException - if there's an error communicating with the DBObject
ControllerException - if there's an error building the Input field.

renderReadWriteInput

protected Input renderReadWriteInput(ControllerResponse response,
                                     Input oneField,
                                     DataObject dbobj,
                                     String fieldName,
                                     String oneFieldValue,
                                     String oneFieldSize)
                              throws DBException,
                                     ControllerException
Modifies an already instantiated Input to be a finished Input control

Parameters:
response - The ControllerResponse object
oneField - The input to flesh out.
dbobj - The data source object
fieldName - The field name in the dbobj to render.
oneFieldValue - The value to add to the input control.
oneFieldSize - The size of the Input control when finished.
Returns:
a rendered Read/Write Input
Throws:
DBException - if there's an error communicating with the DBObject
ControllerException - if there's an error building the Input field.

Expresso 5-6

Please see www.jcorporate.com for information about new Expresso releases.