Class: cWebObject

Properties  Events  Methods    Index of Classes

The Web Framework Web Object class

Hierarchy

cObject
---cWebObject
------cWebBaseUIObject
------cWebGeoLocation
------cWebMenuGroup
------cWebTimer
------cWebViewStack

Library: Web Application Class Library

Package: cWebObject.pkg

Description

In the DataFlex Web Framework a Web Object is an object that has a direct representation on the client.

Web Objects support Web Properties which are properties whose values are transferred to the client representation of the Web Object. If a Web Property changes then its new value is synchronized back to the server web object each time that client makes a server call.

Only objects that are based on cWebObject or a subclass of cWebObject support Web Properties.

All Web Framework controls, such as cWebButton, cWebForm, cWebCheckbox, etc, are subclasses of cWebObject. In addition cWebApp, cWebView and other container objects are also cWebObject subclasses.

All of your application's web objects must be declared as children of the global cWebApp object.

You can use cWebObject to create your own Web Properties for storing application specific data at the client.

Sample

Object oCounterView is a cWebView

    Object oMyObject is a cWebObject
        { WebProperty=True }
        Property Integer piCounter 0

        Procedure IncrementCounter
            Integer i
            WebGet piCounter to i
            WebSet piCounter to (i+1)
        End_Procedure
    End_Object

    Object oIncrementBtn is a cWebButton
        Set psCaption to "Increment"

        Procedure OnClick
            Send IncrementCounter to oMyObject
        End_Procedure
    End_Object

End_Object

The above example declares a view containing a cWebObject (oMyObject) and a button (oIncrementBtn). The cWebObject declares a new web property (piCounter) and a method that increments the web property by one (IncrementCounter). This will increment the web property value only for the client that is connected when IncrementCounter is called. This is what distinguishes a web property from a non-web property in a web application.

Finally, we have a button object. When the button is clicked at the client, the OnClick call is made to the server which will increment that client's copy of the piCounter web property.

This example could have been made simpler by declaring the piCounter web property directly inside the button object, since the cWebButton class is a subclass of cWebObject and thus supports web properties.

OnLoad Events

An important event for all web objects is the OnLoad event. Whenever a web view or web dialog is first loaded to a client (usually this is the first time it is to be shown), then OnLoad is sent to every web object in that view (or dialog).

You can augment OnLoad to manipulate a view's web initial web property values. The OnLoad event is special in several ways:
- It is sent unconditionally to every web object in the view (or dialog). Most web object events can be activated or deactivated by a Boolean web property, this is not the case for OnLoad.
- It is only sent once in the lifetime of each client session.
- It is the one time that you can use the Set (as opposed to the WebSet command) command to manipulate a web property for a particular client. The reason for this is because at the time of the OnLoad event, the web properties of the view being loaded have not yet been transferred to the client.

The global cWebObject and all of its child web objects that are not web views or dialogs (e.g. cWebCommandBar) also receive the OnLoad event when the web application itself is loaded to a client.

Object oUserView is a cWebView
    Set psCaption to "User Name"

    Procedure OnLoad
        String sUser
        Get psUserName of ghoWebSessionManager to sUser
        Set psCaption to sUser
    End_Procedure
End_Object

The above example declares a view where the psCaption web property is modified during OnLoad to match the user name of the currently logged in user stored in the session manager object. Note that the psCaption web property is manipulated using Set rather than WebSet. This is possible because the client has not yet created any web objects or web properties for this view.