Model、Viewテンプレート、Actionの開発

Model作成

Modelは画面で扱うデータを設定します。Modelフィールド値に基づいてコンポーネントを配置することができ、Datasetオブジェクトのカラムとして登録してGridコンポーネントとバインドしてデータを表現することができます。Modelは単独ではなく、Viewテンプレートと接続して使用します。ViewコンポーネントにModelを接続する際にはViewテンプレートを選択し、Viewテンプレートで作成したロジックに基づいてコンテンツを生成します。

TypeDefinitionでサービス登録

1

Project Exeplorerから[TypeDefinition > Services]項目を選択します。

2

User Service項目にサービスを追加します。Type項目は「model」を選択し、PrefixIDを設定します。

modelタイプのサービスの登録時にURL、ServiceList、DataSchemaを設定すると、該当のサービスよりModel Group、Model Service、Modelのデータを取得することもできます。下記のリンクをご参照ください。

Modelサービスの照会

Model Service項目の追加

新しいModelを作成するためには、QuickCodeペインを有効にする必要があります。

1

メニューの[QuickCode > View > QuickCode]項目を選択します。

2

QuickCodeペインが表示されたら、Modelタブを選択します。

3

TypeDefinitionで追加したmodelタイプのサービス項目を右クリックし、コンテキストメニューから「Insert > Model Service」項目を選択することでModel Serviceを追加することができます。

4

Model Service項目を右クリックしてコンテキストメニューから「Insert > Model」項目を選択すると、Model Wizardが表示されます。

Model WizardでModelの作成

1

Model ID、Nameを入力します。

ID項目の値を入力すると、Name項目が同じ値で自動入力されます。Name項目は異なる値に変更することができます。

2

データの用途によってIOTypeプロパティを設定します。

照会条件のようにユーザーが入力したり選択するデータをサーバーに送信する場合には「input」を選択し、照会結果を表示する場合には「output」を選択します。

3

Finishボタンをクリックすると、Wizard画面が閉じられ、ModelおよびModel Serviceの設定画面が表示されます。

4

Model 設定画面でプロパティ(Field Attribute)情報を追加します。

Modelの設定画面の右端の「+」ボタンをクリックすると表示される一覧(Predefined Attribute)の中から「uselabel」項目にチェックを入れます。

デフォルト項目として提供されるField Attributeを削除することはできません。ユーザーが追加したAttributeと区別するためにレーベルの文字が薄い色で表示されます。

5

Model設定画面の右端の「+」ボタンをクリックし、Field List項目を追加します。

項目を追加した後にField Type値を修正できます。Field Type値は、それ自体では機能を持たないですが、Viewテンプレートの画面構成時に該当するフィールド値にどのようなコンポーネントや機能を適用するのかを参照する値です。

6

メニューから保存アイコンをクリックすると、設定内容が保存されます。QuickCodeペインのModelタブよりModel項目をダブルクリックすると、ModelおよびModel Serviceの設定画面が再度表示されます。

7

Modelをコピーし、照会結果を処理するModelを作成します。

Modelを選択した状態でコンテキストメニュー>[Copy]項目を選択します。

コンテキストメニュー>[Paste]項目を選択し、新たなModel項目を生成し保存します。そしてプロパティリストよりid、iotype、nameプロパティ値を変更した後、保存します。

User Attributeの追加

Predefined Attributeに必要な項目がない場合はUser Attributeを追加することができます。

View Templateコード内でfn_GetFieldUserAttributeList関数を作成した場合には、設定されたUser Attribute一覧を取得することができます。

1

Model設定画面の右端の[+]ボタンをクリックすると表示される一覧より「Add Attributes」項目にチェックを入れます。

2

Edit User Attributes画面の右端の設定アイコンをクリックすると、Add User Attribute画面が表示されます。

3

Target ListよりUser Attributeを取得するView Templateを選択します。

4

Attribute Listより、追加したいUser Attribute項目のみチェックします。

5

右方向の矢印ボタンをクリックすると、選択されたUser Attribute項目がUser Attribute Listに追加されます。

6

Add User Attribute画面で[OK]ボタンをクリックすると、Edit User Attributes画面で追加する項目を確認することができます。

7

Edit User Attributes画面で[OK]ボタンをクリックすると、Model設定画面にUser Attributeが追加されていることを確認することができます。

Model Serviceの設定

Model Serviceの編集状態でプロパティリストからService関連プロパティを設定することができます。id、name、urlプロパティを設定します。

Model情報のソースコードの確認

Model設定画面の下部のタブを「Source」に切り替えると、生成されたソースコードが表示されます。ソースコードを直接修正した後に下部のタブを「Items」に切り替えると修正後の内容が反映されていることを確認することができます。

Viewテンプレートの作成

Viewテンプレートの作成方法(2つ)

View Template WizardでViewテンプレートの作成

