quick.dbtable
Interface DataMap


public interface DataMap

DataMap is used to do the convertion from actual data format to the display format.

  Example :
    If the data in database is 1200 and you want to display that as $1,200
    then you need to convert 1200 to $1,200.
  Using this class you can provide the mapping

 Sample implementation
public class MyMap implements DataMap
{
  java.text.DecimalFormat df = new java.text.DecimalFormat("#,##,###,####");

  public Object convertDataToDisplay(Object val)
  {
      //in DB we have a integer value
      Integer myNumber = (Integer)val;

      try
      {
        //convert the integer to string in the format  "#,##,###,####"
        return df.format(myNumber.toString());
      }
      catch(Exception e)
      {
        //handle this better
        return "0";
      }
  }

  public Object convertDataToStore(Object val)
  {
    try
    {
      return Integer.valueOf(df.parse((String)val));
    }
    catch(Exception e)
    {
      return new Integer("0");
    }

  }
}

Since:
2.0.2
See Also:
Column.setDataMap(DataMap)

Method Summary
 java.lang.Object convertDataToDisplay(java.lang.Object val)
          converts the data from database format to the display format
 java.lang.Object convertDataToStore(java.lang.Object val)
          converts the data from display format to the database format
 

Method Detail

convertDataToDisplay

public java.lang.Object convertDataToDisplay(java.lang.Object val)
converts the data from database format to the display format
  Example :
    If the data in database is 1200 and you want to display that as $1,200
    then you need to convert the input value 1200 to $1,200.

 Warning: this method will be called everytime a cell is displayed
          So don't add a time consuming code into this method , that
          will bring down the DBGrid performance
 

Parameters:
val - the actual underlying data object from database

convertDataToStore

public java.lang.Object convertDataToStore(java.lang.Object val)
converts the data from display format to the database format
  Example :
    If the data is displayed as $1,200 and you want to store it as 1200
    in database, then convert $1,200 into 1200

 

Parameters:
val - the actual underlying data object from database