Feed the label with data from an OData stream.
So far you have assigned a static text to the label. This task feeds the label with data coming from an OData stream, fetched via the Internet from a server.
This example uses the LeaveRequest endpoint:
http://vmw3815.wdf.sap.corp:50009/sap/opu/sdata/GBHCM/LEAVEREQUEST/
<?xml version="1.0" encoding="UTF-8"?> <MAF xmlns="http://schemas.sap.com/maf/2012/cfg"> <Binding bindingId="Approvers" type="collection"> <P pid="boType" value="ApproverCollection"></P> </Binding> <!-- Define a "tile" - it translates to UIViewController --> <Tile tileId="First Extensible Screen"> …This example displays the approver name from the OData entry identified by the ApproverEmployeeName property, which is part of the ApproverCollection collection. Next, add the binding reference to the tile:
<!-- Define a "tile" - it translates to UIViewController --> <Tile tileId="First Extensible Screen"> <!-- This is our root view --> <P pid="isRoot" value="true" /> <!-- Reference to the data binding which provides data for this tile --> <BindingRef ref="Approvers"/>Defining a new label is similar to the previous one, but the label's text is fed with data coming from the binding:
<!-- Define 2nd label --> <UIElement type="label"> <!-- The label text is showing real data coming from the OData feed --> <P pid="text" value="Approved By: {$Approvers.ApproverEmployeeName}"></P> <P pid="halign" value="center"></P> <P pid="margin_top" value="20pt"></P> <P pid="style" value="CustomLabel"></P> </UIElement>
The {$Approvers.ApproverEmployeeName} syntax refers to the employee name. Curly brackets indicate that the content must be evaluated by the Extensibility Framework. The $ sign denotes a binding (or expression), followed by the collection and the entry name separated by a period.
new Thread(new Runnable() { @Override public void run() { try { SDMSource source = null; SDMConnectivityParameters connectivityParameters = new SDMConnectivityParameters(); connectivityParameters.setBaseUrl(BACKEND_BASE_URL_FOR_DIRECT_CONNECTION); connectivityParameters.setUserName(USER_NAME_FOR_DIRECT_CONNECTION); connectivityParameters.setUserPassword(PASSWORD_FOR_DIRECT_CONNECTION); synchronized (SDMSource.class) { source = new SDMSource(MainActivity.this.getApplicationContext(), connectivityParameters, "com.sap.mobile.lib.sdmconnectivity.SocketConnectionHandler"); source.loadModel(); } MAFDataSourceAdapter dataSourceAdapter = new MAFSDMDataSourceAdapter(source); mafCore.setDataSourceAdapter(dataSourceAdapter); } catch (Exception e) { MAFLogger.e("HelloWorld", "SDM data source exception during logon", e); } mafCore.switchScreen(MainActivity.this); } }).start();This approach allows passing in a custom data source adapter, but the default implementation works correctly for OData. This setup is all you need to build an extensible app that does not require custom hooks or mixing native UIs with UIs that are defined via metadata.
From this point on, you only have to enhance the layout_phone.xml to define new tiles, UI elements, bindings and so on.