プロジェクトの生成時に「Use QuickCode」項目にチェックを入れ「Install > Sample」を選択した場合は、Tutorialで利用するViewテンプレートがviewtemplateフォルダにコピーされます。Viewテンプレート項目をダブルクリックすると、スクリプトを確認できます。例題では、サンプルViewテンプレートを使用せずに、新しいViewテンプレートを作成します。

1

QuickCodeメニューから「Add」項目を選択してView Template Wizardを実行します。QuickCodeペインを表示せずにメニューの[File > New > View Template]項目を選択してもView Template Wizardを実行できます。

2

Nameを入力します。

3

View Typeを選択もしくは入力します。

基本的に提供されるタイプは「FreeForm」、「GridView」、 「ListView」、「Tutorial」の4種類であり、異なる値を直接入力して追加することができます。直接追加したView Typeの値は、View Template Wizard実行時にリストに表示されます。サンプルと区別できるようにView Typeの項目値を「ViewSample」と入力します。

View Templateの生成時に参考できるサンプルコードをコメントアウトとして追加しない場合は「Include Example」項目値を「false」に変更します。「true」を指定した場合は下記の通りにサンプルコードが追加された状態でView Tamplateが生成されます。

4

「Finish」ボタンをクリックして、Viewテンプレートを作成します。作成されたViewテンプレートは、QuickCodeペインの「View Template」タブで確認できます。

デザインされたViewコンポーネントを用いたViewテンプレートの作成

Viewコンポーネントの画面を予めデザインした状態でViewテンプレートを作成することができます。Viewコンポーネントの画面を基にfn_GetViewGenerationResult関数内のソースコードが自動生成されます。

1

Viewコンポーネントの画面をデザインします。

2

Viewコンポーネントを選択した状態でメニュー[QuickCode > Design > Create View Template]項目を選択します。

3

View Template Wizardが実行されます。Name、ViewTypeなどの項目を入力します。

4

[Finish]ボタンをクリックすると、Viewテンプレートが作成されます。作成されたViewテンプレートのソースコードからfn_GetViewGenerationResult関数内のソースコードが自動生成されていることを確認することができます。

Viewテンプレートスクリプトの編集

View Template WizardでViewテンプレートを作るか、QuickCodeペインでViewテンプレート項目をダブルクリックすると、「ファイル名」.xviewgenというファイルが編集ウィンドウで開きます。該当するスクリプトを編集して、希望する機能を実現することができます。

基本的なインタフェース関数が作成されており、必要な情報をコメントで提供します。

Viewテンプレートでは以下のような関数を実装する必要があります。

関数名

必須有無

説明

fn_GetViewGenerationResult

Model情報によって画面UIの構成のための情報を返します。

fn_GetViewAttributeList

Viewの生成に必要な追加のプロパティ情報を返します。

関数を使用しない場合はnullを返します。

fn_GetFieldUserAttributeList

×

User Attributesの処理のための情報を返します。

User Attributesを使用する場合にのみ作成します。

次は、各関数で受け取るパラメータと戻り値ははどんな形式なのかについて説明します。

fn_GetViewGenerationResult

パラメータ(fieldarray、contents、generationattr)に基づいて生成されたView contentsオブジェクトを返す関数です。 fn_GetViewGenerationResult関数で使用するパラメータと戻り値は、JSON形式のオブジェクトを使用します。

Syntax

fn_GetViewGenerationResult(fieldarray, contents, generationattr)

Parameters

パラメータ

タイプ

説明

fieldarray

Object

Model Field情報

contents

Object

View情報

generationattr

Object

View Generationプロパティ情報

Return

タイプ

説明

String

referenceinfoを除いたcontents形式のオブジェクトを文字列で返します。

戻り値のJSON形式の詳細については、fn_GetViewGenerationResultの戻り値のJSON形式をご参照ください。

fieldarrayパラメータJSON形式

選択したModel情報です。基本的な値はModel生成時のフィールド値であり、「uselabel」のようなAttributeを追加した場合に一緒に渡されます。

{
	"modelinfo": {
		"serviceid": "mdlSample",
		"serviceurl": ""
	},
	"fieldcount": "2",
	"fields": [
		{
			"id": "name",
			"label": "Name",
			"fieldtype": "FreeText",
			"datatype": "STRING",
			"datasize": "80",
			"uselabel" : "true"
		},
		{
			"id": "company",
			"label": "Company",
			"fieldtype": "FreeText",
			"datatype": "STRING",
			"datasize": "80",
			"uselabel" : "true"
		}
	]
}

contentsパラメータJSON形式

Modelに接続しようとするViewコンポーネントの情報です。ViewコンポーネントのBorder領域を除いてコンポーネントを配置できる実際の幅と高さ(referenceinfo)を基準にコンポーネントを配置できます。実際のサイズと各コンポーネントの間隔、フォントサイズなどを考慮してコンポーネントを配置します。

Viewコンポーネントにすでに接続されているModel情報があるか、他のコンポーネントがある場合はModel情報が追加され、Datasetオブジェクトが含まれている場合はObjects情報が追加されます。その他、Viewコンポーネントに関する情報も一緒に渡されます。

