You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by "Mitchell, Charles A CONT J6415," <ch...@pacom.mil> on 2004/03/19 04:33:10 UTC

Suggested Change to Intake's IntegerField.java, DoubleField.java etc

I checked out the 3/15/04 code.  I have some integer fields in the database that I'd like to be able to set to null instead of 0.

The way the code's written in the 3/15 file, the getSafeEmptyValue() defaults to 0.  The following change allows me to build an intake.xml field like :

<field name="SortOrder"  key="SortOrder" type="int" emptyValue="null">
</field>

Changes to setEmptyValue and getSafeEmptyString :
=============


  /**
   * Set the empty Value. This value is used if Intake maps a field to a
   * parameter returned by the user and the corresponding field is either empty
   * (empty string) or non-existant.
   *
   *@param prop  The value to use if the field is empty.
   */
  public void setEmptyValue( String prop ) {
    if ( prop == null ) {
      emptyValue = new Integer( 0 );
    }
    else if ( prop.equalsIgnoreCase( "null" ) ) {
      emptyValue = null ; 
    }
    else {
      emptyValue = new Integer( prop );
    }
  }


  /**
   * Provides access to emptyValue such that the value returned will be
   * acceptable as an argument parameter to Method.invoke. Subclasses that deal
   * with primitive types should ensure that they return an appropriate value
   * wrapped in the object wrapper class for the primitive type.
   *
   *@return   the value to use when the field is empty or an Object that wraps
   *      the empty value for primitive types.
   */
  protected Object getSafeEmptyValue() {
    if ( isMultiValued ) {
      return new int[0];
    }
    else {
      return getEmptyValue();
    }
  }