com.wewebu.ow.server.fieldctrlimpl
Class OwNumberFieldControl

java.lang.Object
  extended by com.wewebu.ow.server.ui.OwEventTarget
      extended by com.wewebu.ow.server.app.OwFieldManagerControl
          extended by com.wewebu.ow.server.fieldctrlimpl.OwNumberFieldControl

public class OwNumberFieldControl
extends OwFieldManagerControl

Field control implementation for Number based fields.
The field rendering and updating relies on Java's NumberFormat. Additional configuration can be specified through a NumberFormat XML configuration element to designate a DecimalFormat format pattern string.
The field control tries to enforce a parsed Number concrete type for the following Java based types : Integer, Long, Double , Float , BigInteger and BigDecimal.

Alfresco Workdesk
Copyright (c) Alfresco Software, Inc.
All rights reserved.

For licensing information read the license.txt file or
go to: http://wiki.alfresco.com

Since:
2.5.2.0

Field Summary
static String ARRAY_ITEM_INDEX_KEY
          query string for the selected array item
static int DEFAULT_SIZE
          default field size
static String FIELD_ID_KEY
          query string for the selected field
 
Constructor Summary
OwNumberFieldControl()
           
 
Method Summary
protected  void addContainmentError(String id_p, int errCount_p)
           
protected  int calculateFieldSize(OwFieldDefinition fieldDef_p)
          (Overridable) Returns the calculated field size (maximum amount of characters entering into field) for the given field definition.
protected  void clearFieldError(String id_p)
          Clears the errors associated with the given field ID.
protected  void clearMarkedArrayItemErrors()
          Removes errors that were marked for deletion and adjusts the already existing indexes.
protected  String createParseIndexedError(String numberString_p, int index_p)
           
protected  int fieldContainmentCount(String id_p)
           
protected  String fieldContainmentId(String id_p)
           
protected  String getExternalComplexFieldIdDelimiter()
          The string ID delimiter used to separate the ID of an externally generated ID of a complex field.
The children of complex fields must be properly detected handled by this field control.
protected  String getFieldError(String id_p)
           
protected  String getValueIndexTitle(String strID_p)
           
 void init(OwFieldManager fieldmanager_p, Node configNode_p)
          Initializes this field control with the configured number format.
If no number format is configured the default locale NumberFormat is used.
protected  void insertAddArrayItemLink(Writer w_p, OwFieldDefinition fieldDef_p, String strID_p)
          Adds element addition link for array fields.
 void insertEditField(Writer w_p, OwFieldDefinition fieldDef_p, OwField field_p, String strID_p)
          format and displays the value attached to the fieldClass in HTML for use in a HTML Form.
 void insertReadOnlyField(Writer w_p, OwFieldDefinition fieldDef_p, Object value_p)
          format and displays the value attached to the PropertyClass in HTML
protected  void insertRemoveArrayItemLink(Writer w_p, OwFieldDefinition fieldDef_p, int index_p, String strID_p)
          Adds element removal link for array fields.
protected  void insertSingleEditField(Writer w_p, OwFieldDefinition fieldDef_p, Object value_p, String id_p, String errorFieldId_p)
          Inserts a single value, editable HTML control.
 void insertSingleReadOnlyField(Writer w_p, OwFieldDefinition fieldDef_p, String id_p, Object value_p)
          Inserts a single-value non-editable HTML control.
protected  boolean isComplexChildId(String strID_p)
           
protected  boolean isErrorContainment(String id_p)
           
protected  boolean isErrorField(String id_p)
           
protected  boolean isMarkedForClear(String id_p)
           
protected  void markArrayItemErrorForClear(String id_p, String fieldId_p, int index_p, int arraySize_p)
          Marks the array item with the give ID for deletion.
 void onAddArrayItem(javax.servlet.http.HttpServletRequest request_p)
          called when user clicks to add an array item
 void onDeleteArrayItem(javax.servlet.http.HttpServletRequest request_p)
          called when user clicks to delete an array item
protected  void setFieldManagerError(String strID_p, String error_p)
          Sets the given error in the current field manager.
This method handles the complex child fields by setting the error for the parent field.
protected  void setInternalFieldError(String id_p, String error_p)
          Register an error for a given field ID.
 Object updateField(javax.servlet.http.HttpServletRequest request_p, OwFieldDefinition fieldDef_p, Object value_p, String strID_p)
          update the property value upon request and validates the new value.
 Object updateSingleField(javax.servlet.http.HttpServletRequest request_p, OwFieldDefinition fieldDef_p, Object value_p, String strID_p, boolean updateErrors_p)
          Updates a single value field.
protected  Number validateNumber(String id_p, Number value_p, OwFieldDefinition fieldDef_p, boolean updateErrors_p)
          Validates a Number value against a given OwFieldDefinition.
 
