Step 4: Data Binding
So far the app only talks. Now the user answers: an input field replaces the text, and whatever is typed into it arrives in your class — without a single line of transfer code:
abap
CLASS zcl_app_walkthrough DEFINITION PUBLIC.
PUBLIC SECTION.
INTERFACES z2ui5_if_app.
DATA recipient TYPE string.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_app_walkthrough IMPLEMENTATION.
METHOD z2ui5_if_app~main.
IF client->check_on_navigated( ).
recipient = `World`.
DATA(view) = z2ui5_cl_ui5_view_builder=>factory(
)->ele( n = `View` ns = `mvc`
)->a( n = `xmlns` v = `sap.m`
)->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
)->ele( `Shell`
)->ele( `Page`
)->a( n = `title` v = `Walkthrough - Step 4`
)->tag( `Input`
)->a( n = `value` v = client->_bind( recipient )
)->tag( `Button`
)->a( n = `text` v = `Say Hello`
)->a( n = `press` v = client->_event( `SAY_HELLO` ) ).
client->view_display( view->stringify( ) ).
ELSEIF client->check_on_event( `SAY_HELLO` ).
client->message_toast_display( |Hello { recipient }!| ).
ENDIF.
ENDMETHOD.
ENDCLASS.You should see
An input field that holds World, and the Say Hello button. Type your name over it and press the button: the message reads Hello plus what you typed.
How the Value Travels
DATA recipient TYPE string— a public attribute is the model. After every roundtrip the framework saves the whole app instance on the server and restores it before the next one. That saved copy is the app draft, and it is why your class keeps its state without any session handling. Attributes you_bind( )must be in thePUBLIC SECTION— the framework reaches them dynamically, and a private or protected one fails the roundtrip withBINDING_ERROR. (Everything else may stay protected; it is serialized either way. Full rules on the Binding page.)client->_bind( recipient )connects the attribute to thevalueproperty of the input. When the button fires, the browser sends the current screen state along with the event — by the time yourELSEIFbranch runs,recipientalready holds what the user typed.- Type it, press the button — the toast greets whatever name is in the field. Both directions, and you wrote no transfer code.
Next, the same binding moves a whole internal table into a list.
Working Samples
Complete apps from the sample catalog that use what this page describes. Each is a single class in abap2UI5/samples unless its row names another of the three sample repositories — pull that repository with abapGit and start the class with ?app_start=<class>.
| Sample | Class |
|---|---|
| Basics II — Data Binding: Input and Button | Z2UI5_CL_SMP_APP_494 |
