Archive for March, 2009

Grey Line

The early bird discount for the two-day Flex workshop in Boston expires on Monday, April 6. Details at http://www.eventbrite.com/event/295389518.  Don’t say we didn’t warn you :)

Those who are planning to learn Flex during weekends should consider the 2-weekend Adobe Certified Flex training in Edison, NJ. Details at http://www.eventbrite.com/event/314201786.

Yakov Fain

Comments off

 

Grey Line

Even though IT market is pretty much dead, Flex developers remain in great demand.  But some people just can’t take the time off work to learn Flex.  To address this demand, we are offering a two-weekend Certified Flex training that will take place in Edison, NJ in June. Actually, this hands-on course is designed by Adobe for a 5-day class, so get ready for intensive training mode as we need to cover all the materials and labs in 4 days (two weekends).
Tuition includes two original Adobe manuals and the courseware (a $100 value).
Some people complain about crisis, but this may be an opportunity for you to learn a new skill on the run.

Details and registration information is over here: http://www.eventbrite.com/event/314201786

See you in class,
Yakov Fain

Comments (2)

 

Grey Line

Tim Bray, a Distinguished Engineer and Director of Web Technologies at Sun Microsystems has been interviewed by InfoQ about the future of the Web. With all my respect to Sun’s engineers, I have to disagree with some of the statements Mr. Bray made.

He said, “Anything that discards the Back button is a step backward”.

Ii strongly disagree that people who are used to the page-based Web apps can’t/won’t learn how to live without it. But even if it is the case, you can create RIA that support Back button – just decide what application view (no page) to show when the user hits the Back button.

Here’s one more of Mr. Bray’s statements, “The whole universe runs on polling and it scales beautifully”.

I don’t think so. To support server-side push you need to keep an open socket connection that doesn’t take almost any resources most of the time. For a server, it’s easier to keep open 65000 connections on the server, than repeatedly responding to multiple requests from 65000 clients when most of them return “Sorry, I don’t have any new data for you”.
I agree that opening a socket present issues for Web applications running behind firewalls, but still the whole polling universe doesn’t scale beautifully.

Mr. Bray continues, “Web applications are not computational intensive”.

Of course, if you are using page-based applications that just show the data, there’s nothing to do on the client other than, well, showing the data. But in the world of RIA, we should get into a different state of mind – you can and should treat the client’s CPU as a first class citizen.

For example, our company helped Mercedes Benz in design and development of their Flex-based RIA: www.mbusa.com. There’s a bunch of interdependent rules for each car model that should enable/disable UI controls depending on the user’s selection. For example, if you ordered white leather interior, you can’t have yellow exterior.  We’ve implemented the entire rule engine on the client, which makes the entire system a lot more responsive.

During one of my recent presentations, I said that if you build Flex/Java RIA utilizing fast AMF or RTMP protocols, you can bring 5000 records and keep them on the client in a split of a second.

A person from the audience asked,
“Why would I even need to keep 5000 records on the client?”
“Because you can! Of course, something like this sounds wrong for AJAX applications, but it’s normal to bring 5000+ records of reference data to the client and keep them in the client’s VM so the user’s application wouldn’t need to do a round trip to the server to validate user’s input”.

If you offload the processing to the clients, you don’t need to horizontally scale the servers.  With RIA, you can afford to have Client/Server mentality again.

Mr. Bray believes that the direction of Web applications is moving form J2EE to PHP and Rails. He didn’t make it clear for what kind of applications though. Is he talking about applications like Twitter that can go down several times a day and people will keep using it because they don’t have any better choice? I’ve heard creator of Rails calling Java legacy, and I understand the populist nature of such a statement, but it’s strange to hear this from one of Sun’s higher ups.

In this case Tim Bray is right. But if you take any application that handles your money (Banking, eCommerce, auctions) I’d rather stick to tried and true J2EE on the server and the RIA client  software (Flash Player, Silverlight, JavaFX) that runs inside a predictable Virtual Machine.

I believe that Web moves to a VM-based stateful clients with fast communication lines between the client and the server moving tons of strongly-typed data back and forth. This was a mouthful sentence, wasn’t it?

Yakov Fain

Comments off

 

Grey Line

I’ve added a new How To entry to the Wiki section of  our open source Clear Toolkit framework. It explains the steps required to turn a CRUD Flex application generated by Clear Data Builder into an AIR application.

The Wiki page of Clear Toolkit is http://cleartoolkit.wiki.sourceforge.net/

The lates build, documentation and the source code of all Clear Toolkit components you can find at https://sourceforge.net/projects/cleartoolkit/

Victor

Comments (1)

 

Grey Line

We’ve just announced the next public certified Flex training in New York City in May. It’s a 5-day training using Adobe’s original courseware where students learn Flex from scratch from well-known instructors, practitioners and book authors Yakov Fain and Dr. Victor Rasputnis.

We’ve substantially lower the price for this training responding to the current economic situation, but hurry to secure the super early discount price. See details at http://www.faratasystems.com under Training.

Enrollment will be closed as soon as we get 10 people.

People who already know Flex may consider our advanced Flex workshop for architects that will take place in Boston, MA on May 21-22.

Yakov Fain

Comments off

 

Grey Line

