Complex State & Back Button

Last Updated: 9/21/2008



Sections above here:
Home  »  Development  »  State Management

Sections below here:

    Topics in this section:
    State Management
    Storage For Delphi Applications
    Complex State & Back Button

    Search Documentation:

    Many people quickly discover that when building an IntraWeb application the back button in the browser does not work. By default IntraWeb disables the back button and pressing it has no effect. Please note first that this only applies to application mode. In page mode the back button is fully functional. This limitation is because of the way that IntraWeb allows and uses complex state.

    Scenario – Normal Application

    Imagine a normal application designed to run on the users local computer. It has five different forms, and for some of the forms multiple instances of that form may be created with different data (such as a properties dialog displaying properties about different objects). Imagine now that at any time, without warning or notice to you the programmer, the user can go to any form in the application. But not only can they go to just any form, they can go to any form, in any prior state, even to versions of the forms which have since been removed from memory. After they move to that form, they can even interact with it. How could such an application deal with this?

    Here are a few, but certainly not all of the problems:

    • Forms may rely on data in databases that no longer exists because the user deleted it.
    • Forms may rely on data that has since changed, and the user would be posting old and invalid data.
    • Objects that were in memory have changed, or no longer exist.

    Back Buttons in non IntraWeb Systems

    System not built in IntraWeb usually support back buttons. However it is because they fall into one of these categories:

    • Stateless – They are completely stateless and reconstruct state between each page. This is usually very inefficient on the server side for web applications and puts considerably extra load on databases because data is read and written unnecessarily.
    • State Streaming – These types stream the state into and out of each web page. This consumes bandwidth and slows down page accesses. They also cannot use complex data, or usage of complex data causes the same problems described prior.

    Even applications that support the back button, such problems are still encountered. However because they allow old data to be posted they must check the data to see if the requested operations can be performed. This adds significantly to the amount of user code except in the simplest of systems. Such systems are typically not web applications, but individual dynamic pages.

    IntraWeb is Not Alone

    If you try many online banking applications or ordering systems, many of them have the same restrictions, but do not behave as well. Most of them allow you to go back, but will tell you that you have requested expired content. That is certainly very user unfriendly and confusing to non technical people.

    Back Button for Historical Purposes

    Under limited circumstances the back button can be supported in application mode. It can be enabled for historical purposes. This means that the back button will be enabled, and the user can move backward. However if they try to interact with data on a page that they have reached using the back button they will fail. If the user tries to interact with such a page, a warning will be displayed:

    You have attempted to post or refresh data from a page that depends on information that is no longer available to the server application.

    Your attempted changes will be ignored. You will now be resynchronized to the current place in the application.

    After this warning is shown, the user will be shown the current form as it was before they used the back button. This functionality can be turned on by setting the .HistoryEnabled property to true in the server controller.

    This warning dialog can also be turned off. To do so set the .ShowResyncWarning property to false in the server controller. If false, instead of seeing the warning dialog the user will simply be resynchronized with the current form.

    Assigning the OnBackButton event 

    IntraWeb introduces a new event called OnBackButton. However, despite its name, it does NOT fire when the back button is pressed in the browser. This is due to the nature of the HTTP protocol and therefore the browser cannot send an event to the server to indicate that this has happened. On the other hand, what can be detected is when a form that has already been sent to the server is re-sent. This is where this event comes into play. 

    OnBackButton is fired when a form is re-submitted to the server. The event can therefore be used to detect what operation needs to take place if old data is re-sent. Assigning the event effects two properties: HistoryEnabled and ShowResyncWarning. When an event has been assigned, the first property is automatically set to True whereas the latter is set to False. 

    IntraWeb works in sequences. Each form that is submitted carries a sequence number with it. When the application is first started, the sequence (or track ID) is set to 0. Every time a form is submitted, this track ID is incremented by 1. Sequences play an important role in back button events.

    The signature for the event is:

    ASubmittedSequence, ACurrentSequence: Integer; AFormName: String; var VHandled, VExecute: Boolean

    • ASubmittedSequence: Represents the sequence that has been submitted. This will always be LOWER than the ACurrentSequence that represents the current sequence.
    • ACurrentSequence: Represents the current Track ID.
    • AFormName: Working with sequence numbers, although powerful can become cumbersome. Alternatively, you can use the AFormName parameter to see WHICH form has been re-submitted.
    • VHandled: When controlling a re-submitted form, you need to set the VHandled property to True, otherwise IntraWeb will understand that the event has not been handled and will display the default action which is to show the Re-sync message.
    • VExecute: When a form is re-created in the OnBackButton event, you can choose whether you want to execute it or generate it. By default VExecute is FALSE which means that the form will be generated.

     For more information and an Delphi example of using the OnBackButton take a look at the BackButton demo located in the application folder.



    (C) 2002-2009 - Atozed Software Ltd.