{
	"View": {
		"tag": "View",
		"referenceinfo": {
			"realwidth": "490",
			"realheight": "90"
		},
		"attribute": {
			"id": "View00",
			"taborder": "0",
			"text": "View00",
			"viewdataset": "viewdataset",
			"left": "0",
			"top": "0",
			"width": "500",
			"height": "100",
			"border":"5px solid darkkhaki"
		},
		"Model": [],
		"Objects": [
			{}
		],
		"Bind": [
			{}
		],
		"InitValue": [
			{}
		],
		"Script": {}
	}
}

generationattrパラメータJSON形式

ViewAttributeの設定情報です。各項目は、fn_GetViewAttributeList関数で返された値であり、項目値はModel接続時にView Template Attributes段階で設定した値です。

{
	"attributes": {
		"use_triggerbutton": "true"
	}
}

戻り値JSON形式

Viewテンプレートのパラメータ(fieldarray、contents、generationattr)値に基づいて生成されたView contents値です。

{
	"View": {
		"tag": "View",
		"attribute": {
			"id": "View00",
			"taborder": "0",
			"text": "View00",
			"viewdataset": "viewdataset",
			"left": "85",
			"top": "43",
			"width": "437",
			"height": "110"
		},
		"Model": [
			{
				"fieldid": "name",
				"Components": [
					{
						"tag": "Static",
						"attribute": {
							"id": "Static0",
							"text": "Name",
							"left": 0,
							"top": 0,
							"width": 60,
							"height": 20,
							"font": "normal bold 15pt/normal"
						}
					},
					{
						"tag": "Edit",
						"attribute": {
							"id": "Edit0",
							"left": "Static0:5",
							"top": 0,
							"width": 100,
							"height": 20,
							"font": "normal bold 15pt/normal"
						}
					}
				]
			},
			{
				"fieldid": "company",
				"Components": [
					{
						"tag": "Static",
						"attribute": {
							"id": "Static1",
							"text": "Company",
							"left": 0,
							"top": 30,
							"width": 60,
							"height": 20,
							"font": "normal bold 15pt/normal"
						}
					},
					{
						"tag": "Edit",
						"attribute": {
							"id": "Edit1",
							"left": "Static1:5",
							"top": 30,
							"width": 100,
							"height": 20,
							"font": "normal bold 15pt/normal"
						}
					}
				]
			},
			{
				"fieldid": "",
				"Components": [
					{
						"tag": "Button",
						"attribute": {
							"id": "btn_Trigger",
							"right": 0,
							"top": 0,
							"width": 70,
							"height": 20,
							"text": "Search"
						}
					}
				]
			}
		],
		"Objects": [
			{
				"tag": "Objects",
				"Objects": [
					{
						"tag": "Dataset",
						"attribute": {
							"id": "ds_company"
						},
						"Dataset": [
							{
								"tag": "ColumnInfo",
								"ColumnInfo": [
									{
										"tag": "Column",
										"attribute": {
											"id": "code",
											"type": "STRING",
											"size": "80"
										}
									},
									{
										"tag": "Column",
										"attribute": {
											"id": "data",
											"type": "STRING",
											"size": "256"
										}
									}
								]
							},
							{
								"tag": "Rows",
								"Rows": [
									{
										"tag": "Row"
									}
								]
							}
						]
					}
				]
			}
		],
		"Bind": [
			{
				"tag": "Bind",
				"Bind": [
					{
						"tag": "BindItem",
						"attribute": {
							"id": "item0",
							"compid": "Edit0",
							"propid": "value",
							"datasetid": "viewdataset",
							"columnid": "name"
						}
					},
					{
						"tag": "BindItem",
						"attribute": {
							"id": "item1",
							"compid": "Edit1",
							"propid": "value",
							"datasetid": "viewdataset",
							"columnid": "company"
						}
					}
				]
			}
		]
	}
}

fn_GetViewAttributeList

Viewの生成に必要なプロパティ情報を返す関数です。

Syntax

fn_GetViewAttributeList()

Return

タイプ

説明

String

View Template Attributesリストオブジェクトを文字列で返します。

null値を返すと、View Generation Wizardで追加プロパティの設定を処理しません。

戻り値JSON形式

{
	"attributecount": 1,
	"attributes": [
		{
			"id": "use_triggerbutton",
			"edittype": "Boolean",
			"defaultvalue": "true",
			"description": "Create a button for data inquiry (true/false)"
		}
	]
}

edittype値が「Enum」である場合には、下記のように処理できます。

