Data Binding is supported for classes according to the JavaBean conventions.
The UI-designer stores the information about the mapping and the assigned Code-Generator generates Java-code, that heavily reduces mundane programming. One of the most visible advantages of XMA is the support for bulk attribute transfer between Java Beans and XMA widget models. If you have defined the mapping as illustrated in the previous section, the Code-Generator automatically generates the mapping code, at the server pages, that looks like in the code listing below.
The methods atomicWMToBusinessData and
businessDataToAtomicWM are included in the generated class
of the page that holds the widgets. businessDataToAtomicWM
is responsible for transferring the mapped attributes from the Java Bean
to the widget-models and the method atomicWMToBusinessData
does the inverse.
/**
* Copies values of widget models to attributes of the provided BusinessData objects.
*/
public void atomicWMToBusinessData(at.spardat.samplespar.model.Sparbuch sparbuch) {
sparbuch.setIdKunde(idKunde.toString());
sparbuch.setIdSparbuch(idSparbuch.toString());
sparbuch.setNumKonto(numKonto.toInt());
sparbuch.setNamKontowortlaut(namKontowortlaut.toString());
sparbuch.setBetSaldo(betSaldo.toInt());
sparbuch.setBtrZinssatz(btrZinssatz.toInt());
sparbuch.setDatEroeffnung(datEroeffnung.toDate());
sparbuch.setLastmodified(lastmodified.toDate());
}
/**
* Copies attribute values of the provided BusinessDatas into widget models.
*/
public void businessDataToAtomicWM(at.spardat.samplespar.model.Sparbuch sparbuch) {
idKunde.set(sparbuch.getIdKunde());
idSparbuch.set(sparbuch.getIdSparbuch());
numKonto.set(sparbuch.getNumKonto());
namKontowortlaut.set(sparbuch.getNamKontowortlaut());
betSaldo.set(sparbuch.getBetSaldo());
btrZinssatz.set(sparbuch.getBtrZinssatz());
datEroeffnung.set(sparbuch.getDatEroeffnung());
lastmodified.set(sparbuch.getLastmodified());
} At a conceptual level,
filling widget-models from attributes of a JavaBean is not much
different than filling a table-model from a List of
JavaBeans. Therefore, the mapping-editor also allows to connect
table-columns to attributes, as you may see in Data Mapping Editor
Again, two modes are supported. Either pre-existing table-columns are being attached to attributes or the table-columns are created from attributes. The last mode is the preferred one because it's the faster approach. Either way, the following example shows how the generated code looks like:
/**
* This is a support method to create the table cells of one row from one or more BusinessObjects.
* You may overwrite this method if you need a custom mapping from BusinessObject attributes
* to table columns that you were unable to specify in the UI designer.
*
* @return the returned Object[] is needed in the constructor of a TableRow.
*/
public Object[] sparbuecherCreateCells(at.spardat.xma.samplespar.data.SparbuchData sparbuch) {
Object [] cells = new Object[7];
cells[0] = sparbuch.getNumKonto();
cells[1] = sparbuch.getNamKontowortlaut();
cells[2] = sparbuch.getBetSaldo();
cells[3] = sparbuch.getBtrZinssatz();
cells[4] = sparbuch.getDomKestpflicht();
cells[5] = sparbuch.getDatEroeffnung();
cells[6] = sparbuch.getLastmodified();
return cells;
}
/**
* This method creates a TableRow object and adds it to the end of the table.
* The key of the row is drawn from the key attribute specified in the UI designer.
* The image id is resolved by calling sparbuecherGetImageId. The cells of the table
* are taken from a call to sparbuecherCreateCells.
*/
public TableRow sparbuecherAddRow (at.spardat.xma.samplespar.data.SparbuchData sparbuch) {
return new TableRow ((TableWM)sparbuecher, sparbuch.getIdSparbuch().toString(), sparbuecherCreateCells (sparbuch), sparbuecherGetImageFor (sparbuch));
}
/**
* This method is called from sparbuecherAddRow to figure out an image
* id for a particular row. If you do not overwrite this method, the table row
* does not have an image id.
*/
public int sparbuecherGetImageFor (at.spardat.xma.samplespar.data.SparbuchData sparbuch) {
return 0;
}
/**
* This method iterates over the collection and calls sparbuecherAddRow for
* each element.
*/
public void sparbuecherFill (Collection c) {
sparbucher.clear();
for (Iterator iter = c.iterator(); iter.hasNext();) {
sparbuecherAddRow ((at.spardat.xma.samplespar.data.SparbuchData) iter.next());
}
}All generated methods start with the name of the table widget
model, which is sparbuecher in the example. Comments on the
generated methods:
xxxCreateCells : Extracts all mapped
attributes from the BusinessObject and fills an
Object[] .
xxxGetImageFor : May be overwritten in the subclass of the generated class to provide the id of an image that is displayed in front of the table row.
xxxAddRow : Adds a row to the end of the
table widget model using xxxCreateCells and
xxxGetImageFor . In order for this method to work
correctly, a key for each row must be defined in the
mapping-editor by connecting an BusinessObject
-attribute to the table, i.e., not to a column but to the table.
Then the generated code calls toString() on that
attribute to get a string representation of the
key-attribute.
xxxFill : Expects a Collection of
BusinessObject s of the same type as connected in the
mapping-editor and adds a row for each element.