SAP Help Allowing a user to input data within an SAP Model view controller (MVC) BSP









Retrieve value from input text field within a model view controller ( MVC) BSP

Below is the basic code for allowing users to input text onto a html page and retrieve what they have entered using HTMLB and MVC techniques.

Display input field and retrieve value entered

View Layout
------
This is the HTMLB code to display an input field. In this example it uses
ld_fieldid to store and display a value in the field, you will need to create
this within the attributes section of the view. 
            <htmlb:inputField id            = "fieldId"
                        invalid        = "true"
                        value          = "<%=ld_fieldid%>"
                        required       = "true"/>

DO_REQUEST method (within controller class)
-----------------
  DATA: data_input  TYPE REF TO cl_htmlb_inputfield,
        ld_fieldid  TYPE string.

  data_input ?= cl_htmlb_manager=>get_data(
                                      request = runtime->server->request
                                      name    = 'inputfield'
                                      id      = 'fieldId' ).
  IF data_input IS NOT INITIAL.
    ld_fieldid = data_input->value.
  ENDIF.




Display dropdown list field and retrieve value entered

Layout
------
The code below is HTMLB.
            <htmlb:dropdownListBox id = "myDropdownListDay"
                               tooltip  = "Quick info for myDropdownListBox">
              <htmlb:listBoxItem key = "<%=dropday%>" value = "<%=dropday%>"/>

              <% data: ld_index type i,
                       ld_datum type sy-datum.
                 ld_index = 0.
                 do.
                  ld_index = ld_index + 1.  %>
                  <htmlb:listBoxItem   key = "<%=ld_index%>"
                                       value = "<%=ld_index%>"/>
                  <% if ld_index = 31.
                   exit.
                  endif.
                 enddo. %>
           </htmlb:dropdownListBox>

DO_REQUEST method (within controller class)
-----------------
  DATA: data TYPE REF TO cl_htmlb_dropdownlistbox,
        ld_dropyear  TYPE string.

  data ?= cl_htmlb_manager=>get_data( request = runtime->server->request
                                      name    = 'dropdownlistbox'
                                      id      = 'mydropdownListDay' ).
  IF data IS NOT INITIAL.
    ld_dropday = data->selection.
  ENDIF.