Image error handling with IllustratedMessage
Handle errors using the sap.m.IllustratedMessage with the error event.
Z2UI5_CL_SMPC_APP_279
Controls
sap.m
UI5 1.98
The facts
- Repository
- abap2UI5/samples-controls
- Class
Z2UI5_CL_SMPC_APP_279- Source file
z2ui5_cl_smpc_app_279.clas.abap↗- Library
- sap.m
- UI5 entity
sap.m.Image- Demo kit sample
sap.m.sample.ImageErrorWithIllustration- SAP's own sample
- running at sdk.openui5.org ↗
- Minimum UI5
- 1.98
- In the playground
- runs in the browser, with no system and nothing installed
Keywords: image, sap.m, imageerrorwithillustration, verticallayout, grid, vbox, button, flexitemdata, illustratedmessage
Controls it builds
- sap.m.Button
- sap.m.FlexItemData
- sap.m.IllustratedMessage
- sap.m.Image
- sap.m.VBox
- sap.ui.core.mvc.View
- sap.ui.layout.Grid
- sap.ui.layout.VerticalLayout
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_smpc_app_279.clas.abap — 121 lines
Click a number to link to a line — shift-click for a range.
Read it on GitHub ↗
" @keywords image sap.m imageerrorwithillustration verticallayout grid vbox button flexitemdata illustratedmessage
" @summary Handle errors using the sap.m.IllustratedMessage with the error event.
CLASS z2ui5_cl_smpc_app_279 DEFINITION PUBLIC.
PUBLIC SECTION.
INTERFACES z2ui5_if_app.
DATA has_error TYPE abap_bool.
DATA image_src TYPE string.
PROTECTED SECTION.
DATA client TYPE REF TO z2ui5_if_client.
METHODS view_display.
METHODS on_event.
METHODS model_init.
PRIVATE SECTION.
ENDCLASS.
CLASS z2ui5_cl_smpc_app_279 IMPLEMENTATION.
METHOD z2ui5_if_app~main.
me->client = client.
IF client->check_on_init( ).
model_init( ).
view_display( ).
ELSEIF client->check_on_navigated( ).
view_display( ).
ELSEIF client->check_on_event( ).
on_event( ).
ENDIF.
ENDMETHOD.
METHOD view_display.
DATA(view) = z2ui5_cl_ui5_view_builder=>factory( ).
view->ele( n = `View` ns = `mvc`
)->a( n = `xmlns` v = `sap.m`
)->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
)->a( n = `xmlns:l` v = `sap.ui.layout`
)->ele( n = `VerticalLayout` ns = `l`
)->a( n = `class` v = `sapUiContentPadding`
)->a( n = `width` v = `100%`
)->ele( n = `content` ns = `l`
)->ele( n = `Grid` ns = `l`
)->a( n = `defaultSpan` v = `XL3 L3 M6 S12`
)->ele( n = `content` ns = `l`
)->ele( `VBox`
)->a( n = `alignItems` v = `Center`
)->tag( `Button`
)->a( n = `text` v = `Set wrong src`
)->a( n = `press` v = client->_event( `SET_SRC` )
)->ele( `Image`
)->a( n = `load` v = client->_event( `LOAD` )
)->a( n = `error` v = client->_event( `ERROR` )
)->a( n = `visible` v = |\{= !${ client->_bind( has_error ) } \}|
)->a( n = `src` v = client->_bind( image_src )
" the controller's phone branch stays a branch: the device model
" decides the size in the frontend, the original resolved it once at onInit
)->a( n = `height` v = |\{= $\{device>/system/phone\} ? '5em' : '10em' \}|
)->a( n = `width` v = |\{= $\{device>/system/phone\} ? '5em' : '10em' \}|
)->ele( `layoutData`
)->tag( `FlexItemData`
)->a( n = `growFactor` v = `1`
)->end(
)->end(
)->tag( `IllustratedMessage`
)->a( n = `description` v = `Image was not found`
)->a( n = `title` v = `Not Found`
)->a( n = `illustrationType` v = `sapIllus-ErrorScreen`
)->a( n = `visible` v = |\{= ${ client->_bind( has_error ) } \}| ).
client->view_display( view->stringify( ) ).
ENDMETHOD.
METHOD on_event.
CASE client->get_event( ).
WHEN `LOAD`.
has_error = abap_false.
WHEN `ERROR`.
has_error = abap_true.
WHEN `SET_SRC`.
" original: the img> model's /products/pic1 is overwritten with a dead url
image_src = `/some/random/url`.
ENDCASE.
ENDMETHOD.
METHOD model_init.
" img>/products/pic1 of sap/ui/demo/mock/img.json, absolutized to the OpenUI5 host
image_src = `https://sdk.openui5.org/test-resources/sap/ui/documentation/sdk/images/HT-7777-large.jpg`.
ENDMETHOD.
ENDCLASS.
More in sap.m
- Message Dialog — Creating a dialog for showing UI messages. The possible messages types are: 'None', 'Succ…
- Dialog - Fullscreen — A dialog that can be toggled to fullscreen mode through a header button, by double-clicki…
- Tile Statuses — Shows the GenericTile while it is loading, if loading fails, and in disabled status.
- List - Growing — The Growing feature helps if your content is too big to be loaded/shown at once. It pagin…
- Table - ContextualWidth (Dynamic) — This example shows the container-based pop-in behavior. The container has dynamic width.
- Message Box — MessageBox is an easy way of displaying a message-type dialog to the user. You can displa…
- TextArea - Value Update — Since 1.30 the value property of sap.m.TextArea is not updated on every keystroke, but fi…
- MultiComboBox - showSelectAll functionality — MultiComboBox with enabled Select All feature inside suggestions.
- Message View inside Dialog — A sample with Message View placed inside a Dialog.
- Popover in Custom Within Area — Within area of sap.ui.core.Popup determines where all popups (including popovers) are pos…
- Breadcrumbs sample with current page link — Breadcrumbs sample with current page set as aggregation, resulting in a link
- Icon Tab Bar - Badges — This sample illustrates the possibility to add badges to the icon tab filters.
On this page