de

Business Entities

Our minimalistic concept of "business entities" means data entities ("records"), which are associated with a certain datatype (like "customer") and have a unique key. In other words: business entities add sufficient semantics to data to allow generic code at least for simple operations like delete or update of entities.

Business entities are especially suitable for XML-driven "single-page applications". The (semantically) same data record may be visible at various panels. If one of them is updated or deleted, in most cases an AJAX-request is posted to update the server-side database. The asynchroniously received server-response can be evaluated by the success-handler of the AJAX-call.

If the response contains one or more "entity events" with the datatype and the unique keys of affected entities, Javascript-events can be triggered to be evaluated by affected panel- or control-instances (which are "tagged" with the datatype).

Business entities are supported by our control xw-browse, if a datatype-name is provided in property "datatype" at initialization and if the meta-property is provided with the unique key-description for the rows. The datatype's name will be added then automatically as CSS-class with prefix "xw-datatype-" (e.g. "xw-datatype-customer", if datatype is named "customer") to the xw-browse. So, the controls with datatype "customer" can be easily notified directly with

$(".xw-datatype-customer").trigger(...);

XML-Events

As our web-apps communicate with XML-messages between client (browser) and server, we defined special XML-structures for the important events "entities-deleted" and "entity-updated", which are sent to the client after successful server transactions.

Sample-Events for datatype "customer"

<!--Server notifies client, that two customers with primary keys "180" and "582" were successfully deleted--> <response> <event datatype="customer" type="entities-deleted"> <key> <pk>180</pk> </key> <key> <pk>582</pk> </key> </event> </response>
<!--Server notifies client, that customer with primary key "582" was modified in several fields--> <response> <event datatype="customer" type="entity-updated"> <key> <pk>582</pk> </key> <values> <name>Musterman</name> <zip>91320</zip> <city>Ebermannstadt</city> <notice> <line>Customer doesn't like</line> <line>email-advertisement.</line> </notice> <title is-null="true"/> </values> </event> </response>

Triggering events in AJAX-success-handler:

function (response) {
  $(response).find(">response>event").each(function () {
    var e = $(this), keys = [];
    e.find(">key").each(function () {
      var key = {}, cn = this.childNodes;
      for (var i = 0; i < cn.length; i++) { 
        var node = cn[i]; 
        if (node.nodeType == 1) // element node
          key[node.nodeName] = $(node).text();
      }
      keys.push(key);
    });
    $(".xw-datatype-" + e.attr("datatype")).trigger(
      e.attr("type"), { event: e, keys: keys });
  });
} 

If compound keys are used, the key-elements contain several sub-elements. A server response may contain an arbitrary count of event-elements.

Javascript Event-Handler

Own panels or controls may participate in the entity-event-concept, if they are tagged with the datatype-class and define event-handlers, e.g.:

$("#myCustomer").addClass("xw-datatype-customer").on("entities-deleted", function (e, ui) { 
    myDeleteRows(ui.keys); 
    return false;
}).on("entity-updated", function (e, ui) {
  var row = myFindRow(ui.keys[0]);
  if (row != null) myUpdateRow(row, ui.event.find(">values"));
  return false;
});