Methods inherited from class com.wewebu.ow.server.app.OwFieldManagerControl
getFieldManager, getFormEventFunction, getFormEventURL, getFormTarget, init, insertLabel
 
Methods inherited from class com.wewebu.ow.server.ui.OwEventTarget
attach, detach, disableRequestListener, enableRequestListener, getAjaxEventURL, getContext, getEventURL, getFormName, getID, onExternalRequest, onFormEvent, onRequest, setExternalFormTarget, updateExternalFormTarget
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARRAY_ITEM_INDEX_KEY

public static final String ARRAY_ITEM_INDEX_KEY
query string for the selected array item

See Also:
Constant Field Values

FIELD_ID_KEY

public static final String FIELD_ID_KEY
query string for the selected field

See Also:
Constant Field Values

DEFAULT_SIZE

public static final int DEFAULT_SIZE
default field size

See Also:
Constant Field Values
Constructor Detail

OwNumberFieldControl

public OwNumberFieldControl()
Method Detail

insertEditField

public void insertEditField(Writer w_p,
                            OwFieldDefinition fieldDef_p,
                            OwField field_p,
                            String strID_p)
                     throws Exception
Description copied from class: OwFieldManagerControl
format and displays the value attached to the fieldClass in HTML for use in a HTML Form. It also creates the necessary code to update the value in the form upon request.

Specified by:
insertEditField in class OwFieldManagerControl
Parameters:
w_p - Writer object to write HTML to
fieldDef_p - OwFieldDefinition
field_p - OwField Value to be displayed
strID_p - ID of the HTML element
Throws:
Exception

insertAddArrayItemLink

protected void insertAddArrayItemLink(Writer w_p,
                                      OwFieldDefinition fieldDef_p,
                                      String strID_p)
                               throws Exception
Adds element addition link for array fields. The field ID is transmitted through a FIELD_ID_KEY specified parameter.

Parameters:
w_p - the writer object
fieldDef_p - - the field definition object
strID_p - ID of the array field
Throws:
IOException
Exception

insertRemoveArrayItemLink

protected void insertRemoveArrayItemLink(Writer w_p,
                                         OwFieldDefinition fieldDef_p,
                                         int index_p,
                                         String strID_p)
                                  throws IOException,
                                         Exception
Adds element removal link for array fields. The field ID is transmitted through a FIELD_ID_KEY specified parameter.

Parameters:
w_p - - the Writer object.
fieldDef_p - - the OwFieldDefinition object.
strID_p - ID of the array field
Throws:
IOException
Exception

onDeleteArrayItem

public void onDeleteArrayItem(javax.servlet.http.HttpServletRequest request_p)
                       throws Exception
called when user clicks to delete an array item

Throws:
Exception

onAddArrayItem

public void onAddArrayItem(javax.servlet.http.HttpServletRequest request_p)
                    throws Exception
called when user clicks to add an array item

Throws:
Exception

calculateFieldSize

protected int calculateFieldSize(OwFieldDefinition fieldDef_p)
                          throws Exception
(Overridable) Returns the calculated field size (maximum amount of characters entering into field) for the given field definition.

By default this implementation returns DEFAULT_SIZE constant

Parameters:
fieldDef_p - OwFieldDefinition of the field
Returns:
the size to be defined in rendered UI
Throws:
Exception

getValueIndexTitle

protected String getValueIndexTitle(String strID_p)
Parameters:
strID_p -
Returns:
the value index based title information for array and complex values
Since:
3.0.0.0

insertSingleEditField

protected void insertSingleEditField(Writer w_p,
                                     OwFieldDefinition fieldDef_p,
                                     Object value_p,
                                     String id_p,
                                     String errorFieldId_p)
                              throws Exception
Inserts a single value, editable HTML control.

Parameters:
w_p -
fieldDef_p -
value_p -
id_p -
Throws:
Exception

insertReadOnlyField

public void insertReadOnlyField(Writer w_p,
                                OwFieldDefinition fieldDef_p,
                                Object value_p)
                         throws Exception
Description copied from class: OwFieldManagerControl
format and displays the value attached to the PropertyClass in HTML

Specified by:
insertReadOnlyField in class OwFieldManagerControl
Parameters:
w_p - Writer object to write HTML to
fieldDef_p - OwFieldDefinition definition of field
value_p - Object Value to be displayed
Throws:
Exception

insertSingleReadOnlyField

public void insertSingleReadOnlyField(Writer w_p,
                                      OwFieldDefinition fieldDef_p,
                                      String id_p,
                                      Object value_p)
                               throws Exception
Inserts a single-value non-editable HTML control.

Parameters:
w_p -
fieldDef_p -
id_p -
value_p -
Throws:
Exception

updateField

