Binding
_bind_path( ) hands you the model PATH of an attribute instead of {/PATH}: the piece a composed expression binding, a sorter or a bindElement needs.
Z2UI5_CL_SMP_APP_508
Learn
Binding
UI5 1.71
The facts
- Repository
- abap2UI5/samples
- Class
Z2UI5_CL_SMP_APP_508- Source file
z2ui5_cl_smp_app_508.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
Keywords: binding, path, only, bare, path, _bind_path, expression, binding, sorter, binding, info, composed, raw, string
Controls it builds
- sap.m.Input
- sap.m.Label
- sap.m.List
- sap.m.MessageStrip
- sap.m.ObjectStatus
- sap.m.Page
- sap.m.Shell
- sap.m.StandardListItem
- sap.m.Text
- sap.ui.core.mvc.View
- sap.ui.layout.form.SimpleForm
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_508.clas.abap — 118 lines
Click a number to link to a line — shift-click for a range.
Read it on GitHub ↗
" @keywords binding path only bare path _bind_path expression binding sorter binding info composed raw string
" @summary _bind_path( ) hands you the model PATH of an attribute instead of {/PATH}: the piece a composed expression binding, a sorter or a bindElement needs.
"! `client->_bind( quantity )` returns `{/QUANTITY}` - a complete property
"! binding, ready for a view attribute. Some attributes need the PATH alone:
"! an expression that combines it with a comparison, a binding-info object
"! that adds a sorter or a formatter, a bindElement. `client->_bind_path(
"! quantity )` returns `/QUANTITY` for exactly that - byte for byte what
"! `_bind( val = quantity path = abap_true )` returns, under a name that
"! says what it does. It registers the attribute like every bind: a path
"! the view names must be in the model, or the client renders nothing.
CLASS z2ui5_cl_smp_app_508 DEFINITION PUBLIC.
PUBLIC SECTION.
INTERFACES z2ui5_if_app.
TYPES:
BEGIN OF ty_s_row,
product TYPE string,
stock TYPE i,
END OF ty_s_row.
DATA t_row TYPE STANDARD TABLE OF ty_s_row WITH EMPTY KEY.
DATA quantity TYPE i.
PROTECTED SECTION.
DATA client TYPE REF TO z2ui5_if_client.
METHODS view_display.
PRIVATE SECTION.
ENDCLASS.
CLASS z2ui5_cl_smp_app_508 IMPLEMENTATION.
METHOD z2ui5_if_app~main.
me->client = client.
IF client->check_on_init( ).
quantity = 120.
t_row = VALUE #( ( product = `Monitor 27"` stock = 5 )
( product = `Headset` stock = 9 )
( product = `Keyboard` stock = 71 )
( product = `Notebook 15"` stock = 12 ) ).
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 - Path Only (_bind_path)`
)->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 = `_bind( ) returns the finished binding string; _bind_path( ) returns the bare path for the ` &&
`places that compose their own binding string: the expression that colours the status ` &&
`below, and the items binding of the list, which adds a sorter to the path. Change the ` &&
`quantity and press Enter to see the expression re-evaluate on the client.`
)->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 = `One attribute, two spellings`
)->a( n = `editable` b = abap_true
)->ele( n = `content` ns = `form` ).
form->tag( `Label`
)->a( n = `text` v = `quantity, bound with _bind( ) - the full binding` ).
form->tag( `Input`
)->a( n = `value` v = client->_bind( quantity )
)->a( n = `description` t = client->_bind( quantity ) ).
" the bare path inside an expression binding: the string is composed in
" ABAP, and the path in it comes from _bind_path( ) rather than being
" written by hand - a hand-written path is not in the model
form->tag( `Label`
)->a( n = `text` v = `the same attribute inside an expression - needs the bare path` ).
form->tag( `ObjectStatus`
)->a( n = `text` v = |\{= $\{{ client->_bind_path( quantity ) }\} > 100 ? 'more than 100 in stock' : 'running low' \}|
)->a( n = `state` v = |\{= $\{{ client->_bind_path( quantity ) }\} > 100 ? 'Success' : 'Warning' \}| ).
form->tag( `Text`
)->a( n = `text` t = |_bind_path( quantity ) returned { client->_bind_path( quantity ) }| ).
" the bare path of a table inside a binding-info object: the sorter is
" client-side, the path still names a bound attribute
form->tag( `Label`
)->a( n = `text` v = `a table path with a sorter added - needs the bare path` ).
form->ele( `List`
)->a( n = `items` v = |\{ path: '{ client->_bind_path( t_row ) }', sorter: \{ path: 'PRODUCT' \}, templateShareable: false \}|
)->tag( `StandardListItem`
)->a( n = `title` v = `{PRODUCT}`
)->a( n = `info` v = `{STOCK} in stock` ).
form->tag( `Text`
)->a( n = `text` t = |_bind_path( t_row ) returned { client->_bind_path( t_row ) } - the list is sorted by product on the client| ).
client->view_display( view->stringify( ) ).
ENDMETHOD.
ENDCLASS.
More in Binding
- Binding — A View Built From RTTI, No Field Named
- Binding — Currency Amounts (sap.ui.model.type.Currency)
- Binding — Dynamic Table Typed at Runtime (RTTI)
- Binding — Expression Binding, Types and Composite Parts
- Binding — Model setSizeLimit for Large Tables (A)
- Binding — Omit Initial Values
- Binding — Pre-serialized JSON (json)
- Binding — Single Table Cell (tab_index)
- Binding — Structure Fields and INCLUDEs
- Binding — Types for Integer, Decimal, Date and Time
On this page