Skip to Content
Author's profile photo Brian McKellar

BSP Programming: Handling HTMLB Events

In the past few weeks in SDN, there have been a number of questions on handling HTMLB events. One of the biggest frustrations was with our

examples. This is a typical example:

<!code>  DATA: evt TYPE REF TO if_htmlb_data.

<!code>  evt = cl_htmlb_manager=>get_event_ex( request ).

<!code>  IF evt IS NOT INITIAL AND evt->event_name = ‘button’ AND evt->event_type = ‘click’.

<!code>    …

<!code>  ENDIF.


The first questions were always: Where can you obtain a list of events that are available? What are these magic strings? What happens if we write

them in upper/lower case?

The second problem was that of event dispatching. For the very old HTMLB library, we supported an interface if_htmlb_event that could be

implemented by an event handler class. However, this work was never done for the XHTMLB or PHTMLB libraries. Then a few days ago, we saw an example of

this technique being actively used with the newer libraries. So definitely it was time to clean this up.

Last, there was the question in the forum about a technique to build an OO framework for the event handling. If we have a button with onClick =

“save”, we would actually like to have the event dispatching done directly onto a method called “save”. After fiddling a little with the code, this

suddenly becomes relatively easy.

In the last two weeks, we have reworked the entire event handling code of the HTMLB family of libraries to address these three points. All of these

improvements will be shipped in the next service pack (620SP43 & 640SP05) that should be available in September 2004. This weblog will give an

overview of the three different techniques on how to handle HTMLB events. It is based on the new work we did. Some parts of this work in older service

packs; but especially for the event dispatching, the above service packs are required.

Test Program

is used to show the current index. Only a small part of the layout

code is shown here. The

complete source code

is available.

<!code>  <xhtmlb:buttonGroup id = “btngrp” onClick = “TablePager”>

<!code>    <xhtmlb:buttonGroupItem key      = “prev_page”

<!code>                            text     = “Previous Page”

<!code>                            design   = “PREVIOUS”

<!code>                            disabled = “<%=vIndex_prev_disabled%>” />

<!code>    <xhtmlb:buttonGroupItem key      = “next_page”

<!code>                            text     = “Next Page”

<!code>                            design   = “NEXT”

<!code>                            disabled = “<%=vIndex_next_disabled%>” />

<!code>  </xhtmlb:buttonGroup>


The output for the complete test program is shown below. In this display, the first visible row is currently one, and thus the button to navigate

to the previous page is disabled.

!|height=0 width=545 height=270 |width=0 width=545 height=270 |src=|border=0 width=545 height=270 !

Approach One: Manually Handling All HTMLB Events

The first approach to HTMLB event handling is to retrieve the event, and then simply investigate what type of event it is. This type of coding is

usually done in the OnInputProcessing handler of BSP pages.

The incoming event is retrieved with the call cl_htmlb_manager=>get_event_ex. In all cases, only this new method must be used. The older

get_event method is obsolete and not supported for the XHTMLB and PHTMLB libraries. Note that this method can be called more than once, and will

always return the same event.

The get_event_ex method will return an event object that implements at least the if_htmlb_data interface. This interface has a number of

interesting parameters that can be examined to see what type of event has been received. See also “

BSP In-Depth: Using the HTMLB Event System

” for an in-depth discussion of the different event parameters.

<!code>  DATA: event TYPE REF TO if_htmlb_data.

<!code>  event = cl_htmlb_manager=>get_event_ex( request ).


<!code>  IF  event IS NOT INITIAL

<!code>  AND event->event_name = xhtmlb_events=>buttongroup

<!code>  AND event->event_type = xhtmlb_events=>buttongroup_click.

<!code>    CASE event->event_defined.

<!code>      WHEN ‘prev_page’.

<!code>        vindex = vindex – vsize.

<!code>        IF vindex < 1.

<!code>          vindex = 1.

<!code>        ENDIF.

<!code>      WHEN ‘next_page’.