I have been very quiet for very long time. It was not because I have nothing interesting to report. On the contrary, it was a roller coaster ride of application development. This year can be labeled something like “Rich Internet Applications meet Enterprise Database by the way of full text search”.
I have been working on the projects to help enterprise subject matter experts do their work. It was very addictive and ever changing process that required reaching certain level of results followed by a cool review to make it believable to a “sane” developer.
We are slowly getting used to the fact that of-the-shelf and free software can find related data out of million records within a second. The fact that the found data can be ordered and presented in a form of the definite answer recognizable by user in a single glance is nothing short of magic.
Enterprises store vast amount of information comparable in size to the public accessible web – some of the clients few years ago were actually bragging how much more data they have over Google. However, most of the workers cannot access it due to data size and “system walls”. As a result, subject matter experts are mainly being used in their historical capacity – people who memorize the facts and working within those constrains. Full text search, combined with some metrics on the quality of the data, challenges both what we “know” and how we perceive our “knowledge”.
The way the knowledge is processed is about change in the next few years, as the companies really have to open up these databases for use if they want to maintain competitive edge. It will lead to a revolution in the enterprise application development. Let us see few side effects of that process so we can recognize the change.
The use of full text search will have a major impact on how the applications interact with the data. Instead of actively looking for information by digging for information with tons of drill downs and clicks, you just type what you want or highlight what matters to you.
The system uses those queues to search, rate and present information back to you with highlighted things that match your request. Moreover, with proper training systems can also identify what might be the reason why it is not applicable in the context.
Properly designed “data driven” application adapts to the things you usually search for as well as data it searches on. It can let user to add as many qualifications or “disqualifications” to the search as you seem appropriate without usual constraints of the structured data. Once a certain level of experience is established, the system easily outperforms the subject matter experts in the speed and quality of data retrieval and statistical qualifications. The main role of the human shifts to use of their analytical and pattern recognition skills.
Flex is really ideal environment for this type of applications, as you really want not only “refresh-free” experience but really “seamless” one. The ability of creating seamless environment is crucial, as the natural system implies user experience that adapts to the process AND context. As a result, visualization and transparency of the context and state are as important as quality of the search engine.
“Seamless” also implies natural flow of things. The push technology that Adobe was promoting for so long is finally coming to enterprise applications.
I will cover in next parts few components that are coming from all that development. Good news is that SEO2 are within the reach and in the eyesight of the new crop of applications.
Sincerely,
Anatole Tartakovsky

Comments off

 

Grey Line

The goal of this article is to give you a brief overview of some of the objects from clear.swc, which is a part of the open source Clear Toolkit framework available at https://sourceforge.net/projects/cleartoolkit.
Component library clear.swc includes a number of enhanced Flex components that software engineers of Farata Systems have been developing and using during the last three years in many enterprise projects. To better understand brief explanations given in this document, we strongly recommend to check out the source code from Sourceforge CVS repository and examine the source code of the classes mentioned below.
The ChangeObject Class

If you are familiar with LCDS, you know that Data Managemet Services use  ChangeObject, which is a special DTO that is used to propagate the changes between the server and the client.  Our component also includes such object but it can be used not only with LCDS but with BlazeDS too.

The class ChangeObject lives on the client side  – it is just a simple storage container for original and new versions of the record that is undergoing some changes:

package  com.farata.remoting {
[RemoteClass(alias="com.farata.remoting.ChangeObjectImpl")]
public class ChangeObject {

public var state:int;
public var newVersion:Object = null;
public var previousVersion:Object = null;
public var error:String = “”;
public var changedPropertyNames:Array= null;

public static const UPDATE:int=2;
public static const DELETE:int=3;
public static const CREATE:int=1;

public function ChangeObject(state:int=0,
newVersion:Object=null, previousVersion:Object = null) {
this.state = state;
this.newVersion = newVersion;
this.previousVersion = previousVersion;
}

public function isCreate():Boolean {
return state==ChangeObject.CREATE;
}
public function isUpdate():Boolean {
return state==ChangeObject.UPDATE;
}
public function isDelete():Boolean {
return state==ChangeObject.DELETE;
}
}

Every changed record can be in DELETE, UPDATE or CREATE state. The original version of the object is stored in the previousVersion property and current one is in the newVersion. That turns the ChangeObject into a lightweight implementation of the Assembler pattern, which offers a simple API to process all the data changes in a standard way similar to what’s done in Data Management Services that come with LCDS.

The DataCollection class that will be described below automatically keeps track of all the changes made by the use in the UI and sends a collection of the corresponding ChangeObject instances to the server.

On the server side, you can you need to separate a task into DAO and Assembler layers by introducing  external interfaces – the methods with  fill (retrieve) and sync (update) functionality (note the suffixes _fill and _sync in the Java code below).  Iterate through the collection of ChangeObject instances and call appropriate persistence functions:

/* Generated by ClearDB Utility (Dao.xsl) */
package com.farata.datasource;
import java.sql.*;
import java.util.*;
import flex.data.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.transaction.*;
import com.farata.daoflex.*;

public final class EmployeeDAO extends Employee {
public final List /*com.farata.datasource.dto.EmployeeDTO[]*/ fill{
return getEmployees_fill();
}

public final List getEmployees_sync(List items)    {
Coonection conn = null;
try  {
conn = JDBCConnection.getConnection(“jdbc/test”);
ChangeObject co = null;
for (int state=3;  state > 0; state–) { //DELETE, UPDATE, CREATE
Iterator iterator = items.iterator();
while (iterator.hasNext()) {   // Proceed to all updates next
co = (ChangeObject)iterator.next();
if(co.state == state && co.isUpdate())
doUpdate_getEmployees(conn, co);
if(co.state == state && co.isDelete())
doDelete_getEmployees(conn, co);
if(co.state == state && co.isCreate())
doCreate_getEmployees(conn, co);
}
}
} catch(DataSyncException dse) {
dse.printStackTrace();
throw dse;
} catch(Throwable te) {
te.printStackTrace();
throw new DAOException(te.getMessage(), te);
} finally {
JDBCConnection.releaseConnection(conn);
}
return items;
}
DataCollection class

This object keeps track of the changes on the client. For example, a user modifies the data in a DataGrid that has a collection of some objects used as a data provider. We’ve made a standard Flex ArrayCollection a little smarter so it’ll create a collection of ChangeObject instances for every modified, new, and deleted row. The class DataCollection will do exactly this.
Generate a sample CRUD application with Clear Data Builder and review the code of the generated sample Flex clients.  The code to populate DataCollection will look similar to this one:

[Bindable]
public var collection:DataCollection ;

collection = new DataCollection();
collection.destination=”myEmployeeDestination”;
collection.method=”getEmployees”;

collection.addEventListener( CollectionEvent.COLLECTION_CHANGE, logEvent);
collection.addEventListener(“fault”, logEvent);
collection.fill();
When the user is ready to submit the changes to the server, the following line will send a collection of ChangeObject instances to the server:
collection.sync();

Below are some relevant fragments from the class DataCollection. It offers an API for manipulating collection’s state. You can query the collection to find out if this particular object is new, updated or removed:

public function isItemNew(item:Object):Boolean {
var co: ChangeObject = modified[item] as ChangeObject;
return (co!=null && co.isCreate());
}
public function setItemNew(item:Object):void {
var co:com.farata.remoting.ChangeObject = modified[item] as ChangeObject;
if (co!=null){
co.state = ChangeObject.CREATE;
}
}
public function isItemModified(item:Object):Boolean {
var co: ChangeObject = modified[item] as ChangeObject;
return (co!=null && !co.isCreate());
}
public function setItemNotModified(item:Object):void {
var co: ChangeObject = modified[item] as ChangeObject;
if (co!=null) {
delete modified[item];
modifiedCount–;
}
}

private var _deletedCount : int = 0;
public function get deletedCount():uint {
return _deletedCount;
}

public function set deletedCount(val:uint):void {
var oldValue :uint = _deletedCount ;
_deletedCount = val;
commitRequired = (_modifiedCount>0 || deletedCount>0);
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, “deletedCount”, oldValue, _deletedCount));
}

