Show TOC

Step 1 b) Using <htmlb:SimpleFormItem>Locate this document in the navigation structure

Use

Element <sf:SimpleFormItem> has been implemented and can therefore be used. You must now ensure that each entry is rendered directly in the current output stream. If the <htmlb:gridLayout> is used later, a counter is required to count exactly the number of fields that are required so that the gridLayout and, of course, each individual cell can be configured correctly. This means that entries are first counted and then later rendered.

The best way to do this is if elements <htmlb:label> and <htmlb:inputField> are rendered immediately, although not in the output stream. Instead, these elements are rendered in separate writers, in which the content is stored and the entries are counted, and with which they are finally rendered.

To realize this, the entry must be changed so that it renders a string, and that this string is forwarded for rendering the <sf:SimpleForm> later.

A new method ADD_ITEM is added to element <sf:SimpleForm> with the two parameters label_html and inputField_html, which are both of type string.

Note

You can add additional methods to the BSP event handlers, which implement additional functionality, and which can in turn be used by "lesser" elements. The element handler classes are normal ABAP classes that can be processed in the Workbench.

The simple coding will be as follows:

method ADD_ITEM .

  DATA:  out TYPE REF TO IF_BSP_WRITER.
  out = me->GET_PREVIOUS_OUT( ).

  out->PRINT_STRING( '<tr><td>' ).      " <tr><td>
  out->PRINT_STRING( label_html ).      " <htmlb:Label/>
  out->PRINT_STRING( '</td><td>' ).     " </td><td>
  out->PRINT_STRING( inputField_html ). " <htmlb:inputField/>
  out->PRINT_STRING( '</td></tr>' ).    " </td></tr>

endmethod.


         

The only task for ADD_ITEM at the moment to render the string immediately.

In the next step, the coding is changed within <sf:SimpleFormItem>. For each internal element that is used, the element output must not be written to the current writer under any circumstance. As a result, this ensures that a new writer is pushed on the stack. Furthermore, all new elements will write to this new writer, and the context can be extracted from this new writer at any time.

The changed coding is then as follows:

method IF_BSP_ELEMENT~DO_AT_BEGINNING .

  DATA:   my_out          TYPE REF TO IF_BSP_WRITER,
          label_html      TYPE STRING,
          inputField_html TYPE STRING.

* Add own temporary writer on stack
my_out = m_page_context->PUSH_WRITER( ).

* <htmlb:Label/>
....
label_html = my_out->GET_CONTENT( ).
my_out->CLEAR( ).

* <htmlb:inputField/>
....
inputField_html = my_out->GET_CONTENT( ).
my_out->CLEAR( ).

* Remove my writer from stack
m_page_context->POP_WRITER( ).

* Copy Text to <sf:SimpleForm>
  DATA:  sf     TYPE REF TO CL_BSP_TUTCMPLX_SIMPLE_FORM.
  sf ?= me->GET_CLASS_NAMED_PARENT
( 'CL_BSP_TUTCMPLX_SIMPLE_FORM' ).
  sf->ADD_ITEM( label_html = label_html inputField_html = inputField_html ).

  rc = CO_ELEMENT_DONE.
endmethod.


         

Note the following points:

  • The use of PUSH_WRITER() at the beginning to add an additional writer to the stack.

    All new elements that are now processed write to the top writer on the stack. At the end of this method, the additional writer must be removed from the stack using method POP_WRITER().

  • The use of methods GET_CONTENT() to extract the current string to the output, and CLEAR() to ensure that the two elements are in separate strings.

  • The use of method GET_CLASS_NAMED_PARENT() to receive a reference to an element that is located "further up" in the element stack.

  • The call of method ADD_ITEM(), which represents a local method that is defined by the element.

You can now execute page after.htm again to ensure that it still runs correctly.

The element <sf:SimpleFormItem> is then complete. This section has described how BSP elements are processed on the stack. We have also described how the output of this type of element can be written to a string, so that it can be rendered later.

For more information, see Step 2: Creating <sf:SimpleForm>.