BUI logoDWC logoBBjWebManager::setCallback

Description

In BBj 16.00 and higher, this method registers the callback routine for a specified BBjWebManager event.

In BBj 24.11 and higher, this method registers the callback routine for a specified window event. These event type codes are defined by the window interface.

Note:

In BBj 22.03 and higher, BBjWebManager is an alias for BBjBuiManager.

Syntax

Return Value Method
void setCallback(int eventType, CustomObject customObject, String methodName)
void setCallback(int eventType, String callback)
int setCallback(String eventType, String callback)
int setCallback(String eventType, String callback, BBjWebEventOptions options)
int setCallback(String eventType, CustomObject customObject, String methodName)
int setCallback(String eventType, CustomObject customObject, String methodName, BBjWebEventOptions options)

Parameters

Parameter Description
eventType Event type for which the callback is to be registered.
customObject A CustomObject containing the method to be called when the event is processed by PROCESS_EVENTS.
methodName

The name of the method that is to be called when the event is processed by PROCESS_EVENTS. The method must take a single BBjWebEvent parameter:

method public void onWebEvent(BBjWebEvent event!)
    rem ' handle a BBjWebEvent.
methodend
callback Subroutine name to be executed in PROCESS_EVENTS.
options An optional BBjWebEventOptions structure that specifies JavaScript code to execute inside the client-side event handler and a list of values to return from the event or window.

Return Value

This method returns the callback ID if the eventType argument is a String.

Remarks

Web Event callbacks can be registered for any string event code. Supported events are defined by the window interface. Internally, this maps to addEventListener.

The setCallback method will implicitly GOSUB to the subroutine specified in subroutineName. Since the block of code executed at callback is arrived at via an implicit GOSUB, a RETURN is required at the end of the subroutine.

The setCallback method will implicitly CALL a program at the specified label when the callback parameter includes "::" (e.g.: "EventHandlerProgram::label"). Since a CALL has been made to a public program, an ENTER may optionally be used at the beginning, and an EXIT is required at the end.

The setCallback method must be called before the PROCESS_EVENTS verb, or within a subroutine that is called in response to an event.

If the setCallback method specifies a non-null BBjWebEventOptions, multiple web event callbacks can be registered for a given eventType. If the setCallback method does not specify a BBjWebEventOptions options parameter, or if the parameter is null, only the last one registered is used, as in BBjControl::setCallback.

Example 1

rem ' BBjWebManager

declare BBjSysGui sysgui!
declare BBjWebManager bui!
declare BBjBusyIndicator busy!
sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
bui! = bbjapi().getWebManager()
bui!.setCallback(bui!.ON_BROWSER_BACK,"browser_back")
url$ = "(Not BUI)"
url$ = bui!.getUrl(err=*next)
appName$ = " (Not BUI)"
appName$ = bui!.getApplicationName(err=*next)
title$ = "BBjWebManager: " + appName$
touch = 0
touch = bui!.isTouchSupported(err=*next)
if touch then title$ = title$ + " (Touch)" else title$ = title$ + " (Not Touch)"
window! = sysgui!.addWindow(100,100,450,475,title$,$00090003$)
window!.setCallback(window!.ON_CLOSE,"eoj")
window!.addStaticText(99,25,25,400,25,"URL: "+url$,$$)
window!.addGroupBox(100,25,75,400,125,"End Actions")
endApp! = window!.addRadioButton(101,30,100,75,25,"App",$0020$)
endUrl! = window!.addRadioButton(102,105,100,75,25,"URL",$0020$)
endMsg! = window!.addRadioButton(103,180,100,75,25,"Msg",$0020$)
endNone! = window!.addRadioButton(104,255,100,75,25,"None",$0020$)
endDefault! = window!.addRadioButton(105,330,100,75,25,"Default",$0020$)
endGroup! = window!.addRadioGroup()
endGroup!.add(endApp!)
endGroup!.add(endUrl!)
endGroup!.add(endMsg!)
endGroup!.add(endNone!)
endGroup!.add(endDefault!)
window!.addStaticText(106,30,150,60,25,"Value:",$8000$)
endValue! = window!.addEditBox(107,100,150,225,25,$$)
setEndAction! = window!.addButton(108,340,150,75,25,"Set",$$)
setEndAction!.setCallback(setEndAction!.ON_BUTTON_PUSH,"setEndAction")
window!.addGroupBox(200,25,225,400,125,"Err Actions")
errApp! = window!.addRadioButton(201,30,250,75,25,"App",$0020$)
errUrl! = window!.addRadioButton(202,105,250,75,25,"URL",$0020$)
errMsg! = window!.addRadioButton(203,180,250,75,25,"Msg",$0020$)
errNone! = window!.addRadioButton(204,255,250,75,25,"None",$0020$)
errDefault! = window!.addRadioButton(205,330,250,75,25,"Default",$0020$)
errGroup! = window!.addRadioGroup()
errGroup!.add(errApp!)
errGroup!.add(errUrl!)
errGroup!.add(errMsg!)
errGroup!.add(errNone!)
errGroup!.add(errDefault!)
window!.addStaticText(206,30,300,60,25,"Value:",$8000$)
errValue! = window!.addEditBox(207,100,300,225,25,$$)
setErrAction! = window!.addButton(208,340,300,75,25,"Set",$$)
setErrAction!.setCallback(setEndAction!.ON_BUTTON_PUSH,"setErrAction")
title$ = "Show Confirm Close Dialog"
confirm = 0
confirm = bui!.getShowConfirmCloseDialog(err=*next)
flags$ = iff(confirm,$0004$,$0000$)
setShowConfirmDialog! = window!.addCheckBox(209,25,375,300,25,title$,flags$)
setShowConfirmDialog!.setCallback(setShowConfirmDialog!.ON_CHECK_ON,"showConfirmDialogOn")
setShowConfirmDialog!.setCallback(setShowConfirmDialog!.ON_CHECK_OFF,"showConfirmDialogOff")
showBusy! = window!.addButton(1,25,425,100,25,"Busy",$$)
showBusy!.setCallback(showBusy!.ON_BUTTON_PUSH,"showBusy")
busyMessage! = window!.addEditBox(300,150,425,200,25,"Working...",$$)
gosub fetch
process_events