private var _modifiedCount : int = 0;
public function get modifiedCount():uint {
return _modifiedCount;
}
public function set modifiedCount(val:uint ) : void{
var oldValue :uint = _modifiedCount ;
_modifiedCount = val;
commitRequired = (_modifiedCount>0 || deletedCount>0);
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, “modifiedCount”, oldValue, _modifiedCount));
}

private var _commitRequired:Boolean = false;
public function set commitRequired(val :Boolean) :void {
if (val!==_commitRequired) {
_commitRequired = val;
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, “commitRequired”, !_commitRequired, _commitRequired));
}
}
public function get commitRequired() :Boolean {
return _commitRequired;
}

public function resetState():void {
deleted = new Array();
modified = new Dictionary();
modifiedCount = 0;
deletedCount = 0;
}

All the changes are accessible as the properties deletes, inserts and updates:

public function get changes():Array {
var args:Array = deletes;
for ( var item:Object in modified) {
var co:com.farata.remoting.ChangeObject =
com.farata.remoting.ChangeObject(modified[item]);
co.newVersion = cloneItem(item);
args.push(co);
}
return args;
}

public function get deletes():Array {
var args:Array = [];
for ( var i :int = 0; i < deleted.length; i++) {
args.push(
new ChangeObject(
ChangeObject.DELETE, null,
ObjectUtils.cloneItem(deleted[i])
)
);
}
return args;
}
public function get inserts():Array {
var args:Array = [];
for ( var item:Object in modified) {
var co: ChangeObject = ChangeObject(modified[item]);
if (co.isCreate()) {
co.newVersion = ObjectUtils.cloneItem(item);
args.push( co );
}
}
return args;
}
public function get updates():Array {
var args:Array = [];
for ( var item:Object in modified) {
var co: ChangeObject = ChangeObject(modified[item]);
if (!co.isCreate()) {
// make up to date clone of the item
co.newVersion = ObjectUtils.cloneItem(item);
args.push( co );
}
}
return args;
}

This collection should also take care of the communication with the server and call the fill and sync methods:

public var _method : String = null;
public var syncMethod : String = null;

public function set method (newMethod:String):void {
_method = newMethod;
if (syncMethod==null)
syncMethod = newMethod + “_sync”;
}
public function get method():String {    return _method;        }

protected function createRemoteObject():RemoteObject {
var ro:RemoteObject = null;
if( destination==null || destination.length==0 )
throw new Error(“No destination specified”);

ro = new RemoteObject();
ro.destination    = destination;
ro.concurrency    = “last”;
ro.addEventListener(ResultEvent.RESULT, ro_onResult);
ro.addEventListener(FaultEvent.FAULT,   ro_onFault);
return ro;
}

public function fill(… args): AsyncToken {
var act:AsyncToken = invoke(method, args);
act.method = “fill”;
return act;
}

protected function invoke(method:String, args:Array):AsyncToken {
if( ro==null ) ro = createRemoteObject();
ro.showBusyCursor = true;
var operation:AbstractOperation = ro.getOperation(method);
operation.arguments = args;
var act:AsyncToken = operation.send();
return act;
}

protected function ro_onFault(evt:FaultEvent):void {
CursorManager.removeBusyCursor();
if (evt.token.method == “sync”) {
modified = evt.token.modified;
modifiedCount = evt.token.modifiedCount;
deleted = evt.token.deleted;
}
dispatchEvent(evt);
if( alertOnFault && !evt.isDefaultPrevented() ) {
var dst:String = evt.message.destination;
if( dst==null || (dst!=null && dst.length==0) )
try{ dst = evt.target.destination; } catch(e:*){};

var ue:UnhandledError = UnhandledError.create(null, evt,
DataCollection, this, evt.fault.faultString,
“Error on destination: ” + dst);
ue.report();
}
}

public function sync():AsyncToken {
var act:AsyncToken = invoke(syncMethod, [changes]);
act.method = “sync”;
act.modified = modified;
act.deleted = deleted;
act.modifiedCount=modifiedCount;
if (writeThrough)
resetState();
return act;
}

}
}

Data Styling with Resource Files

Resources are small files that can be attached as a property to a regular UI component as well as DataGrid column.  We call programming with resources data styling.
Again, start with examining the code of a sample project generated by Clear Data Builder. You can find a number of resource files under the folder flex_src\com\farata\resource.
Review the code of  YesNoCheckBoxResource.mxml:

<?xml version=”1.0″ encoding=”utf-8″?>
<fx:CheckBoxResource
xmlns=”com.farata.resources” xmlns:mx=”http://www.adobe.com/2006/mxml”
xmlns:resources=”com.theriabook.resources.*”
offValue = “N”
onValue = “Y”
textAlign=”center”
>

</fx:CheckBoxResource>

Doesn’t it look like a style to you? It can be specific to locale too. It makes it easy to change Y/N as on/off values to Д/Н, which means Да/Нет in Russian and Si/No in Spanish.
We’d like you to think of such resources as of entities that are separate from the application components. Isn’t such functionality similar to what CSS is about?
As a matter of fact, it’s more sophisticated than CSS because this resource is a mix of styles and properties. The next code example is yet another resource called StateComboBoxResource.mxml.  It demonstrates using properties (i.e. dataProvider) in such resource, which we also call  a Business Style Sheet. Such  resource can contain a list of values such as names and abbreviations of states:

