Data Binding Tutorial - 06 Resource Models

홍종화·2021년 10월 12일
0

databinding

목록 보기
6/16

📌 개요

business application는 사용자 인터페이스의 labels 및 description으로 사용되는 번역가능한 텍스트도 필요하다.
번역 가능한 텍스트를 모델에 직접 배치하는 것은 좋은 프로그래밍 방법으로 간주되지 않기 때문에 번역 가능한 모든 텍스트를 resource bundle에 배치한다.

📌 예제

Resource Model을 더 보기에 앞서 빠르게 예제부터 보자.

  • resource bundle

  • MainView.controller.js

sap.ui.define([
	...
	"sap/ui/model/resource/ResourceModel"
],
	...
			onInit: function () {
				...
				
				const oResourceModel = new ResourceModel({
					bundleName: 'databinding.i18n.i18n',
					supportedLocales: ['', 'de'],
					fallbackLocale: ''
				})
               			this.getView().setModel(oResourceModel, 'i18n');
  • i18n/i18n.properties
# Field labels
firstName=First Name
lastName=Last Name
enabled=Enabled
  • MainView.view.xml
						<Panel headerText="{i18n>panelHeaderText}" class="sapUiSmallMargin" width="auto">
							<form:SimpleForm editable="true" layout="ResponsiveLayout">
								<Label text="{i18n>firstName}"/>
								<Input value="{/firstName}" valueLiveUpdate="true" width="200px" enabled="{/enabled}"/>
								<Label text="{i18n>lastName}"/>
								<Input value="{/lastName}" valueLiveUpdate="true" width="200px" enabled="{/enabled}"/>
								<Label text="{i18n>enabled}"/>
								<CheckBox selected="{/enabled}"/>
								<Label text="Check Current Model"/>
								<Button text="press button" press="checkCurrentDataModel" width="200px"/>
								<Label text="initialize Model"/>
								<Button text="refresh button" press="refreshDataModel" width="200px"/>
							</form:SimpleForm> 
						</Panel>

> 문자는 Model 이름과 Property 이름을 구분하며 i18n Property 이름은 /로 시작할 수 없다.

다른 Model 이름을 사용하여 여러 Model instance를 사용할 수 있다. Model 이름은 setModel(oResourceModel, 'i18n') 메소드를 사용하여 두 번째 매개변수로 설정할 수 있다. 이 Model은 집계된(aggregated) 모든 자식 컨트롤(및 해당 자식 ....)에 전파된다!!!

📌 Resource Model

resource model은 resource bundle의 wrapper로 사용된다. 예를 들어, data binding에서 resource model instance를 사용하여 컨트롤 텍스트를 언어에 의존하는 resoruce bundle 속성에 binding 한다.
resource model은 bundleName 또는 bundleURL로 인스턴스화된다. bundleName은 resource bundle의 이름이며 define/require 개념내에서 SAPUI5 module 이름과 같다. bundleURL은 resource bundle을 가리킨다. bundleName을 사용하는 경우 파일에 .properties 접미사가 있어여 한다. locale을 지정하지 않으면 시스템에서 로그인 어어를 사용한다.

const myBundle = oResourceModel.getResourceBundle();

resource model이 instance화되면 resource bundle 텍스트를 데이터로 포함하는 모델이 있다.

🔗 참고

profile
coding everywhere

0개의 댓글