abap2UI5

Binding

Expression binding in the view - conditions, composite parts and a regular expression decide visible and enabled without asking the backend.

Z2UI5_CL_SMP_APP_027

Learn Binding UI5 1.71

The facts

Repository
abap2UI5/samples
Class
Z2UI5_CL_SMP_APP_027
Source file
z2ui5_cl_smp_app_027.clas.abap ↗
Category
Binding
Learning path
Get your data on screen
Minimum UI5
1.71 — the floor abap2UI5 holds its samples to
In the playground
runs in the browser, with no system and nothing installed
Documentation
abap2ui5.github.io/docs/cookbook/model/expression_binding ↗

Keywords: formatter, parts, conditional, regexp, visible, enabled, syntax

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

Run it here

The sample running, in this page — the app on its own, with no editor over it. Switch to Playground with this code

Nothing is installed and nothing is sent anywhere: the ABAP is compiled to JavaScript in this browser and runs against abap2UI5 itself.

The ABAP

z2ui5_cl_smp_app_027.clas.abap — 126 lines Read it on GitHub ↗
" @keywords formatter parts conditional regexp visible enabled syntax
" @summary Expression binding in the view - conditions, composite parts and a regular expression decide visible and enabled without asking the backend.
" @docs https://abap2ui5.github.io/docs/cookbook/model/expression_binding
CLASS z2ui5_cl_smp_app_027 DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

    DATA product  TYPE string.
    DATA quantity TYPE i.
    DATA input2   TYPE string.
    DATA input31  TYPE i.
    DATA input32  TYPE i.
    DATA input41  TYPE string.
    DATA input51  TYPE string.
    DATA input52  TYPE string.

  PROTECTED SECTION.
    DATA client TYPE REF TO z2ui5_if_client.

    METHODS view_display.

  PRIVATE SECTION.
ENDCLASS.


CLASS z2ui5_cl_smp_app_027 IMPLEMENTATION.


  METHOD z2ui5_if_app~main.

    me->client = client.
    IF client->check_on_init( ).

      product  = `tomato`.
      quantity = `500`.
      input41  = `faasdfdfsaVIp`.
      view_display( ).

    ELSEIF client->check_on_navigated( ).
      view_display( ).
    ENDIF.

  ENDMETHOD.


  METHOD view_display.

    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:form`   v = `sap.ui.layout.form` ).
    DATA(page) = view->ele( `Shell`
        )->ele( `Page`
            )->a( n = `title`          v = `abap2UI5 - Binding - Expression Binding, Types and Composite Parts`
            )->a( n = `showNavButton`  b = client->check_app_prev_stack( )
            )->a( n = `navButtonPress` v = client->_event_nav_app_leave( ) ).

    page->tag( `MessageStrip`
        )->a( n = `text`     v = `Advanced binding syntax: expression binding, typed bindings, conditional enabling ` &&
                   `with RegExp checks, and composite (parts) bindings.`
        )->a( n = `type`     v = `Information`
        )->a( n = `showIcon` b = abap_true
        )->a( n = `class`    v = `sapUiSmallMargin` ).

    DATA(form) = page->ele( n = `SimpleForm` ns = `form`
        )->a( n = `title`    v = `Binding Syntax`
        )->a( n = `editable` b = abap_true
        )->ele( n = `content` ns = `form` ).

    form->tag( `Title`
        )->a( n = `text` v = `Expression Binding`
        )->tag( `Label`
            )->a( n = `text` v = `Documentation`
        )->tag( `Link`
            )->a( n = `text`   v = `Expression Binding`
            )->a( n = `href`   v = `https://sdk.openui5.org/topic/daf6852a04b44d118963968a1239d2c0`
            )->a( n = `target` v = `_blank`
        )->tag( `Label`
            )->a( n = `text` v = `input in uppercase`
        )->tag( `Input`
            )->a( n = `value` v = client->_bind( input2 )
        )->tag( `Input`
            )->a( n = `enabled` b = abap_false
            )->a( n = `value`   v = |\{= ${ client->_bind( input2 ) }.toUpperCase() \}|
        )->tag( `Label`
            )->a( n = `text` v = `max value of the first two inputs`
        )->tag( `Input`
            )->a( n = `value` v = |\{ type : "sap.ui.model.type.Integer", path:"{ client->_bind( val = input31 path = abap_true ) }" \}|
        )->tag( `Input`
            )->a( n = `value` v = |\{ type : "sap.ui.model.type.Integer", path:"{ client->_bind( val = input32 path = abap_true ) }" \}|
        )->tag( `Input`
            )->a( n = `enabled` b = abap_false
            )->a( n = `value`   v = |\{= Math.max(${ client->_bind( input31 ) }, ${ client->_bind( input32 ) }) \}|
        )->tag( `Label`
            )->a( n = `text` v = `only enabled when the quantity equals 500`
        )->tag( `Input`
            )->a( n = `value` v = |\{ type : "sap.ui.model.type.Integer", path:"{ client->_bind( val = quantity path = abap_true ) }" \}|
        )->tag( `Input`
            )->a( n = `enabled` v = |\{= 500===${ client->_bind( quantity ) } \}|
            )->a( n = `value`   v = client->_bind( product )
        )->tag( `Label`
            )->a( n = `text` v = `RegExp Set to enabled if the input contains VIP, ignoring the case.`
        )->tag( `Input`
            )->a( n = `value` v = client->_bind( input41 )
        )->tag( `Button`
            )->a( n = `text`    v = `VIP`
            )->a( n = `enabled` v = |\{= RegExp('vip', 'i').test(${ client->_bind( input41 ) }) \}|
        )->tag( `Label`
            )->a( n = `text` v = `concatenate both inputs`
        )->tag( `Input`
            )->a( n = `value` v = client->_bind( input51 )
        )->tag( `Input`
            )->a( n = `value` v = client->_bind( input52 )
        )->tag( `Input`
            )->a( n = `enabled` b = abap_false
            )->a( n = `value`   v = |\{ parts: [ "{ client->_bind( val = input51 path = abap_true ) }", | &&
                                    |"{ client->_bind( val = input52 path = abap_true ) }" ] \}| ).

    client->view_display( view->stringify( ) ).

  ENDMETHOD.
ENDCLASS.

More in Binding

Search every abap2UI5 sample · the full list on one page

On this page