<?xml version=”1.0″ encoding=”utf-8″?>
<fx:ComboBoxResource
xmlns=”com.farata.resources” xmlns:mx=”http://www.adobe.com/2006/mxml”
xmlns:resources=”com.theriabook.resources.*”
dropdownWidth=”160″
width=”160″
>
<fx:dataProvider>
<mx:Array>
<mx:Object data=”AL” label=”Alabama” />
<mx:Object data=”AZ” label=”Arizona” />
<mx:Object data=”CA” label=”California” />
<mx:Object data=”CO” label=”Colorado” />
<mx:Object data=”CT” label=”Connecticut” />
<mx:Object data=”DE” label=”Delaware” />
<mx:Object data=”FL” label=”Florida” />
<mx:Object data=”GA” label=”Georgia” />
<mx:Object data=”WY” label=”Wyoming” />
</mx:Array>
</fx:dataProvider>
</fx:ComboBoxResource>

Yet another example of a resource contains a reference to remote destination for automatic retrieval of dynamic data coming from, say  a DBMS:

<?xml version=”1.0″ encoding=”utf-8″?>
<fx:ComboBoxResource
xmlns=”com.farata.resources” xmlns:mx=”http://www.adobe.com/2006/mxml”
xmlns:resources=”com.theriabook.resources.*”
width=”160″
dropdownWidth=”160″
destination=”Employee”
keyField=”DEPT_ID”
labelField=”DEPT_NAME”
autoFill=”true”
method=”getDepartments”
>
</fx:ComboBoxResource>

As a matter of fact, you can’t say from this code if the data is coming from a DBMS or from somewhere else.  That data is cleanly separated from the instances of the ComboBox objects associated with this particular resource and can be cached either globally (if the data needs to be retrieved once) or according to the framework caching specifications. If you are developing a business framework, you may allow, say lookup objects to be loaded once per application or once per view.  This flexibility doesn’t exist in Singleton-based architectural frameworks.

Based on this resource file you can only say that the data comes back from a remote destination called Employee, which either a name of a class or a class factory. You can also see that the method getDepartments() will be returning the data containing DEPT_ID and DEPT_NAME that are going to be used with our enhanced ComboBox described earlier in this chapter.

OK, now we need to come up with a mechanism of attaching such resources to Flex UI components. To teach a Combobox working with resources, add a resource property to it:

private var _resource:Object;
public function get resource():Object
{
return _resource;
}

public function set resource(value:Object):void {
_resource = value;
var objInst:*  = ResourceBase.getResourceInstance(value);
if(objInst)
objInst.apply(this);
}

The resource property allows you to write something like this:

<fx:ComboBox resource=”{DepartmentComboResource}”

Each of the enhanced UI components that’s included in clear.swc includea such property.
Since interfaces don’t allow default implementation of such setter and getter and since ActionScript does not support multiple inheritance, the easiest way to include this implementation of the resource property to each control is by using the language compile-time directive #include, which includes the contents of the external file, say resource.as, into the code of your components:
#include “resource.as”

Check the code of Employee_getEmployee_GridFormTest.mxml generated by Clear Data Builder. You’ll find there several samples of using resources:

<fx:DataGrid dataProvider=”{collection}” doubleClick=”vs.selectedIndex=1″ doubleClickEnabled=”true” editable=”true” height=”100%” horizontalScrollPolicy=”auto” id=”dg” width=”100%”>
<fx:columns>
<fx:DataGridColumn dataField=”emp_id” editable=”false”
headerText=”Emp Id”/>

<fx:DataGridColumn dataField=”dept_id” editable=”false”
headerText=”Department”
resource=”{com.farata.resources.DepartmentComboResource}”/>
<fx:DataGridColumn dataField=”state” editable=”false”
headerText=”State”
resource=”{com.farata.resources.StateComboResource}”/>
<fx:DataGridColumn dataField=”bene_health_ins” editable=”false”
headerText=”Health”
resource=”{com.farata.resources.YesNoCheckBoxResource}”/>
<fx:DataGridColumn dataField=”bene_life_ins” editable=”false”
headerText=”Life”
resource=”{com.farata.resources.YesNoCheckBoxResource}”/>
<fx:DataGridColumn dataField=”bene_day_care” editable=”false”

headerText=”Day Care”
resource=”{com.farata.resources.YesNoCheckBoxResource}”/>
<fx:DataGridColumn dataField=”sex” editable=”false”
headerText=”Sex”
resource=”{com.farata.resources.SexRadioResource}”/>
</fx:columns>
</fx:DataGrid>

Using resources really boosts your productivity.

The DataForm Component

Almost every enterprise application uses forms.  Flex has the Form class that application programmers bind to an object representing data model. But the original Form class does not have means of tracking the data changes.

Since DataCollection is smart enough to automatically tracks the changes to the data on the client side, we found the way of enhancing the Form class so it works similarly to DataGrid/DataCollection duo. Yep, it has the dataProvider too.

Our DataForm control is bound to its model of type a DataCollection and it automatic tracks of all changes compatible with ChangeObject class that is implemented with remote data service.
The second improvement belongs to the domain of data validation. The DataForm can validate not just individual form items, but the form in its entirety too.  Our DataForm stores its validators inside the form rather than in an external global object.  The form becomes a self-contained black box that has everything it needs.

Software developers working on prototypes would appreciate if they should not be required to give definitive answers as to which control to put on the data form.  The first cut of the form may use a TextInput control, but the next version should use a ComboBox instead.
The third improvement should simplify the UI prototyping. We came up with a UI-neutral data form item that will allow not to be specific like, “I’m a TextInput”, or “I’m a ComboBox”. Instead, developers will be able to create prototypes with generic data items with easily attachable resources.

The DataForm is a subclass of a Flex Form, and its code implements two-way binding and includes a new property dataProvider. Its function validateAll()supports data validation. This DataForm component will properly respond to data changes propagating them to its data provider.
Review the code of the class DataForm available in Sourceforge CVS repository. Notice the setter dataProvider that always wraps up the provided data into a collection. This is needed to ensure that our DataForm supports working with remote data services the same way as DataGrid does.  It checks the data type of the value. It wraps an Array into an ArrayCollection, and XML turns into XMLListCollection. If you need to change the backing collection that store the data of a form, just point the collection variable at the new data.

