The architecture for controls in DataFlex WebApp is similar to Visual DataFlex desktop applications. In Visual DataFlex a control consists of a DataFlex class and a windows class. The DataFlex class is generally a combination of DataFlex code and C/C++ runtime code and the windows classes are C/C++ code in the Visual DataFlex runtime or an external DLL.

DataFlex WebApp Controls consist of 2 main parts

  • Server Side DataFlex control class
  • Client Side control

 

DataFlex Server Side control

lets trake a look at the server side class for a simple control, the cWebHtmlBox. This is a simple control that allows you to add client side Html via a simple server control

for readability we removed some of the code in the class and only left the pieces important to this post

At the top the cWebBaseControl package is used. This is of course the base class for the control

The DesignerJSClass meta data tells the DataFlex Studio what Javascript class to use when modeling this control in the Studio Designer

The class name is cWebHtmlBox and the base class is cWebBaseControl.

In the constructor a property called psHtml is declared. It is also prefixed with a metadata keyword of WebProperty. This tells DataFlex that this property is a web property.

Web Properties

Web properties are properties that are marked to specifically track data for each client connection. You cannot use regular properties or objects to track data. Server processes are being reused by different connections and the data contained in regular properties will not be the one from the previous call.

Web Properties maintain their state across calls automatically. There are different typeeee to maintain the state of web properties

There are different types of web properties

  • Client
  • Server
  • ServerSession

A Client web property stores its value on the client. The value of the property is sent back to the server on every call and synchronized  so it is available on the server as well.

A Server web property stores its value on the server. The value is not available on the client side. Server web properties are cleared when the page is reloaded

A Server Session web property stores its value on the server and attaches the value to the session. Its value is not available on the client side and does not get cleared with a page reload. It does however expire when the session expires

Events

The second property pbServerOnClick is a special web property that controls the OnClick event. Most events are not automatically sent to the server to keep the communication overhead to a minimum.

if the pbServerOnClick property is set to true the client java script code knows that we want the OnClick event to be called on the server.

Later in the code you can see the declaration of the event prefixed by the meta data { MethodType = Event }.

in addition any event has to be published. This is done in the End_Construct_Object method using the WebPublishProcedure command.Client Side control

Client Side control

Another line you can see in the constructor is the setting of the psJSClass property.

This property connects the server side DataFlex class to a Javascript client side class in our case df.WebHtmlBox.

DataFlex WebApp client controls are made of 3 distinct parts.

  • A JavaScript class
  • CSS Classes
  • HTML code generated by the Javascript class

lets look at a few parts of the JavaScript class

above you can see the constructor of the client side class for the cWebHtmlBox. Again we have removed code that is not needed for this exercise.

similar to the DataFlex server side control you can see the base class, declaration of web properties and events.

lets look at a few important methods in this class

 

The openHtml and closeHtmmethods are called by DataFlex when the control needs to be added to the web page. They are creating the necessary Html code for the control.

The afterRender method is called when the control is fully rendered on the client side and available in the DOM.

The above code shows two more methods of interest. The updateHtml method which is called from the server side UpdateHtml method via ClientAction and the onHtmlClick method which is used to send the OnClick event to the server.

 

Communication between Server and Client

In Visual DataFlex communication between the DataFlex class and windows control is rather easy. They run in the same process and can talk directly to each other.

In a web application things get more complicated. The web server is almost always a different computer from the computer that runs the client (web browser). Often they are of course in different geographical areas as well.

One thing that complicates things even more is that a client process is not connected to the server process all the time. The client calls the server which executes code in a server process. Once the code execution finishes data is sent back to the client and the connection between client and server ends at this time.

For one thing already mentioned earlier data stored on the server in properties or global variables or objects is not available between two different calls from the same client. Even worse a call from a different client can see the data that was previously sent from another client. This is were web properties come in. They are synchronized on each call to the data for a specific client.

Communication is handled bu a number of methods

  • Server Actions
  • Events
  • Client Actions

Server Actions

Server Actions are essentially methods in the server side DataFlex class that are called from the client side JavaScript code using the serverAction method. You can pass parameters and there is also a return value

Events

Events are a special kind of server action. Technically they work the same as a standard server action but as mentioned earlier events have a way to be enabled/disabled by properties. Events are called from the JavaScript code using the fire method.

Client Actions

Client actions are JavaScript methods that are called from the server side DataFlex code, You can pass parameters to the call but there are no return values.

Also client actions are not called immediately but are queued until the execution of the server code finishes. Once execution returns to the client side all client actions called during the call are executed in order.

This is an overview of the DataFlex WebApp control architecture. We will go into more detail in additional posts on this subject