2016-12-22 25 views
-2

ODataサービスを使用してバックエンドABAPシステムに接続しようとしていますが、スクリーンショットに示すようにエラーが発生しています。ODataサービスに接続できません

ライブラリ-preload.js:522キャッチされない例外TypeError:プロパティを読み取ることができません。(...)未定義の '読み取り'

Error

ここでは、さまざまなファイルのコードです:

ネオアプリは、 .json:

{ 
    "path": "/DB7", 
    "target": { 
    "type": "destination", 
    "name": "DB7" 
    }, 
    "description": "DB7" 
} 

Component.js

init: function() { var oModel = new sap.ui.model.odata.v2.ODataModel(this.getMetadata().getConfig().serviceUrl); 
    this.setModel(oModel,"data"); 

}

manifest.jsonを

{ 
"_version": "1.1.0", 
"sap.app": { 
    "_version": "1.1.0", 
    "id": "com.abc.cup", 
    "type": "application", 
    "i18n": "i18n/i18n.properties", 
    "applicationVersion": { 
     "version": "1.0.0" 
    }, 
    "title": "{{appTitle}}", 
    "description": "{{appDescription}}", 
    "sourceTemplate": { 
     "id": "ui5template.basicSAPUI5ApplicationProject", 
     "version": "1.32.0" 
    }, 
    "dataSources": { 
     "invoiceRemote": { 
     "uri": "/destinations/DB7/sap/opu/odata/ATSH/UI5_DISPLAY_SRV/", 
     "type": "OData", 
     "settings": { 
      "odataVersion": "2.0" 
    } 
    } 
} 
}, 
"sap.ui": { 
    "_version": "1.1.0", 
    "technology": "UI5", 
    "icons": { 
     "icon": "", 
     "favIcon": "favicon.ico", 
     "phone": "", 
     "[email protected]": "", 
     "tablet": "", 
     "[email protected]": "" 
    }, 
    "deviceTypes": { 
     "desktop": true, 
     "tablet": true, 
     "phone": true 
    }, 
    "supportedThemes": ["sap_hcb", "sap_bluecrystal"] 
}, 
"sap.ui5": { 
    "_version": "1.1.0", 
    "rootView": { 
     "viewName": "com.abc.cop.view.View1", 
     "type": "XML" 
    }, 
    "dependencies": { 
     "minUI5Version": "1.30.0", 
     "libs": { 
      "sap.ui.core": {}, 
      "sap.m": {}, 
      "sap.ui.layout": {} 
     } 
    }, 
    "contentDensities": { 
     "compact": true, 
     "cozy": true 
    }, 
    "models": { 
     "":{ 
      "dataSource": "invoiceRemote", 
      "settings":{} 
     }, 
     "i18n": { 
      "type": "sap.ui.model.resource.ResourceModel", 
      "settings": { 
       "bundleName": "com.abc.cop.i18n.i18n" 
      } 
     } 
    }, 
    "resources": { 
     "css": [{ 
      "uri": "css/style.css" 
     }] 
    }, 
    "routing": { 
     "config": { 
      "routerClass": "sap.m.routing.Router", 
      "viewPath": "com.abc.cop.view", 
      "controlId": "appId", 
      "controlAggregation": "pages", 
      "transition": "fade" 
     }, 
     "routes": [{ 
      "name": "main", 
      "pattern": "", 
      "target": ["initialScreen"] 
     }, { 
      "name": "moreDetails", 
      "pattern": "moreDetails", 
      "target": ["moreDetails"], 
      "greedy": true 
     } 
     ], 
     "targets": { 
      "main": { 
       "viewType": "XML", 
       "transition": "slide", 
       "viewName": "View1", 
       "viewId": "view1", 
       "viewLevel": 1 
      }, 
      "moreDetails": { 
       "viewType": "XML", 
       "transition": "fade", 
       "viewName": "View2", 
       "viewId": "view2", 
       "clearAggregation": true, 
       "viewLevel": 2, 
       "controlId": "appId" 
      }, 
      "initialScreen": { 
       "viewType": "XML", 
       "transition": "fade", 
       "clearAggregation": true, 
       "viewName": "View3", 
       "viewId": "view3" 
      } 
     } 
    } 
} 

}

Controller.js

onBeforeRendering: function() { 
     var oModell = new sap.ui.model.odata.ODataModel(
      "https://webidetesting3386376-p1942296689trial.dispatcher.hanatrial.ondemand.com/destinations/DB7/sap/opu/odata/ATSH/UI5_DISPLAY_SRV/" 
     ); 

     //var oJSONModel = new sap.ui.model.json.JSONModel(); 
     oModell.read("SY_INFOSet(Customer='ABC',Sysid='DB7')", null, null, true, function(oData, oResponse) { 
      alert("Read successful: " + JSON.stringify(oData)); 

      this.getView().setModel(oModell, "jsonData"); 

      //var oModel22 = new sap.ui.model.json.JSONModel(oData); 
      //sap.ui.getCore().setModel(oModel22, "jsonData"); 

     }, function() { 

      alert("Read failed"); 
     }); 
    }, 

View.xml

<ObjectHeader class="HeaderObjectwidth" id="objectHeader" title="{i18n>systemId} - {SYS_INFOSet/Sysid}" number="{i18n>numUsers} {SYS_INFO/Customer}" numberUnit="{i18n>versionId} {SYS_INFO/Sysid}"> 
    <attributes> 
     <ObjectAttribute title="{i18n>custName}" text="{jsonData>/FILE_UPD_UI5Set/Customer}"/> 
     <ObjectAttribute title="{i18n>osDetails}" text="{jsonData>Customer}"/> 
     <ObjectAttribute title="{i18n>dbDetails}" text="{jsonData>/Value}"/> 
    </attributes> 
</ObjectHeader> 
+0

マニフェストから 'sap.ui5'名前空間の 'models'を貼り付けることはできますか? –

+0

...詳細が必要です。 'this.getView()....'はどこですか?初期化メソッドで?ここでの問題は 'getModel'は何も返さないため、何らかの理由でビューに関連するモデルがありません。 –

+0

@RahulBhardwaj私はmanifest.jsonからモデルを追加しました – sky

答えて

0

エラーは、呼び出されたオブジェクトがundefinedであるため、メソッドreadを呼び出すことができないことを示しています。つまり、this.getView().getModel()undefinedを返します。

ビューのモデルは、onInitライフサイクルフックの間は利用できません。別のライフサイクルメソッドを選択する必要があります。

すべてのライフサイクルフックのリストはAPI description of the controller classにあります。

onInitの直後に呼び出されているので、onBeforeRenderingを使用することをおすすめします。

this github issueも参照してください。同じ問題が説明されています(また、いくつかの回答があります)。

+0

onBeforeRendering関数を追加したので、oData変数のデータをアラートで見ることができます。しかし、私はモデルにバインドすることができません。 私はthis.getView()。setModel()とsap.ui.getCore()。setModel()を使用しようとしましたが、モデル内のデータは取得しませんでした。 デバッガコンソールでは、これら2行のsap.ui.getCore()。setModel()/ this.getView()。setModel()で実行が停止します。 – sky

+0

コードが正常に動作していますが、私は不正なoModel.read()関数内でthis.getView()。setModel()にアクセスしようとしていました。だから、私はthis.getView.setModel()をread()関数の外に移動し、今は動作しています。 oデータ接続が確立され、モデルが設定されます。 – sky

関連する問題