If a single object is given as a dataProvider, turn it into a one-element array and then into a collection object. A good example of such case is an instance of a Model, which is an ObjectProxy  that knows how to dispatch events about changes of its properties.

Once in a while, application developers need to render non-editable forms hence the DataForm class defines the readOnly property.
The changes of the underlying data are propagated to the form in the method collectionChangeHandler().  The data can be modified either in the dataProvider on from the UI and the DataForm ensures that each visible  DataFormItem object (items[i]) knows about it. This is done in the function distributeData().

private function distributeData():void {
if((collection != null) && (collection.length > 0)) {
for (var i:int=0; i<items.length; i++)    {
DataFormItem(items[i]).data = this.collection[0];
}
}
}

Again, we need the data to be wrapped into a collection to support DataCollection or DataService from LCDS.

Technically, a DataForm class is a VBox that lays out its children vertically in two columns and automatically aligns the labels of the form items. But we’d like our DataForm to allow nesting – containing items that are also instances of the DataForm object. A recursive function enumerateChildren() loops through the children of the form, and if it finds a DataFormItem, it just adds it to the array items. But if the child is a container, the function loops through its children and adds them to the same items array. In the end, the property items contains all DataFormItems that have to be populated.

The DataForm has a function validateAll(), which in Flex framework is located in the class Validator. There, the validation functionality was external to   Form elements and you’d need to give an array of validators that were tightly coupled with specific form fields.

Enhancing Validation

It seems that validation in Flex has been designed with an assumption that software developers will mainly use it with forms and each validator class will be dependent only on one field it’s attached to.  Say, you have a form with two email fields. Flex framework forces you to create two instances of the EmailValidator object – one per field.
In the real life though, you may also need to come up with validating conditions based on relationships between multiple fields. You may also need to highlight invalid values in more than one field. For example, set the date validator to a field and check if the entered date falls into the time interval specified in  start and end date fields. If the date is invalid, you may want to highlight all form fields.

In other words, you may need not just to validate an object property, but also have an ability to write a number of validation rules in a function that can be associated not only with the UI control but also with the underlying data, i.e. with a data displayed in a row in a DataGrid.

Yet another issue of Flex Validator is its limitations when it comes to working with view states when the UI controls are created automatically. Everything would be a lot easier if validators could live inside the UI controls, in which case they would be automatically added to view states along with the hosting controls.
Having convenient means of validation on the client is an important part of the enterprise Flex framework.

Let’s consider a RIA for opening new customer accounts in a bank or an insurance company. This business process often starts with filling multiple sections in a mile-long application form. In Flex, such an application may turn into a ViewStack of custom components with, say five forms totaling 50 fields. These custom components and validators are physically stored in separate files. Each section in a paper form can be represented as a content of one section in an Accordion or other navigator. Say you have total of 50 validators, but realistically, you’d like to engage only those validators that are relevant to the open section of the Accordion.
If an application developer decides to move a field from one custom component to another, he needs to make appropriate changes in the code to synchronize the old validators with a relocated field.

What some of the form fields are used with view states? How would you validate these moving targets? If you are adding three fields when the currentState=”Details”, you’d need manually write AddChild statements in the state section Details.
Say 40 out of these 50 validators are permanent, and the other 10 are used once in a while.  But even these 40 you don’t want to use simultaneously hence you need to create, say two arrays having twenty elements each, and keep adding/removing temporary validators to these arrays according to view state changes.
Even though it seems that Flex separates validators and field to validate, this is not a real separation but rather a tight coupling.
During a conversation with a software developer, one manager said, “Don’t give me problems, give me solutions”.  OK, here comes the solution.
We’d like to make it clear – our goal in not to replace existing Flex validation routines, but rather offer you an alternative solution that can be used with forms and list-based controls.

We want to be able to have a ViewStack with five custom components, each of those has one DataForm whose elements have access to the entire set of 50 fields, but each will validate only its own set of 10.  In other words, all five forms will have access to the same 50-field dataProvider.  If during account opening the user entered 65 in the field age on the first form, the fifth form may show fields with options to open a pension plan account, which won’t be visible for young customers.
That’s why each form needs to have access to all data, but when you need to validate only the fields that are visible on the screen at the moment, you should be able to do this on behalf of this particular DataForm.

Clear component library includes the class ValidationRule.  We won’t go into details of this class here, but will rather tease you by showing a code snippet that illustrates how easy it is to embed a validator inside of the DataGridColumn:

<fx:DataGridColumn dataField=”PHONE” headerText=”Phone Number”
formatString=”phone”  >
<fx:validators>
<mx:Array>
<mx:PhoneNumberValidator  wrongLengthError=”Wrong
length, need 10 digit number”/>
</mx:Array>
</fx:validators>
</fx:DataGridColumn>

Needless to say that this is not an original Flex DataGridColumn, but its descendent.

Summary

In this writeup we’ve just touched upon the major players from the Clear component library. In the next article we’ll review the enhanecements made for the small guys like ComboBox or CheckBox.
We are also planning to record and publish a number of screencsasts that illustrate the use of various components of clear.swc. The process of creating enhanced library of Flex components will be described in greater detail in our upcoming O’Reilly book “Enterprise Development with Flex”.

Comments (1)

 

Grey Line

Clear Data Builder is a part of the open source Flex framework Clear Toolkit, see https://sourceforge.net/projects/cleartoolkit/. This blog introduces data-sync feature of CDB.

When more than one client works with the same application and the same piece of data, Clear Data Builder offers auto-notification mechanism about data modifications.  TO see how it works, examine the code of the Java class that is used for generation of a sample CRUD application using Java DTO src\com\farata\test\Employee.java:
/*
* @daoflex:java
*   transferType=com.farata.test.EmployeeDTO[]
*   keyColumns=emp_id
*   autoSyncEnabled=true
*/
public List<EmployeeDTO> fill()

The attribute autoSyncEnabled allow possibility to turn on/poff auto-notification of changes.  Set  the attribute autoSyncEnabled to true and then rebuild the project.
Copy the generated sample application \test\rpc\com\farata\test\Employee_fill_GridTest.mxml into the folder flex_src. This file contains the following code (note the line collection.autoSyncEnabled=true):
private function onCreationComplete() : void {
collection = new DataCollection();
collection.destination=”com.farata.test.Employee”;
collection.method=”fill”;
collection.autoSyncEnabled=true;
//fill_sync is the default for collection.syncMethod
log = new ArrayCollection();
collection.addEventListener( CollectionEvent.COLLECTION_CHANGE, logEvent);
collection.addEventListener(“fault”, logEvent);
fill_onClick();
}

