Confirmations in Web Applications
Confirmations
In Windows applications, message boxes are used to handle the display of information and process confirmations. With a WebApp, this is more complicated because a confirmation requires client-server round trip requests and responses. The WebApp framework provides a standard method for handling this.
The ShowInfoBox message is used to display a message and title caption.
Send ShowInfoBox "Testing 1 2 3" "Test"
The ShowYesNo message is used to handle yes/no confirmations. It uses the lower-level ShowMessageBox, which can also be used to process other types of custom confirmations.
Both ShowYesNo and ShowMessageBox use the concept of a callback object and message. These are passed to the procedure and sent to the client. Upon completion, the client makes a server call, which will send a callback message to the callback object passing the results of the confirmation. Therefore, a confirmation must consist of code for creating the confirmation and a method handler to handle the response.
The following is an example where a client button click will call OnClick, which then performs a yes/no confirmation. This confirmation triggers a call to the ButtonCallback method that receives the response to the yes/no confirmation.
Object oChangeButton is a cWebButton
Set psCaption to "Click me"
{ WebProperty=Server }
Property Boolean pbAllowUpdate False
Procedure ButtonCallback Integer eConfirmMode
Boolean bAllowUpdate
WebGet pbAllowUpdate to bAllowUpdate
WebSet pbAllowUpdate to False
If (bAllowUpdate and eConfirmMode = cmYes) Begin
WebSet psCaption to (CurrentDateTime())
End
End_Procedure
// This tells the system that this method is allowed for this object
WebPublishProcedure ButtonCallback
Procedure OnClick
// Do confirmation and call this object's ButtonCallback message with the results
WebSet pbAllowUpdate to True
Send ShowYesNo (Self) (RefProc(ButtonCallback)) "Update this" "Question"
End_Procedure
End_Object
When callbacks are used, the callback must be an allowable callback for the callback object. This is accomplished by publishing the method, which is what the WebPublishProcedure command does here. This is done to ensure that only known methods are processed on the server.
Publishing the callback also means that the client can call that method. If the callback is only valid after a server-side condition has been met, always re-check that condition inside the callback before performing the action. In the example above, pbAllowUpdate is a Server Web Property, so its value is kept on the server and can be used by ButtonCallback to verify that the update is currently allowed.
Note that this confirmation is already built into the data entry framework and save (Verify_Save_Msg), delete (Verify_Delete_Msg), and data-loss (Verify_Data_Loss_Msg) confirmations are set to an appropriate confirmation method. By default, those confirmations are enabled and they call the built-in SaveConfirmation, DeleteConfirmation, and DataLossConfirmation methods.
Previous Topic: Creating and Maintaining a Web Application
Next Topic: Web Properties