Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Introduction

This How to Guide deals with the following topics:

  • Being able use SICF handler classes which also have access to BSP controller classes
  • Not having to create a new SICF service, each time there is demand for bypassing the BSP hierarchy

Generic crm_callback Service and its Methods

A new generic SICF service "crm_callback" was created.

To access this service, one can create a URL which points to that service and add two parameters, one including the name of one's custom handler class and one including the controller id. The latter is optional.

For convenience the method CL_CRM_WEB_UTILITY=>CREATE_SERVICE_URL has been created, which passes back a URL which

  • points to our generic service with the controller id and the handler class
  • is in the same session (something which has to be insured if one wants to access a BSP controller)

The method has the following important parameters:

  • IV_HANDLER_CLASS_NAME Name of handler class
  • IV_CONTROLLER_ID Controller ID
  • IV_QUERY Additional parameters you want to pass to the backend

For further convenience CL_CRM_WEB_UTILITY=> CREATE_SERVICE_SCRIPT goes a step further and passes back a JS snippet which if invoked creates an AJAX request (using the thtmlb AJAX library) to the generic service, so it immediately carries out the request to the backend after invoking. Apart from the parameters of the CREATE_SERVICE_URL it has the additional optional important parameter IV_JS_CALLBACK_FUNCTION name of a JS function that is called when the response is retrieved by the AJAX object

The Handler Class

You can define your own handler class. All it requires is that interface IF_CRM_WEB_CALLBACK Is implemented. This interface comes with one method: HANDLE_REQUEST HANDLE_REQUEST gets the server object (IR_SERVER) passed, thus one has access to the request and response object just like one has in an SICF service handler. On top of this though, it also gets the instance of the controller (IR_CONTROLLER) which belongs to the controller id specified in the URL.

Examples

Handler Class:

  

 

METHOD IF_CRM_WEB_CALLBACK~HANDLE_REQUEST.
 
  DATA: LR_CONTROLLER TYPE REF TO CL_BSP_WD_VIEW_CONTROLLER.
  DATA: LV_XML        TYPE BSP_DLC_XML.
 
  LR_CONTROLLER ?= IR_CONTROLLER.
 
* -> get the configuration of the current controller
  IF LR_CONTROLLER IS BOUND AND LR_CONTROLLER->CONFIGURATION_DESCR IS BOUND.
    LV_XML = LR_CONTROLLER->CONFIGURATION_DESCR->GET_CONFIG_DATA( ).
    IR_SERVER->RESPONSE->SET_CDATA( LV_XML ).
    IR_SERVER->RESPONSE->SET_HEADER_FIELD( NAME  = 'content-type'
                                           VALUE = 'text/xml' ).
  ENDIF.
 
ENDMETHOD.

 

Create a Script on a view that points to the view's controller and attach this script to a button:

 
<%
data: lv_script       type string.
data: lv_page_context type ref to cl_bsp_page_context.
 
* -> create script for service call back
lv_page_context ?= me->_m_page_context.
lv_script = cl_crm_web_utility=>CREATE_SERVICE_SCRIPT(
    IV_HANDLER_CLASS_NAME   = 'CL_THTMLB_CALLBACK_DEMO'
    IV_CONTROLLER_ID        = lv_page_context->m_page_id
  ).
%>
 
<thtmlb:button
  id           = "servicebut"
  text         = "call backend via service url"
  onClientClick= "<%= lv_script %>" />

 

Create a Script on a view that points to the view's controller and attach this script to a button + attach a callback JS function:

 
<%
data: lv_script       type string.
data: lv_page_context type ref to cl_bsp_page_context.
 
* -> create script for service call back
lv_page_context ?= me->_m_page_context.
lv_script = cl_crm_web_utility=>CREATE_SERVICE_SCRIPT(
    IV_HANDLER_CLASS_NAME   = 'CL_THTMLB_CALLBACK_DEMO'
    IV_CONTROLLER_ID        = lv_page_context->m_page_id
    IV_JS_CALLBACK_FUNCTION = 'thtmlbCompCallbackTest'
  ).
%>
 
<script>
  function thtmlbCompCallbackTest(reqObj) {
    var responseText = reqObj.request.responseText;
    alert(responseText);
  }
</script>
 
<thtmlb:button
  id           = "servicebut"
  text         = "call backend via service url"
  onClientClick= "<%= lv_script %>" />

 

Example of the whole process

In CRM_THTMLB_COMP/formConfig there is a new button underneath the form.

The view formConfig.htm includes the above coding. When one hits the button, an AJAX request is invoked and the SICF service is called. The service in turn calls demo handler class CL_THTMLB_CALLBACK_DEMO or rather its methods HANDLE_REQUEST. In this the configuration XML is retrieved from the BSP controller's config object and put into an HTTP response. This response is used by the demo response callback JS function thtmlbCompCallbackTest which just puts the XML of the response into an alerted message.