Kbase 18217: Apptivity how to convert data between database and screen
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  31/08/1998 |
|
Apptivity how to convert data between database and screen
This K-base will explain how to build your own translator class so
that you can manipulate data between the database and the screen.
To provide you with a way to change the data between the database and
the screen output, Apptivity made two levels of abstraction:
1) Apptivity offers the abDataSink as a buffer where all data passes
from the database to the screen and back.
2) The abBinder class offers the possibility to change the behavior
of data-aware controls.
The basic idea is to change the data coming from the database to
another value when it is displayed. When saved to the database, the
screen-value needs to be reconverted to the database-value.
There are several ways to implement this but the best way seems to do
this using the abTranslator class. In the code you can bind the
abTranslator that you created to the binder of the data-aware control
in order to use some methods that you have overwritten to do the
convertion for you.
The example code will show how to extend the abTranslator class and
implement your own translation algorithm. The class will add or
delete "\n\ntbo" to or from a database field towards a abTextfield in
order to show the mechanisme.
The new class looks like:
import java.applet.*;
import java.net.*;
import jdbc.math.*;
import jdbc.sql.*;
import progress.apptivity.client.*;
import progress.apptivity.igui.*;
import com.indius.base.*;
import netscape.application.*;
public class myTranslator extends abTranslator{
public myTranslator(abEnv theEnv){
super(theEnv);
}
public myTranslator(abEnv theEnv, int theStorageType){
super(theEnv,theStorageType);
}
public myTranslator(abEnv theEnv, int theDisplayType, int theStora
ageType){
super(theEnv,theDisplayType,theStorageType);
}
//tbo
//This method will be called when the binder transfers the data
//from the abDataSink to the Object bound to it.
//the ExchangeMode of the binder must be set to READ_MODE or
//READ_WRITE_MODE (default) that can be found in the abI_Binder
//class
public Object getDisplayValue( Object storageValue ){
if(storageValue == null){
return null;
}
else{
return ((String)storageValue + "\ntbo");
}
}
//tbo
//This method will be called when the binder transfers the data
//from the bound object
//to the abDatasink. The ExchangeMode of the binder must be set to
//WRITE_MODE or READ_WRITE_MODE (default) that can be found in the
//abI_Binder class
//CAVE AT
//The documentation says that the method
//public Object getStorageValue(Object)
//will be called so you need to override it
//but this will not work. It took me some time
//to figure out that in
//the abTranslator class there is a second method
//defined with the same name but
//an additional boolean parameter so it is this method
//that needs to be overwritten.
//To find this, I used some class-viewer I found on the web.
public Object getStorageValue(Object displayValue,boolean testing){
String theDisplay = (String) displayValue;
String storageValue = null;
if(displayValue == null){
return null;
}
if(theDisplay.endsWith("\ntbo")){
storageValue = theDisplay.substring(0,theDisplay.length() -4 );
}
else{
storageValue = theDisplay;
}
return storageValue;
}
}
This translator can be implemented in the following way in the init
method of the form:
translatingForTbo = new myTranslator(theApp());
textField1.binder().setTranslator(translatingForTbo);
TBO
08/31/1998