Entering content frame

Procedure documentation Defining Event Handlers for the First Page Locate the document in its SAP Library structure

Use

Now that you have specified the events in the layout that are executed when the user chooses certain buttons, you need to define the event handlers.

In this example you simply need the event handler for processing OnInputProcessing.

Event CLICK is triggered if the user clicks on a pushbutton. You can use the corresponding onClick event handler to execute a predefined task. You can dynamically activate or deactivate the CLICK event with the attribute disabled. If a pushbutton is deactivated, it no longer reacts to the user’s actions.

Event Handling with HTMLB Element button

A BSP element can have many events. BSP element button has only two event handlers, onClick and onClientClick. In the example, only onClick is used.

You usually realize your user interface elements with a <form> element in the layout of your BSP, which refers back to the same page. This is the same here. In the default case, you create the coding for event handling in the OnInputProcessing section. Within the OnInputProcessing event handler, the event ID variable can recognize and evaluate events from the HTMLB BSP extension. For all HTMLB events, this variable has the value CL_HTMLB_MANAGER=>event_id. The events are usually handled according to this framework:

IF event_id = CL_HTMLB_MANAGER=>EVENT_ID.
… handle HTMLB event…
ENDIF.

You can implement event handling for HTMLB events in two ways: The first technique involves retrieving event data and then processing this data (usually in a large case statement). The alternative is to "fire" the event at a user-instantiated event class.

In this case the HTMLB manager is called in order to obtain a reference to a generic event object of type CL_HTMLB_EVENT. You can use attributes name and event_type on this event object to determine which type of event is available. If the element supports attribute id, you can use attribute id to find out which element the event triggered. To receive detailed event data, you map the event object to an event object of suitable type, in this case a button event. You can find additional information about the button event in class CL_HTMLB_EVENT_BUTTON.

DATA: event TYPE REF TO CL_HTMLB_EVENT.
event = CL_HTMLB_MANAGER=>get_event( runtime->server->request ).
IF event->name = 'button' AND event->event_type = 'click'.
DATA: button_event TYPE REF TO CL_HTMLB_EVENT_BUTTON.
button_event ?= event.
  ENDIF.

Note

Note that for BSP element button and the onClick events, the event class is CL_HTMLB_EVENT_BUTTON.

Interface IF_HTMLB_EVENT is available for event handling. This interface contains methods for all of the BSP elements that are used in BSP extension HTMLB and which use events.

The event can be fired at a user-instantiated event handler class. In this example, the event handling class can be any user-defined class, provided that it implements interface IF_HTMLB_EVENT and is already instantiated. You can usually use the application class, for example, for handling specific events. The only requirement is that the application class implements interface IF_HTMLB_EVENT.

In the following example, a separate class called CL_HTMLB_EVENT_EXAMPLE is used for event handling:

DATA: event_handler TYPE REF TO CL_HTMLB_EVENT_EXAMPLE.
CREATE OBJECT event_handler.
CL_HTMLB_MANAGER=>dispatch_event(
request = runtime->server->request
event_handler = event_handler
page_context = page_context
).

The button element fires event IF_HTMLB_EVENT~BUTTON_CLICK that also contains the additional parameter id.

The onClick attribute is available for all triggered events. This is the name assigned by the user for the event handler method.

Caution

All BUTTON click events are fired by this one method for all of the buttons on the page. As a developer, ensure that you choose the correct ID to decide which button was triggered.

See also:

Defining the Event Handler for the Entry Page of the Second Tutorial

Procedure

  1. Choose the tab page Event Handler for the first page.
  2. In the pulldown menu, choose OnInputProcessing.
  3. Specify the processing procedure that will be carried out as a result of the end user’s actions:
  4. CLASS CL_HTMLB_MANAGER DEFINITION LOAD.

    * Optional: test that this is an event from HTMLB library.
    IF event_id = CL_HTMLB_MANAGER=>EVENT_ID.

    * See if upload is triggered from button
      DATA: event TYPE REF TO CL_HTMLB_EVENT.
      event = CL_HTMLB_MANAGER=>get_event( runtime->server->request ).
      IF event->name = 'button' AND event->event_type = 'click'.
        DATA: button_event TYPE REF TO CL_HTMLB_EVENT_BUTTON.
        button_event ?= event.
      ENDIF.

      CASE event->id.

        WHEN 'search'.

          DATA: lname TYPE REF TO CL_HTMLB_INPUTFIELD.
          DATA: fname TYPE REF TO CL_HTMLB_INPUTFIELD.

          lname ?= CL_HTMLB_MANAGER=>GET_DATA(
                              request = runtime->server->request
                              name    = 'inputField'
                              id      = 'authorlname'
                                            ).
          IF lname IS NOT INITIAL.
            authorlname = lname->value.
          ENDIF.
          fname ?= CL_HTMLB_MANAGER=>GET_DATA(
                              request = runtime->server->request
                              name    = 'inputField'
                              id      = 'authorfname'
                                            ).
          IF fname IS NOT INITIAL.
            authorfname = fname->value.
          ENDIF.
          navigation->set_parameter( 'authorlname' ).
          navigation->set_parameter( 'authorfname' ).
          navigation->next_page( 'TORESULTS' ).

        WHEN 'authorlist'.
          navigation->next_page( 'TOAUTHORS' ).

        WHEN others.

      ENDCASE.

    ENDIF.

  5. Save your entries.

This graphic is explained in the accompanying textNow go on to the Layout for the List of Authors

Leaving content frame