Start the server and run the application as per CDB documentation.  When the application runs, open yet another browser instance pointing at the same url.

Modify some data in one browser and press the button Commit. The data grid in another browser window will reflect the latest changes.
This synchronization has been implemented using the data push via streaming AMF channel and has been tested with BlazeDS.

Comments off

 

 

cialis cananda canadian site for cialis can viagra be purchased without prescription viagra canadian pharmacy cialis on line india non pescription cialis order viagra uk levitra sales online how to buy cialis in canada cheap levitra without prescription propecia generic from india buy propecia without a prescription viagra quick delivery cialis samples cialis dosage cialis usa best way to use cialis viagra pay by e check find cheap cialis canadian viagra no prescription us viagra sold in us no prescription needed viagra sales from us buy cialis africa cheapest propecia prescription price cialis buy generic cialis online cialis canada on line cialis fast delivery cialis professionel buy vardenafil get free viagra sell viagra cialis delivery in 5 days or less canadian cheap viagra pills levitra sale viagra online in canada viagra canada 50mg buy female viagra online without prescription generic viagra canadian pharmacy generic viagra uk viagra online to canada cialis endurance cialis canadian cost super viagra uk cheap propecia canada cialis soft tablets pharmacy fast delivery viagra buy cheap uk viagra cialis com viagra ordering canada cialis order by mail buying cialis online canada viagra sale buy indian generic viagra buy viagra canada is it legal to buy viagra from canada purchase cialis no prescription viagra on line sale canada pharmacy best levitra prices cialis online canada no prescription drug hair loss propecia buy viagra online in the uk ed canadian pharmacy viagra pills online pharmacy propecia renova viagra online without prescription in canada tadalafil cheapest viagra buy brand name cialis no prescription needed best canadian pharmacy for propecia cheap 25mg viagra but viagra online with mastercard cheapest propecia uk baldness male propecia viagra cost soft viagra tabs viagra online shop france deer viagra cheap levitra cialis online ordering buy cialis best price cialis 10mg price how to buy cialis online with overnight shipping shop viagra pfizer where to get viagra viagra online 50mgs viagra cialis canadian pharmacy brand name cialis without prescription cialis mail order uk cheap propecia online cheapest propecia in uk discount viagra soft gels fast shiping viagra buy viagra in australia generic cialis 10mg cialis on line pricing in canada buy levitra without prescription cialis uk order cialis kanada buy viagra now how to get cialis without prescription drug viagra cheapest priced propecia viagra original buy online order viagra canada 5 mg propecia buy viagra visa cheapest propecia in uk original viagra where to buy cialis cheap viagra for mail order find cheapest cialis best price for propecia online health center for viagra prescriptions purchase discount viagra 10 mg vardenafil online canadian pharmacy viagra cheap viagra prescription online usa pharmacy viagra viagra cheapest prices canadian pharmacy discount cheap canadien viagra viagra femele viagra purchase online pharmacy canada viagra viagra mexico buy pfizer viagra online generic fda approved purchase no rx cialis canada viagra sales viagra pushups viagra online reviews cialis 20 mg canada cialis mail order uk canada online pharmacy propecia viagra from china cheapest levitra uk order viagra us buying propecia online discouont viagra levitra purchase viagra where to buy were to buy viagra buy viagra without rx levitra in uk how to buy levitra online propecia pay by check buy cialis pill fda approved viagra viagra online buy buy cialis online without prescription viagra online tester best place cialis canadian viagra sales best way to buy cialis online generic viagra viagra online 50mgs prescription viagra buying viagra now buy cialis canada purchase cialis us viagra england mexico viagra without prescription viagra cialis online canada canadian online cialis order discount viagra online natural viagra propecia candaian pharmacy lowest price viagra us pharmacy propecia or finasteride cialis ship to canada cialis 50 viagra online delivered next day canadian healthcare generic cialis how much is viagra fine levitra viagra price cheap propecia online india get propecia prescription cialis sample viagra prescription needed cheap viagra pills online free sample pack of cialis best price generic propecia cialis pharmacy online purchase viagra usa discount sale viagra bought cialis in mexico? viagra online without prescription united states propecia buy cialis philippines female viagra next day delivery approved cialis pharmacy tuna viagra viagra on line canada cialis and ketoconazole sales of viagra real viagra no prescription mexico online generic cialis 100 mg cialis canadian viagra generic canada pharmacy viagra super active viagra purchase on line pharmacy cheap propecia online canadian online pharmacy viagra online prescription propecia canada prescription viagra overnight delivery cialis cialis generic how to buy levitra online purchase cialis usa viagra dose brand por cialis online 100mg viagra canadian scam cheap cialis online canada cialis discount prices non generic levitra propecia sales canadian canadian healthcare generic cialis low cost viagra from canada buy cialis canada hydrochlorothiazide cialis health center for viagra prescriptions viagra cialis online cialis at canadian pharmacy online propecia prescription generic viagra australia cialis or viagra discount sale viagra viagra no prescription needed canadian generic viagra online best price for cialis viagra alternatives canada generic propecia buy 25mg viagra online canada generic viagra with echeck get cialis fast viagra onlines viagra prescriptions without medical overnight canadian viagra cialis without rx buy cialis on line no prescription viagra online without prescription in canada cialisis in canada propecia 1mg price canada cheap viagra buying generic viagra online for soft tabs viagra buy real viagra pills usa viagra price germany levitra.com cheapest viagra to buy online in uk discount levitra online viagra cialis trazodone cialis 5mg canada cialis 50 canada levitra order propecia viagra us pharmacy cheap generic viagra india usa cialis viagra cialis for sale cheapest propecia pharmacy online buying cheapest viagra no rx viagra best prices on generic cialis viagra tablet no prescription needed cialis overnight cialis professional 100 mg buy generic no online prescription viagra viagra canadian sales 50mg viagra retail price cialis online cheap cialis samples buy levitra online canada online canadian pharmacy propecia viagra pharmacy cialis 30 mg 50mg generic viagra wh ere can i buy cheap cialis viagra for canada levitra sell i need to buy propecia order levitra online were to buy viagra? cheap viagra 50mg cheap viagra canada online viagra levitra cialis viagra femele order viagra online no prescription purchasing cialis viagra echeck canadian healthcare viagra sales levitra online pharmacy cialis canada 5mg cheap propecia no prescription free viagra without prescription buy cialis from india buy cheap uk viagra cialis free delivery viagra uk usa cialis women cialis 20 mg 100 mg viagra fast order cialis viagra in usa order rx canadian cialis buy generic viagra canada cheap fast generic viagra samples of cialis low cost viagra from canada canadian cialis without a perscription generic propecia cheap online presription for viagra viagra online without prescription from india best propecia prices buy canada in propecia levitra 20 mg viagra samples buy viagra with discount overnight cialis delivery saturday online canadian pharmacy levitra cialis from canada buy viagra online canada i need viagra now cialis price in canada propecia sales canadian online propecia uk order viagra online uk cialis london delivery buy propecia now pharmacys that sell propecia buy cialis mexico what is viagra soft tabs buy viagra online from canada cialis without prescription brand name buy propecia without prescription cialis australia buying generic viagra online for generic cialis for sale cialis 50 cheap cialis without rx buy online propecia viagra no prescription canada cialis no rx required viagra in australia canadian generic cialis - best price viagra overnite can viagra be purchased without prescription cheap propecia no prescription viagra 25 mg online viagra prescription label buy propecia international pharmacy i want free viagra cialis online us cialis canada on line propecia cialis viagra purchase cialis soft tabs find cialis no prescription required pharmacy fast delivery viagra cialis woman viagra for less in the usa cialis professional no prescription where can i purchase propecia uk viagra sales best deal for propecia best reviewed cialis sites online levitra cheap discount cialis purchase no rx cialis buy cialis online china viagra soft tablets canadi an pharmacy propecia viagra in the united kingdom we deliver to canada viagra generic cialis cialis super viagra drug viagra cheap viagra ship next day buy viagra without a prescription no prescription cialis united-pharmacy viagra tablets cialis buy pfizer viagra online canada viagra sales discount cialis online buy prescription propecia without cheap propecia online india female viagra cheap pfizer viagra for sale homemade viagra cialis brand without prescription generic viagra canadian viagra online overnight viagra pharmacy buy viagra online canada viagra switzerland cheap levitra online cialis 5 mg where to buy viagra online women viagra cialis prices cialis canadian cost where to buy viagra best cialis prices best place to buy viagra viagra ordering generic cialis sales find discount cialis online original brand cialis buy cialis online uk cialis tabs cialis canadian pharmacy buy cialis on line no prescription going off propecia canadian pharmacy viagra cheap generic prescriptions propecia canadian soft viagra real cialis without prescription canadian cialis 20 mg cheap propecia canadian pharmancy order cialis online canada levitra purchase cialis no prescription needed buy cialis from mexico canadian generic viagra online generic propecia finasteride price cialis cialis 5mg canadian generic buy propecia prescriptions online pill decription of propecia viagra medication cialis soft womens viagra online viagra generic best prpice cialis brand name cialis internet generic cialis mexico: one day delivery cialis viagra without prescription low price cialis buy viagra online canada cialis generic online cheap viagra online canadian healthcare viagra online uk get viagra fast best shop for viagra best price propecia womens viagra cheap no prescription cialis generic drug viagra fed ex cheap levitra without prescription viagra injectable buy cialis overnight delivery generic viagra online pharmacy canadian online pharmacy viagra canadian low price cialis and viagra generic propecia viagra healthcare canadian pharmacy propecia cost cheap generic levitra buy cheap cialis online uk cialis sale overnight shipping order viagra 25mg online canada bought cialis in mexico? where to get a precription filled for viagra cialis express delivery viagra professional canada generic levitra cialis buy viagra online canada cialis dosage viagra overnight mail order propecia prescriptions cialis samples canada cialis online pharmacy viagra online usa purchase cialis without prescription canada viagra pharmacies scam brand name viagra cialis online ordering cialis soft tablets purchase levitra canadian pharmacy where to purchase cialis viagra costs generic viagra canada buy cheap propecia online generic propecia alternative best doses for propecia viagra online reviews levitra versus viagra drug hair loss propecia united healthcare viagra ed canadian pharmacy where buy viagra buy viagra from canada viagra online wit cheapest viagra anywhere canadian cialis no prescription buy propecia now cheap prescription propecia cialis on prescrition in australia canadain cialis buy cialis online without prescription canadian pharmacy cialis 5 mg is buying viagra online bad viagra dose viagra no prescription needed propecia no prescription cialis no prescription needed quick delivery cialis ottawa pharmacy viagra sales in canada deals on cialis cialis generic cialis health store how to buy levitra in canada please prescription. 20 purchase cialis vs. australia healthcare online viagra cheap viagra from india how to get some viagra best viagra buy in canada online cialis lowest price propecia buy viagra online paypal viagra availability in chicago cheap propecia uk purchase viagra from canada purchase real name brand viagra generic cialis next day delivery alternatives to cialis cialis mail order usa cialis canadian pharmacy generic cialis mexico cialis free delivery generic online propecia generic propecia sale sales cialis viagra and paypal viagra, overnight delivery canadian healthcare find cheap viagra online no prescription viagra brand cialis online lowest propecia price soft tab viagra cialis women purchase viagra online pharmacy rx1 buy propecia now levitra 20mg canadian pharmacy discount lowest price propecia best pfizer viagra for sale viagra canda purchasing cialis with next day delivery canadian medicine viagra viagra online delivered next day propecia canada viagra.com viagra for sale online in the uk herbal propecia viagra online 50mgs cialis medication cialis professional 100 mg cialis delivered fast viagra cialis online sales viagra to sell buying cialis no prescription viagra for sale united pharmacy buying propecia cheapest price viagra cialis canada cheap cialis free samples drug viagra viagra delivered one day compare cialis prices online levitra discount pfizer mexico viagra best price viagra buy viagra lowest price 30 day package of cialis viagra cialis sales price of propecia from canada canadian levitra without prescription viagra online without prescription from canada propecia for sale how do i order viagra online cialis delivered canada ordering viagra uk 50mg viagra no prescription cialis generica generic levitra canada buy viagra without pr canada healthcare viagra mexico pharmacy cialis 10 mg vardenafil online cialis from india viagra in usa order cheap canadian viagra pills approved viagra pharmacy cialis sales usa order generic viagra canada buy cialis pills cialis order by mail rx canadian cialis free viagra cheap generic viagra india where to buy cialis compare cialis prices online cheap cialis in uk professional cialis cialis pills for sale guaranteed cheapest viagra cialis 10 mg levitra discount cheap drugs, viagra buy generic cialis online from canada canadian pharmacy no prescription needed viagra prescription for cialis online canadian rx viagra canada cheap viagra buy online viagra cialis for sale in uk viagra in usa order get viagra without a prescription cialis online store price check 50mg viagra cheapest viagra prices best prices on generic cialis find cheap viagra online name brand cialis levitra prescription levitra canadian pharmacy buy cialis online in usa propecia with no prescription cialis delivered canada best price for generic cialis online prescription propecia cheap price viagra discount sale viagra herbal viagra wholesale buy cialis online uk brand cialis for sale cialis from qualified pharmacy viagra availability in chicago cialis without prescription brand name purchase discount cialis canadian non prescription viagra canadian pharmacy cialis professional online cheap viagra canada canada healthcare viagra brand cialis online free sample pack of cialis viagra discount can viagra be purchased without prescription viagra quick delivery cheap cialis discount drug propecia cialis no presciptions cialis professional canadian pharmacy viagra no prescription best price generic cialis can levitra be bought without a prescription mexican viagra cialis without a prescription viagra professional canadian pharmacy brand name viagra buy viagra from canada cialis for free usa buy viagra viagra echeck discount price viagra find cialis no prescription required buy viagra without rx canadian healthcare canadian viagra and healthcare viagra in us pharmacy, propecia soft gel viagra canadian healthcare online viagra cheap viagra canada cialis prices viagra online no prescription canadian pharmacy discount code viagra we deliver to canada viagra generic levitra canadian healthcare buying cialis soft tabs 100 mg viagra prices viagra for order levitra sales online viagra new zealand buy viagra pills viagra in usa buy cialis on line canadian low price cialis and viagra viagra north shore three meds viagra when will viagra be generic cheapest propecia uk cheap viagra without prescription purchase viagra online without prescription cialis online usa viagra lawyers by cialis online buy cheap generic propecia best viagra soft prices viagra canda cialis online canada no prescription viagra express delivery propecia for sale online propecia without perscription viagra 25 mg online can i buy viagra in canada get propecia online pharmacy buying viagra in canada canadian healthcare viagra uk purchase viagra without prescription how to buy cialis viagra online in spain viagra pfizer no prescription cheap levitra without prescription cialis next day viagra north shore homemade cialis cialis no prescription needed quick delivery purchase cialis from us viagra free trial pack cheapest propecia indian cialis rx generic viagra cialis online canadian pharmacy buy viagra online without a prescription info viagra generic viagra online pharmacy generico viagra were to buy viagra online indian viagra cialis delivery canadian pharmacy viagra brand aus viagra viagra pill cheepest cialis cialis no rx discount generic propecia viagra 50mg no prescription 10mg levitra get viagra buy cheap propecia internet pharmacy propecia cost viagra propecia generic canada buy cialis on where to purchase cialis cialis 100 mg buy real cialis online get cialis very fast purchase discount cialis canadian viagra for sale cheapest price propecia cheap viagra canadian chemist generic propecia cheap purchase cialis online without prescription cheapest viagra to buy online in uk generic propecia india real viagra pharmacy prescription how much to buy viagra in pounds purchase viagra online best price generic propecia cialis canada online drugstore non prescription cialis buy cialis online usa viagra in usa levitra tablets canadian pharmacy viagra cheap cheap viagra internet 5mg cialis online viagra alternatives cialis +2 free viagra combine cialis and levitra best viagra and popular in uk cialis women viagra pharmacy cialis alternatives viagra cialis for sale buy propecia online usa how to order one viagra canadian healthcare online viagra levitra sales cialis health store online pharmacy canada viagra generic propecia online pharmacy online viagra levitra cialis viagra for sale fast viagra usa branded viagra cialis canada on line propecia in canada daily cialis online buy generic cialis canada viagra overnight shipping 100 mg viagra canada pfizer viagra cheap real viagra to buy propecia dr dallas levitra for sale canadian health care pharmacy order viagra viagra online uk usa cialis sales buy cialis without rx viagra canadian chemist online generic cialis 100 mg cialis from india tablet viagra propecia online usa viagra seizures viagra soft cialis and viagra on li cialis india pharmacy buy canadian cialis online best price propecia canada info viagra daily cialis for sale buy levitra online without prescription viagra 100mg england cheap cialis canada cialis eli lilly cialis for sale in uk quality cialis soft tabs cialis buy cialis online no prescription cialis online sale how much cialis canadian cialisis buy viagra 100mg cheap discount cialis safe online to buy cialis buy viagra online real brand viagra for sale viagra cheap fast shipping finasteride no prescription viagra pharmacy london how to get cialis in canada viagra express delivery buy real viagra pills usa cialis online uk viagra without prescription levitra viagra cialis brand cialis online fast shiping viagra canadiancialis viagra 100 non pescription cialis mail online order propecia canadian pharmacy for generic cialis viagra mastercard cialis by mail viagra professional canada order propecia online pharmacy canada cialis buying propecia online cialis vs levitra next day delivery cialis discount online propecia generic propecia in uk purchase viagra from us propecia 1mg price cialis online uk quick united states viagra cheapest cialis to buy online cialis mexico sell viagra tennessee online pharmacy propecia viagra fast shipping purchase cialis no prescription cialis online order cialis canadian buy cialis uk viagra soft tabs 50 mg canadian pharmacy for cialis canada viagra pharmacies scam canadian pharmacy cialis soft www.viagra.com 25mg viagra online search: rx1 cialis cialis daily canada branded viagra order cialis from canada cialis online shop cheapest propecia uk cheap viagra with fast delivery cialis fast delivery viagra online to canada brand viagra canada usa cialis selling propecia online cialis 10 mg best price for propecia online free cialis sample cialis samples canada viagra/cialis sales best prices for propecia pfizer viagra