abap2UI5

SmartField in a SmartForm

needs the GWSAMPLE_BASIC OData service

Z2UI5_CL_SMPS_APP_475

Stack Smart Controls UI5 1.71 needs a system

needs a system. This sample is listed here because a sample somebody cannot find is worse than one they cannot run: SAPUI5 + an activated Gateway service. The ABAP is below; installed on a system that has what it needs, it runs there.

The facts

Repository
abap2UI5/samples-stack
Class
Z2UI5_CL_SMPS_APP_475
Source file
z2ui5_cl_smps_app_475.clas.abap
Category
Smart Controls
Minimum UI5
1.71 — the floor abap2UI5 holds its samples to
In the playground
needs a system — it opens for reading instead
Runs on
Cloud + Standard ≥ 7.40 SP08

Keywords: smartform, smartfield, group, groupelement, columnlayout, annotations

Controls it builds

Read out of the builder chain by the abap2UI5 linter, not from the category this sample is filed under — which is what makes “which samples build one of these” a question the catalogue can answer at all.

Libraries

The ABAP

z2ui5_cl_smps_app_475.clas.abap — 72 lines, on branch 02-smart-controls Read it on GitHub ↗
" @keywords smartform smartfield group groupelement columnlayout annotations
" @summary needs the GWSAMPLE_BASIC OData service
CLASS z2ui5_cl_smps_app_475 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

  PROTECTED SECTION.
    " Smart controls build their UI from OData V2 metadata, so this app carries no
    " ABAP data at all - it switches the default model to a service instead. The
    " SAP Gateway demo service GWSAMPLE_BASIC ships with every on-premise system
    " and only has to be activated once in /IWFND/MAINT_SERVICE. Its entity set is
    " ProductSet, which is why the tutorial's Products entity set is mapped onto it.
    CONSTANTS c_odata_service TYPE string VALUE `/sap/opu/odata/IWBEP/GWSAMPLE_BASIC/`.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smps_app_475 IMPLEMENTATION.

  METHOD z2ui5_if_app~main.

    IF client->check_on_navigated( ).

      DATA(view) = z2ui5_cl_ui5_view_builder=>factory(
          )->ele( n = `View` ns = `mvc`
              )->a( n = `displayBlock`     v = `true`
              )->a( n = `height`           v = `100%`
              )->a( n = `xmlns`            v = `sap.m`
              )->a( n = `xmlns:mvc`        v = `sap.ui.core.mvc`
              )->a( n = `xmlns:core`       v = `sap.ui.core`
              )->a( n = `xmlns:smartField` v = `sap.ui.comp.smartfield`
              )->a( n = `xmlns:smartForm`  v = `sap.ui.comp.smartform` ).

      DATA(page) = view->ele( `Shell`
          )->ele( `Page`
              )->a( n = `title`          v = `abap2UI5 - Smart Controls - SmartField`
              )->a( n = `showNavButton`  b = client->check_app_prev_stack( )
              )->a( n = `navButtonPress` v = client->_event_nav_app_leave( ) ).

      " The tutorial binds the view to a single product record in its controller
      " (bindElement( `/Products('4711')` )). There is no controller here, so the
      " element binding is declared on the SmartForm - the SmartField's relative
      " {Price} binding resolves against it. This is an OData ENTITY path into the
      " service, not a path into an ABAP-fed model, so there is no
      " client->_bind( ) variable to derive it from.
      DATA(form) = page->ele( n = `SmartForm` ns = `smartForm`
          )->a( n = `editable` v = `true`
          )->a( n = `binding`  v = `{/ProductSet('AR-FB-1000')}` ).

      form->ele( n = `layout` ns = `smartForm`
          )->ele( n = `ColumnLayout` ns = `smartForm`
              )->a( n = `emptyCellsLarge` v = `4`
              )->a( n = `labelCellsLarge` v = `4`
              )->a( n = `columnsM`        v = `1`
              )->a( n = `columnsL`        v = `1`
              )->a( n = `columnsXL`       v = `1` ).

      form->ele( n = `Group` ns = `smartForm`
          )->ele( n = `GroupElement` ns = `smartForm`
              )->ele( n = `SmartField` ns = `smartField`
                  )->a( n = `value` v = `{Price}`
                  )->a( n = `id`    v = `idPrice` ).

      client->view_display( val = view->stringify( ) switch_default_model_path = c_odata_service ).

    ENDIF.

  ENDMETHOD.

ENDCLASS.

More in Smart Controls

Search every abap2UI5 sample · the full list on one page

On this page