{
    "attributecount": "1",
    "attributes": [
        {
            "id": "gridtype",
            "edittype": "Enum",
            "defaultvalue": "Single Line",
            "enumlist": [
                "Single Line",
                "Multi Line"
            ],
            "description": "Specifies the generation type of grid."
        }
    ]

edittypeの値が「Layout」である場合は、下記のように処理できます。

{
    "attributecount": "1",
    "attributes": [
        {
            "id": "view_layout",
            "edittype": "Layout",
			"userproperties": {
				"propertycount": "1",
				"properties": [
					{
						"id": "gap",
						"edittype": "Number",
						"defaultvalue": 5
					}
				]
			}
        }
    ]

fn_GetFieldUserAttributeList

fn_GetFieldUserAttributeList関数は、2つの機能をサポートします。

Model生成時のUser Attributes処理

Model作成時、「Add User Attribute」設定でfn_GetFieldUserAttributeList関数を持つView TemplateリストをTarget Listに表示し、View Templateを選択すると、追加できるUser Attributes情報を表示します。

Model適用時、User Attributes処理

ViewコンポーネントにModel適用時、選択したView Templateにfn_Get FieldUserAttributeList関数がある場合、User Attributes情報をModelフィールドに追加します。

Modelで定義したUser Attributeとidが同じ場合には、Modelで定義したUser Attributeが適用されます。

Syntax

fn_GetFieldUserAttributeList()

Return

タイプ

説明

String

Model Fieldとして追加するUser Attributes一覧オブジェクトを文字列として返します。nullを返した場合、Attribute Listを表示しません。

戻り値のJSON形式

{
	"attributecount": 1,
	"attributes": [
		{
			"id": "editable",
			"edittype": "Boolean",
			"defaultvalue": "true",
			"description": "Sets whether the field data can be edited."
		}
	]
}

Viewテンプレートの例

例題では、2つのViewテンプレートを生成します。viewSampleFormは、Model情報に基づいて照会条件UIを生成するか、Gridコンポーネントで選択した項目の詳細情報を表現するUIを生成します。viewSampleGridは、Model情報に基づいてGridコンポーネントを表現します。

下記のサンプルでは、JSON戻り値の形式を作るためにObject、Arrayを使いましたが、下記のように文字列のみでコードを作成できます。

...
var strDataset1 = "{";
strDataset1 += "\"tag\": \"Dataset\",";
strDataset1 += "\"attribute\": {\"id\": \"viewdataset\"},";
strDataset1 += "\"Dataset\": [";
strDataset1 += "{\"tag\": \"ColumnInfo\",";
strDataset1 += "\"ColumnInfo\": [";
...

サンプルコードでは関数の中にすべてのコードを追加しましたが、戻り値に含まれる各オブジェクトごとに区分して別途の関数を作り、結果値を組み合わせると、もっと使いやすいです。

viewSampleForm

フィールド情報に基づいてEditコンポーネントを生成し、uselabel追加プロパティが「true」である場合には、StaticコンポーネントをEditコンポーネントの前に配置します。fn_GetViewAttributeList関数では、use_triggerbuttonという項目を返してButtonを生成するかどうかを判断します。

ModelによってDatasetオブジェクトを生成し、生成されたDatasetオブジェクトはviewdatasetプロパティ値として設定されます。そしてEditコンポーネントのvalueプロパティとバインドします。

fn_GetViewGenerationResult = function (fieldarray, contents, generationattr) {
    var vResult = "";
	var json_contents = JSON.parse(contents);
	var json_fieldarray = JSON.parse(fieldarray);
	var json_generationattr = JSON.parse(generationattr);
	
	var View = new Object(); // JSON Object	
	var tempInfo;
	var tempPostion;
	
	var ModelArray = new Array();
	var ModelInfo;
	
	var ComponentArray;
	var ObjectsArray = new Array();
	var ObjectArray = new Array();
	var DatasetArray = new Array();
	var ColumnArray = new Array();
	var BindsArray = new Array();
	var BindArray = new Array();

	for (var i in json_fieldarray.fields) {
		ModelInfo = new Object();
		ComponentArray = new Array();
		ModelInfo.fieldid = json_fieldarray.fields[i].id;
		
		tempInfo = new Object();
		tempInfo.tag = "Column";
		tempInfo.attribute = new Object();
		tempInfo.attribute.id = json_fieldarray.fields[i].id;
		tempInfo.attribute.type = json_fieldarray.fields[i].datatype;
		tempInfo.attribute.size = json_fieldarray.fields[i].datasize;
		ColumnArray.push(tempInfo);
		
		if(json_fieldarray.fields[i].uselabel == "true") {
			tempInfo = new Object();
			tempInfo.tag = "Static";
			tempInfo.attribute = new Object();
			tempInfo.attribute.id = "Static"+i;
			tempInfo.attribute.text = json_fieldarray.fields[i].label;
			tempInfo.attribute.left = 0;
			tempInfo.attribute.top = i*30;
			tempInfo.attribute.width = 60;
			tempInfo.attribute.height = 20;
			tempInfo.attribute.font = "normal bold 15pt/normal";
			ComponentArray.push(tempInfo);
		}
		
		tempInfo = new Object();
		tempInfo.tag = "Edit";
		tempInfo.attribute = new Object();
		tempInfo.attribute.id = "Edit"+i;
		tempInfo.attribute.left = "Static"+i+":5";
		tempInfo.attribute.top = i*30;
		tempInfo.attribute.width = 100;
		tempInfo.attribute.height = 20;
		tempInfo.attribute.font = "normal bold 15pt/normal";
		ComponentArray.push(tempInfo);
		
		tempInfo = new Object();
		tempInfo.tag = "BindItem";
		tempInfo.attribute = new Object();
		tempInfo.attribute.id = "item"+i;
		tempInfo.attribute.compid = "Edit"+i;
		tempInfo.attribute.propid = "value";
		tempInfo.attribute.datasetid = "viewdataset";
		tempInfo.attribute.columnid = json_fieldarray.fields[i].id;
		BindArray.push(tempInfo);	
		
		ModelInfo.Components = ComponentArray;
		ModelArray.push(ModelInfo);		
	}

	tempInfo = new Object();
	tempInfo.tag = "Bind";
	tempInfo.Bind = BindArray;
	BindsArray.push(tempInfo);
	
	if(json_generationattr.attributes.use_triggerbutton == "true") {
		ModelInfo = new Object();
		ComponentArray = new Array();
		ModelInfo.fieldid = "";
		
		tempInfo = new Object();
		tempInfo.tag = "Button";
		
		var buttonwidth = 70;
		tempInfo.attribute = new Object();
		tempInfo.attribute.id = "btn_Trigger";
		tempInfo.attribute.right = 0;
		tempInfo.attribute.top = 0;
		tempInfo.attribute.width = buttonwidth;
		tempInfo.attribute.height = 20;
		tempInfo.attribute.text = "Search"
		ComponentArray.push(tempInfo);
		ModelInfo.Components = ComponentArray;
		ModelArray.push(ModelInfo);
	}	

	tempInfo = new Object();
	tempInfo.tag = "View";
	tempInfo.attribute = json_contents.View.attribute;
	tempInfo.Model = ModelArray;
	tempInfo.Objects = ObjectsArray;
	tempInfo.Bind = BindsArray;

	View.View = tempInfo;
	var vResult = JSON.stringify(View);
    return vResult;
};

fn_GetViewAttributeList = function () {
	var attrArray = new Array();
	var attrObj = new Object();
	attrObj.id = "use_triggerbutton";
	attrObj.edittype = "Boolean";
	attrObj.defaultvalue = "true";
	attrObj.description = "Create a button for data inquiry (true/false)";
	attrArray.push(attrObj);
	
	var attr = new Object();
	attr.attributecount = attrArray.length;
	attr.attributes = attrArray;
	
	var strJson = JSON.stringify(attr);
	trace("RE : "+strJson);	
	return strJson;
};

viewSampleGrid

フィールド情報に基づいてGridコンポーネントとDatasetオブジェクトを生成し、DatasetオブジェクトはGridコンポーネントとバインドします。 fn_GetViewAttributeList関数は使用しません。

fn_GetViewGenerationResult = function (fieldarray, contents, generationattr) {
    var vResult = "";
	var json_contents = JSON.parse(contents);
	var json_fieldarray = JSON.parse(fieldarray);
	//var json_generationattr = JSON.parse(generationattr);
	
	var View = new Object(); // JSON Object	
	var tempInfo;
	
	var ModelArray = new Array();
	var ModelInfo = new Object();
	ModelInfo.fieldid = "";

	var ComponentArray = new Array();
	var ObjectsArray = new Array();
	var ObjectArray = new Array();
	var DatasetArray = new Array();
	var ColumnArray = new Array();
	
	var GridColumnsArray = new Array();
	var GridRowsArray = new Array();
	var GridBandHeadArray = new Array();
	var GridBandBodyArray = new Array();


	for (var i in json_fieldarray.fields) {
		if(ModelInfo.fieldid != "") {
			ModelInfo.fieldid += ",";
		}
		ModelInfo.fieldid += json_fieldarray.fields[i].id;
		
		tempInfo = new Object();
		tempInfo.tag = "Column";
		tempInfo.attribute = new Object();
		tempInfo.attribute.id = json_fieldarray.fields[i].id;
		tempInfo.attribute.type = json_fieldarray.fields[i].datatype;
		tempInfo.attribute.size = json_fieldarray.fields[i].datasize;
		ColumnArray.push(tempInfo);
		
		tempInfo = new Object();
		tempInfo.tag = "Column";
		tempInfo.attribute = new Object();
		tempInfo.attribute.size = "80";
		GridColumnsArray.push(tempInfo);

		tempInfo = new Object();
		tempInfo.tag = "Cell";
		tempInfo.attribute = new Object();
		tempInfo.attribute.col = i;
		tempInfo.attribute.text = json_fieldarray.fields[i].label;
		GridBandHeadArray.push(tempInfo);		
		
		tempInfo = new Object();
		tempInfo.tag = "Cell";
		tempInfo.attribute = new Object();
		tempInfo.attribute.col = i;
		tempInfo.attribute.text = "bind:"+json_fieldarray.fields[i].id;
		tempInfo.attribute.edittype = "text";
		GridBandBodyArray.push(tempInfo);
	}
	var GridInfo = new Object();
	GridInfo.tag = "Formats";
	GridInfo.Formats = new Array();
	var formatInfo = new Object();
	formatInfo.tag = "Format";
	formatInfo.attribute = new Object();
	formatInfo.attribute.id = "default";
	formatInfo.Format = new Array();
	
	tempInfo = new Object();
	tempInfo.tag = "Columns";
	tempInfo.Columns = GridColumnsArray;
	formatInfo.Format.push(tempInfo);
	
	tempInfo = new Object();
	tempInfo.tag = "Row";
	tempInfo.attribute = new Object();
	tempInfo.attribute.band = "head";
	tempInfo.attribute.size = "24";
	GridRowsArray.push(tempInfo);
	tempInfo = new Object();
	tempInfo.tag = "Row";
	tempInfo.attribute = new Object();
	tempInfo.attribute.size = "24";
	GridRowsArray.push(tempInfo);	

	tempInfo = new Object();
	tempInfo.tag = "Rows";
	tempInfo.Columns = GridRowsArray;
	formatInfo.Format.push(tempInfo);
	
	tempInfo = new Object();
	tempInfo.tag = "Band";
	tempInfo.attribute = new Object();
	tempInfo.attribute.id = "head";
	tempInfo.Columns = GridBandHeadArray;
	formatInfo.Format.push(tempInfo);	
	
	tempInfo = new Object();
	tempInfo.tag = "Band";
	tempInfo.attribute = new Object();
	tempInfo.attribute.id = "body";	
	tempInfo.Columns = GridBandBodyArray;
	formatInfo.Format.push(tempInfo);	
	GridInfo.Formats.push(formatInfo);
	
	tempInfo = new Object();
	tempInfo.tag = "Grid";
	tempInfo.attribute = new Object();
	tempInfo.attribute.id = "Grid"+i;
	tempInfo.attribute.left = 0;
	tempInfo.attribute.top = 0;
	tempInfo.attribute.right = 0;
	tempInfo.attribute.bottom = 0;
	tempInfo.attribute.binddataset = "viewdataset";
	tempInfo.Grid = new Array();
	tempInfo.Grid.push(GridInfo);
	ComponentArray.push(tempInfo);		

	ModelInfo.Components = ComponentArray;
	ModelArray.push(ModelInfo);

	tempInfo = new Object();
	tempInfo.tag = "View";
	tempInfo.attribute = json_contents.View.attribute;
	tempInfo.Model = ModelArray;
	tempInfo.Objects = ObjectsArray;

	View.View = tempInfo;
	var vResult = JSON.stringify(View);
    return vResult;
};

fn_GetViewAttributeList = function () {
	return null;
};

Action作成

ModelとViewテンプレートを使用して作った画面で、実際に動作する機能を設定する段階です。Triggerで指定したオブジェクトに特定のイベントが発生する場合、指定した動作を処理します。例題では、検索ウィンドウでボタンをクリックすると、Gridコンポーネントにデータが表示されます。データ照会のためのActionプロパティ値に基づいてデータ照会が成功した時に、特定のプロパティ値であれば、警告ダイアログボックスを表示します。

Actionはユーザーモジュールの形式で生成してnexacro studioでインストールします。

nexacroモジュールデベロッパーでInvisible Objectプロジェクトを作成してActionモジュールを生成することができます。

Actionモジュールプロジェクトの生成

1

nexacroモジュールデベロッパーを起動します。

nexacro studioのインストール時にショートカットを作成していない場合には、インストールフォルダ配下の「nexacromoduledeveloper.exe」ファイルより起動します。

2

メニュー[File > New > Project]より、Project Wizardを実行します。

3

Module項目からInvisible Objectを選択します。

4

Project Nameを入力して[Next]ボタンをクリックします。

5

Object IDを入力します。Object IDはActionオブジェクト名として設定されます。

例題では、「TestQueryAction」といったObject IDを使用します。ClassNameはObject IDを入力すると自動設定されます。 FinalClassプロパティ値は「true」、Contentsプロパティ値は「false」に変更します。

6

[Finish]ボタンをクリックします。

プロジェクトが生成されます。詳細オプションは、例題では設定しません。オブジェクトの詳細設定はあとから設定することができます。

Actionオブジェクト追加

プロジェクト生成時には、基本オブジェクトが1つ生成され、同じモジュールとして配布するオブジェクトを別途追加する必要があります。

1

メニュー[File > New > Invisible Object]より、Invisible Object Wizardを実行します。

2

Object IDを入力します。

例題では、"TestAlertAction"といったActionオブジェクト名を使用します。FinalClassプロパティ値は「true」、Contentsプロパティ値は「false」に変更します。

3

[Finish]ボタンをクリックします。

Actionオブジェクトのプロパティ編集

1

Project ExplorerよりTestQueryAction、TestAlertActionオブジェクトのMetaInfo項目を選択し、プロパティリストで下記のプロパティを設定します。

subgroup: Action
registration: allow

2

変更内容を保存します。

Actionオブジェクトのスクリプト編集

1

Project Explorerより、編集対象のActionオブジェクトのスクリプトファイルをダブルクリックするか、コンテキストメニューから[Edit]項目を選択します。

2

Actionオブジェクトに合わせてスクリプトファイルを修正します。

Actionスクリプトはnexacro.Actionを継承して実現します。基本的な構造は下記の通りで、イベント発生時にrun関数が実行されます。run関数内で必要な情報を収集·処理することになります。

スクリプト内で必要な情報は、Actionオブジェクトのプロパティ、メソッドを使ってアクセスできます。

Actionオブジェクトのプロパティ、メソッド、イベント

(function(nexacro) {
    "use strict";

	if (!nexacro)
		return;
	if (nexacro.TestQueryAction)
		return nexacro.TestQueryAction;

	var TestQueryAction = function(id, parent)
	{
        nexacro.Action.call(this, id, parent);
	};	
		
	var _pTestQueryAction = nexacro._createPrototype(nexacro.Action, TestQueryAction);		
	TestQueryAction.prototype = _pTestQueryAction;
	_pTestQueryAction._type_name = "TestQueryAction";
	_pTestQueryAction.uservalue = null;	
	
	_pTestQueryAction.destroy = function ()
	{
		nexacro.Action.prototype.destroy.call(this);
		this.uservalue = null;
    };

	_pTestQueryAction.set_uservalue = function (v)
	{
		if (v && this.uservalue!== v)
		{		
			this.uservalue= v;
		}
	};

	_pTestQueryAction.run = function ()
	{
	};

    nexacro.TestQueryAction = TestQueryAction;
    return TestQueryAction;
}) (nexacro);

TestQueryAction, TestAlertActionで使用するスクリプトは下記の通りです。

TestQueryActionスクリプト

trigger発生時(ボタンクリック時)にrun関数を呼び出します。

_getArgumentList関数を呼び出して引数として渡されたContents情報とviewdatasetプロパティに設定されたDatasetオブジェクトに保存されているカラム値を取得します。samplefilenameとして入力された値に応じてデータローディングのためのXMLファイルを確認した後、transactionメソッドを実行します。

例題ではXMLファイルを呼び出すため、引数として渡れた値はtraceメソッドで出力のみ行います。

$r_title(TestQueryAction.js)
(function(nexacro) {
    "use strict";

	if (!nexacro)
		return;
	if (nexacro.TestQueryAction)
		return nexacro.TestQueryAction;

	var TestQueryAction = function(id, parent)
	{
        nexacro.Action.call(this, id, parent);
	};	
		
	var _pTestQueryAction = nexacro._createPrototype(nexacro.Action, TestQueryAction);		
	TestQueryAction.prototype = _pTestQueryAction;
	_pTestQueryAction._type_name = "TestQueryAction";		
	
	_pTestQueryAction.samplefilename = ""; // XML file name	
	_pTestQueryAction.alerttype = false; // TestAlertAction condition
	_pTestQueryAction.targetobj = null;

	_pTestQueryAction.destroy = function ()
	{
		nexacro.Action.prototype.destroy.call(this);
        this.samplefilename = null;
		this.alerttype = null;
        this.targetobj = null;		
    };
    
	_pTestQueryAction.set_samplefilename = function (v)
	{
		if (v && this.samplefilename !== v)
		{		
			this.samplefilename = v;			
		}
	};
	
	_pTestQueryAction.set_alerttype = function (v)
	{
		if (v && this.alerttype !== v)
		{		
			this.alerttype = v;			
		}
	};	
	
    _pTestQueryAction.set_targetobj = function (v)
	{
		if (v && this.targetobj !== v)
		{
			this.targetobj = v;	
		}
    };	


	_pTestQueryAction._getArgumentList = function (strType)
	{
		var argumentlist = this.getContents(strType);
		if (!argumentlist) {
			return;
		}
		if(strType == "model")
		{
			for (var i = 0; i < argumentlist.length; i++)
			{
				var tempDataset = this.parent.lookup(argumentlist[i].viewid).getViewDataset();
				argumentlist[i].value = tempDataset.getColumn(tempDataset.rowposition, argumentlist[i].fieldid);
			}
		}
		return argumentlist;
	};

	_pTestQueryAction.run = function ()
	{
		var targetview = this.getTargetView();
		var viewdataset = targetview.viewdataset;
		var argumentlist = "";

		var modellist = this._getArgumentList ("model");
		var extralist = this._getArgumentList ("extra");
		var outdataset = viewdataset + "=ds_" + viewdataset;

        var callbackfn = "fn_callback";

        if (modellist)
        {
            for (var i = 0; modellist.length > i; i++)
            {
                if (modellist[i].value)
                {
                    argumentlist += modellist[i].name + "=" + modellist[i].value;
                    argumentlist += " ";
                }
            }
        }
		
        if (extralist)
        {
            for (var i = 0; extralist.length > i; i++)
            {
                if (extralist[i].value)
                {
                    argumentlist += extralist[i].name + "=" + extralist[i].value;
                    argumentlist += " ";
                }
            }
        }		
		
		// transaction callback function (onsuccess, onerror event)
		var targetaction = this;
		targetview.form[callbackfn] = function (strSvcID, nErrorCode, strErrorMag)
		{
			if (nErrorCode >= 0)
			{
				targetaction.error = "callback-success";
				targetaction.on_fire_onsuccess();
			}
			else
			{
				targetaction.error = "callback-error";
				targetaction.on_fire_onerror();
			}	
		}

		argumentlist += "dsname=" + viewdataset + " ";
		argumentlist.trim();
		var serviceurl = "Sample::"+this.samplefilename+".xml";
		trace("argumentlist: "+argumentlist);
		trace("outdataset: "+outdataset);
		trace("serviceurl: "+serviceurl);

		targetview.form.transaction("TEST", serviceurl, "", outdataset, argumentlist, callbackfn);
    };		
    
    nexacro.TestQueryAction = TestQueryAction;

    return TestQueryAction;
    
}) (nexacro);

TestAlertActionスクリプト

TestAlertActionスクリプトでは、run関数の実行時にmessageプロパティ値をalertメソッドのパラメータに指定して実行するのみです。

$r_title(TestAlertAction.js)
(function(nexacro) {
	"use strict";

	if (!nexacro)
		return;
	if (nexacro.TestAlertAction)
		return nexacro.TestAlertAction;
		
	var TestAlertAction = function(id, parent)
	{
		nexacro.Action.call(this, id, parent);
	};
		
	var _pTestAlertAction = nexacro._createPrototype(nexacro.Action, TestAlertAction);		
	TestAlertAction.prototype = _pTestAlertAction;
    _pTestAlertAction._type_name = "TestAlertAction";		
        
    _pTestAlertAction.message = "";

	_pTestAlertAction.destroy = function ()
	{
		nexacro.Action.prototype.destroy.call(this);
        
        this.message = null;
    };

    _pTestAlertAction.set_message = function (v)
	{
		this.message = v;			
	};

    _pTestAlertAction.run = function ()
	{
        alert(this.message);
	};		
	
	nexacro.TestAlertAction = TestAlertAction;

	return TestAlertAction;

}) (nexacro);

Actionオブジェクトのmetainfoの編集

Actionをモジュールで配布して使用するためには、metainfoファイルを生成する必要があります。

1

Project Explorerより、編集対象のActionオブジェクトのMetaInfo項目をダブルクリックするか、コンテキストメニューから[Edit]項目を選択します。

2

targetviewプロパティの詳細情報を編集します。

parent、targetviewプロパティはnexacro.Actionの基本プロパティであり、Actionオブジェクトの生成時にmetainfoでデフォルト値として表示されます。targetviewプロパティを選択し、プロパティリストより情報を設定します。

Group: Action
Edit Type: ViewObjList

3

[Property]タブで[+]ボタンをクリックしてActionオブジェクトのプロパティを追加します。

Actionスクリプトの編集時にAddメニューによりプロパティを追加すると、metainfoの方にも情報を自動的に追加されますが、スクリプトを直接編集した場合にはmetainfoの方に情報を手動で追加する必要があります。

TestQueryActionオブジェクトには、下記の通りに2つのプロパティを追加します。

Name: samplefilename
Group: Misc.
Edit Type: String

Name: alerttype
Group: Misc.
Edit Type: Boolean
Default Value: false

TestAlertActionオブジェクトには下記の通りに1つのプロパティを追加します。

Name: message
Group: Misc. 
Edit Type: String

TestAlertActionオブジェクトではtargetviewプロパティを使用しません。該当のプロパティを選択した後にUnused項目を「true」に変更します。

metainfoファイルで設定した内容はActionの紐づけの際にController Wizardで下記の通りに処理されます。

group

Controller Wizardで表示されるグループ名を指定できます。 ユーザーが簡単にプロパティを認識できるよう補助的に提供する情報です。

edittype

ObjectInfoタグでは、edittypeを「action」に設定します。

<ObjectInfo ... edittype="action" ...

各プロパティを設定する際にedittypeを指定すると、ユーザー入力値の形式を設定できます。テキストで値を入力せずにリストから選択できるような機能もサポートします。Actionで使用可能なedittypeは下記の通りです。

edittype

説明

String

文字列を入力します。

Number

数字を入力します。

Boolean

true, falseのどちらかを選択します。

ModelServiceID

Modelリストを提供します。

ViewObjList

現在のFormで使用できるViewコンポーネントリストを提供します。refreshinfo項目を一緒に設定すると、選択した項目の変更時に下位項目にも影響を与えます。

ViewChildObjList

ViewObjListで選択したViewコンポーネントに含まれるコンポーネントもしくはオブジェクトのリストを提供します。

Actionモジュールファイルの生成

1

メニューより[Deploy > Module Package]を選択します。

2

モジュールファイルを格納先を確認して[Next]ボタンをクリックします。

Versionなどの情報は必要に応じて入力します。

3

[Deploy]ボタンをクリックしてxmoduleファイルを生成します。