eoj:
release

fetch:
    endAction! = bui!.getEndAction(err=*return)
    switch endAction!.getActionType()
        case endAction!.ACTION_APP
            endApp!.setSelected(1)
            endValue!.setText(endAction!.getAppName())
            break
        case endAction!.ACTION_URL
            endUrl!.setSelected(1)
            endValue!.setText(endAction!.getUrl())
            break
        case endAction!.ACTION_MSG
            endMsg!.setSelected(1)
            endValue!.setText(endAction!.getMessage())
            break
        case endAction!.ACTION_NONE
            endNone!.setSelected(1)
            endValue!.setText("")
            break
        case endAction!.ACTION_DEFAULT
            endDefault!.setSelected(1)
            endValue!.setText("")
            break
    swend
    errAction! = bui!.getErrAction(err=*return)
    switch errAction!.getActionType()
        case errAction!.ACTION_APP
            errApp!.setSelected(1)
            errValue!.setText(errAction!.getAppName())
            break
        case errAction!.ACTION_URL
            errUrl!.setSelected(1)
            errValue!.setText(errAction!.getUrl())
            break
        case errAction!.ACTION_MSG
            errMsg!.setSelected(1)
            errValue!.setText(errAction!.getMessage())
            break
        case errAction!.ACTION_NONE
            errNone!.setSelected(1)
            errValue!.setText("")
            break
        case errAction!.ACTION_DEFAULT
            errDefault!.setSelected(1)
            errValue!.setText("")
            break
    swend
return

setEndAction:
    if endApp!.isSelected() then action! = bui!.appAction(endValue!.getText())
    if endUrl!.isSelected() then action! = bui!.urlAction(endValue!.getText())
    if endMsg!.isSelected() then action! = bui!.msgAction(endValue!.getText())
    if endNone!.isSelected() then action! = bui!.noneAction()
    if endDefault!.isSelected() then action! = bui!.defaultAction()
    bui!.setEndAction(action!,err=*return)
return

setErrAction:
    if errApp!.isSelected() then action! = bui!.appAction(errValue!.getText())
    if errUrl!.isSelected() then action! = bui!.urlAction(errValue!.getText())
    if errMsg!.isSelected() then action! = bui!.msgAction(errValue!.getText())
    if errNone!.isSelected() then action! = bui!.noneAction()
    if errDefault!.isSelected() then action! = bui!.defaultAction()
    bui!.setErrAction(action!,err=*return)
return

showConfirmDialogOn:
    bui!.setShowConfirmCloseDialog(1,err=*next)
return

showConfirmDialogOff:
    bui!.setShowConfirmCloseDialog(0,err=*next)
return

showBusy:
    busy! = bui!.getBusyIndicator(err=*return)
    busy!.setText(busyMessage!.getText())
    busy!.setVisible(1)
    wait 3
    busy!.setVisible(0)
return

browser_back:
    event! = sysgui!.getLastEvent()
    i = msgbox(str(event!))
return

Example 2

rem ' BBjWebManager WebEvents

sysgui = unt
open (sysgui)"X0"
title$ = "BBjWebManager WebEvents"
sysgui! = bbjapi().getSysGui()
window! = sysgui!.addWindow(25,25,800,100,title$,$00090083$)
window!.setCallback(window!.ON_CLOSE,"eoj")
status! = window!.addStatusBar(99)
status!.setText("Resize browser to see WebEvents")

web! = bbjapi().getWebManager(err=oops)
web!.setCallback(web!.ON_BROWSER_CLOSE,"eoj",err=oops)

options! = web!.newEventOptions()
options!.addItem("innerWidth","event.target.innerWidth")
options!.addItem("innerHeight","event.target.innerHeight")
options!.addItem("outerWidth","event.target.outerWidth")
options!.addItem("outerHeight","event.target.outerHeight")
web!.setCallback("resize","webevent",options!)

web!.setCallback("focus","webevent")
web!.setCallback("blur","webevent")

process_events

oops:
  i = msgbox(errmes(-1))
eoj:
  release

webevent:
  event! = sysgui!.getLastEvent()
  eventMap$ = event!.getJsonString()
  eventMap$ = ""
  map! = event!.getEventMap()
  iterator! = map!.keySet().iterator()
  while iterator!.hasNext()
    key$ = iterator!.next()
    value! = map!.get(key$)
    value$ = String.valueOf(value!)
    eventMap$ = eventMap$ + key$ + "=" + value$ + " "
  wend
  msg$ = date(0:"%Hz:%mz:%sz.%tz ")+event!.getEventName()
  msg$ = msg$ + " " + event!.getEventType()
  msg$ = msg$ + " " + eventMap$ 
  status!.setText(msg$)
return

ClosedVersion History

  • BBj 24.11: Added ways to register the callback routine for a specified window event.
  • BBj 22.03: BBjWebManager became an alias for BBjBuiManager.
  • BBj 16.00: BBjBuiManager::setCallback added.

See Also

BBjAPI

Object Variables

BBjWebManager::clearCallback

PROCESS_EVENTS Verb

BBj Custom Objects Tutorial

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.