Skip to content

Commit

Permalink
Added everything for Step 6: Resource Models
Browse files Browse the repository at this point in the history
  • Loading branch information
wridgeu committed May 20, 2020
1 parent cb37402 commit 7fe1738
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
12 changes: 9 additions & 3 deletions webapp/controller/Home.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ sap.ui.define(
[
"com/mrb/UI5-Data-Binding/controller/BaseController",
"sap/ui/model/json/JSONModel",
"sap/ui/model/BindingMode",
"sap/ui/model/resource/ResourceModel"
],
function (BaseController, JSONModel, BindingMode) {
function (BaseController, JSONModel, ResourceModel) {
"use strict";

return BaseController.extend("com.mrb.UI5-Data-Binding.controller.Home", {
Expand All @@ -17,11 +17,17 @@ sap.ui.define(
panelHeaderText: "Data Binding Basics",
});

oModel.setDefaultBindingMode(BindingMode.OneWay);
// Create a resource bundle for language specific texts
// nowadays those are being declared via manifest.json
var oResourceModel = new ResourceModel({
bundleName: "com.mrb.UI5-Data-Binding.i18n.i18n_example",
});

//Set model globally for all views/controls (dirty) "sap.ui.getCore().setModel(oModel);""
//the go-to way for global definition would be to define the model within the manifest.json-file
//and retrieve it via "this.getOwnerComponent().getModel();"
this.getView().setModel(oModel);
this.getView().setModel(oResourceModel, "i18n_example")
},
});
}
Expand Down
7 changes: 7 additions & 0 deletions webapp/i18n/i18n_example.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Field labels
firstName=First Name
lastName=Last Name
enabled=Enabled

# Screen titles
panelHeaderText=Data Binding Basics
8 changes: 4 additions & 4 deletions webapp/view/Home.view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
xmlns="sap.m"
xmlns:mvc="sap.ui.core.mvc">
<Page titleAlignment="Center" title="{i18n>title}">
<Panel headerText="{/panelHeaderText}" class="sapUiResponsiveMargin" width="auto">
<Panel headerText="{i18n_example>panelHeaderText}" class="sapUiResponsiveMargin" width="auto">
<content>
<Label text="First Name" class="sapUiSmallMargin" />
<Label text="{i18n_example>firstName}" class="sapUiSmallMargin" />
<Input value="{/firstName}" valueLiveUpdate="true" width="200px" enabled="{/enabled}" />
<Label text="Last Name" class="sapUiSmallMargin" />
<Label text="{i18n_example>lastName}" class="sapUiSmallMargin" />
<Input value="{/lastName}" valueLiveUpdate="true" width="200px" enabled="{/enabled}" />
<CheckBox selected="{/enabled}" text="Enabled" />
<CheckBox selected="{/enabled}" text="{i18n_example>enabled}" />
</content>
</Panel>
</Page>
Expand Down

1 comment on commit 7fe1738

@wridgeu
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property "panelHeaderText" within the JSONModel of the Home.Controller has been removed as it is being translated within this i18n-file.

Please sign in to comment.