<!code>        vindex = vindex + vsize.

<!code>        IF vindex >= LINES( sflight ).

<!code>          vindex = LINES( sflight ) – vsize + 1.

<!code>        ENDIF.

<!code>    ENDCASE.

<!code>  ENDIF.


This approach of event handling is very fast to program, especially on a BSP page. The disadvantage of this approach is that the code quickly

explodes once events for many controls must be handled.

Approach Two: Dispatching Events via IF_HTMLB_EVENTS Interface

The HTMLB rendering libraries also contain a technique to dispatch events to a handler class. For this, use the

cl_htmlb_manager=>dispatch_event_ex method. One of the parameters is a handler class that will accept the incoming event and process it. Typically,

this can be a separate developed class, a controller class, or even the application class.

In this example, we will use a handler class that has been developed separately. On the BSP page, in the OnInputProcessing method, the event

handling code now reduces to a few lines. All that is required is an instance of the handler class, and then the dispatcher is called.


<!code>  CREATE OBJECT handler.

<!code>  cl_htmlb_manager=>dispatch_event_ex( request       = request

<!code>                                       page_context  = page_context

<!code>                                       event_handler = handler ).


The benefit of this approach is that the event handling code is placed into a separate class, where the full strength of the workbench can be used.

It reduces clutter in BSP pages. In addition, if new controls are added, no further plumbing code is required on the BSP page. All events will be

dispatched by this one call.

The important question is how will the handler class know what events are available, and what parameters each event handling method must have. For

this, an interface if_htmlb_events is defined. This interface contains all the possible events that can be fired by the HTMLB library. Each method

contains the correct parameters with which it will be called. Similar interfaces exist: if_xhtmlb_events and if_phtmlb_events for the other two


!|height=0 width=402 height=238 |width=0 width=402 height=238 |src=|border=0 width=402 height=238 !</body>

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      Hi Brian,
      This weblog is really useful, I started implementing the same way you mentioned in approach three. However, I am stumped with a problem. How do I get access to my Model instance in the new class which handles all the data related processing.

      Thanks in advance

      Author's profile photo Brian McKellar
      Brian McKellar
      Blog Post Author
      Just have a new attribute in this handler class that points onto your model. Set the attribute when you construct the handler class.
      Author's profile photo Former Member
      Former Member
      Hi Brian,

      I am fairly new to BSP Technology (as would soon be evident!) and I find your Weblogs absolutely fantastic.

      I was trying things mentioned on this page. However, I could not find any class XHTMLB_EVENTS in the system. Am I missing something here?

      Thanks a lot!

      Author's profile photo Brian McKellar
      Brian McKellar
      Blog Post Author
      The class XHTMLB_EVENTS was only added in July 2004, and probably went out in 620SP44.
      Author's profile photo Sergio Ferrari
      Sergio Ferrari
      About the 3rd approach, could you please provide a short example related to MVC design pattern?
      I implemented the TABLEPAGER method (in the controller) but it doesn't work leaving to the old dear DO_HANDLE_EVENT method all the job.
      Should I implement the call to the method cl_htmlb_manager=>dispatch_event_ex in the DO_HANDLE_EVENT?
      If Yes, how can I address the page_context object?
      Thanks so much
      Author's profile photo Sergio Ferrari
      Sergio Ferrari
      I think I found the answer.
      It was quite easy...

      DATA:  o_page_context TYPE REF TO if_bsp_page_context.
      o_page_context = me->get_page_context( ).
      cl_htmlb_manager=>dispatch_event_ex( request = request page_context  = o_page_context event_handler = me ).
      Author's profile photo Sergio Ferrari
      Sergio Ferrari
      I like the 3rd approach of your weblog.
      I can dispatch the right method for most of TAGs in my applications (MVC based).
      I'm not able to manage events raised by phtmlb:containerTabStripItem.
      System tries to call a method called as the number of the selected tabstrip.
      So I should define methods called: 1, 2, 3 and so on....It is not a good way...
      Any idea?