public Object updateField(javax.servlet.http.HttpServletRequest request_p,
                          OwFieldDefinition fieldDef_p,
                          Object value_p,
                          String strID_p)
                   throws Exception
Description copied from class: OwFieldManagerControl
update the property value upon request and validates the new value. Updates the object, which was displayed in a form using the getEditHTML(...) code. Throws Exception if new value could not be validated

Specified by:
updateField in class OwFieldManagerControl
Parameters:
request_p - HttpServletRequest
fieldDef_p - OwFieldDefinition
value_p - Object old Value
strID_p - ID of the HTML element
Throws:
Exception

isComplexChildId

protected boolean isComplexChildId(String strID_p)
Parameters:
strID_p -
Returns:
true if the given ID is an externally generated complex child field ID false otherwise
Since:
2.5.3.0
See Also:
getExternalComplexFieldIdDelimiter()

setFieldManagerError

protected void setFieldManagerError(String strID_p,
                                    String error_p)
Sets the given error in the current field manager.
This method handles the complex child fields by setting the error for the parent field.

Parameters:
strID_p - the ID of the control to set the error for
error_p - the error text to set for the given control
Since:
2.5.3.0
See Also:
isComplexChildId(String)

getExternalComplexFieldIdDelimiter

protected String getExternalComplexFieldIdDelimiter()
The string ID delimiter used to separate the ID of an externally generated ID of a complex field.
The children of complex fields must be properly detected handled by this field control. The detection is performed by ID using isComplexChildId(String) which checks for the occurrence of the an external ID delimiter specified by this method.

Returns:
the external field complex child field ID delimiter
Since:
2.5.3.0

createParseIndexedError

protected String createParseIndexedError(String numberString_p,
                                         int index_p)
Parameters:
numberString_p - an erroneous number String
index_p - the error index
Returns:
an parse error text with error information (first wrong character)

validateNumber

protected Number validateNumber(String id_p,
                                Number value_p,
                                OwFieldDefinition fieldDef_p,
                                boolean updateErrors_p)
                         throws Exception
Validates a Number value against a given OwFieldDefinition. If the value is not valid an error field will be recorded for the given ID.

Parameters:
id_p -
value_p -
fieldDef_p -
Throws:
Exception - if an error occurs during validation
See Also:
setInternalFieldError(String, String)

setInternalFieldError

protected final void setInternalFieldError(String id_p,
                                           String error_p)
Register an error for a given field ID.

Parameters:
id_p - String field ID
error_p - String error message

addContainmentError

protected final void addContainmentError(String id_p,
                                         int errCount_p)

clearFieldError

protected final void clearFieldError(String id_p)
                              throws Exception
Clears the errors associated with the given field ID.

Parameters:
id_p -
Throws:
Exception

markArrayItemErrorForClear

protected final void markArrayItemErrorForClear(String id_p,
                                                String fieldId_p,
                                                int index_p,
                                                int arraySize_p)
                                         throws Exception
Marks the array item with the give ID for deletion.

Parameters:
id_p -
fieldId_p -
index_p -
arraySize_p -
Throws:
Exception

clearMarkedArrayItemErrors

protected final void clearMarkedArrayItemErrors()
                                         throws Exception
Removes errors that were marked for deletion and adjusts the already existing indexes.

Throws:
Exception

isErrorField

protected final boolean isErrorField(String id_p)
Parameters:
id_p -
Returns:
true if there are registered errors for the given field id
false otherwise

fieldContainmentId

protected final String fieldContainmentId(String id_p)

fieldContainmentCount

protected final int fieldContainmentCount(String id_p)

isErrorContainment

protected final boolean isErrorContainment(String id_p)

isMarkedForClear

protected final boolean isMarkedForClear(String id_p)

getFieldError

protected final String getFieldError(String id_p)
Parameters:
id_p -
Returns:
the error String associated with the given field id
If no error is associated with the given field ID (ie. isErrorField(String) returns false) the hard-coded "NO ERROR" String is returned.

updateSingleField

public Object updateSingleField(javax.servlet.http.HttpServletRequest request_p,
                                OwFieldDefinition fieldDef_p,
                                Object value_p,
                                String strID_p,
                                boolean updateErrors_p)
                         throws Exception
Updates a single value field.

Parameters:
request_p -
fieldDef_p -
value_p -
strID_p -
Returns:
the update value as found on the given request and parsed using the current formatter (m_numberFormat)
Throws:
Exception

init

public void init(OwFieldManager fieldmanager_p,
                 Node configNode_p)
          throws Exception
Initializes this field control with the configured number format.
If no number format is configured the default locale NumberFormat is used.

Overrides:
init in class OwFieldManagerControl
Parameters:
fieldmanager_p -
configNode_p -
Throws:
Exception


Copyright © 2013 Alfresco Business Solutions. All Rights Reserved.