2017-04-03 117 views
0

我在門戶上部署了SAPUI5應用程序。 我想在我的SAPUI5中獲取登錄入口的用戶登錄名。SAPUI5和NW門戶

但是當我運行我的應用程序它沒有得到任何數據。

貝婁是我的代碼

sap.ui.define([ 
'jquery.sap.global', 
'sap/ui/core/Fragment', 
'sap/ui/core/mvc/Controller', 
'sap/ui/model/Filter', 
'sap/ui/model/json/JSONModel' 
], function(jQuery, Fragment, Controller, Filter, JSONModel) { 
    "use strict"; 

    var CController = Controller.extend("sap.m.ZHRUI001.C", { 
     inputId: '', 
     valueHelpRequest: function(oController) { 
      this.inputId = oController.oSource.sId; 
      var sServiceUrl = "http://<my server host>:<my server port>/sap/bc/ui2/start_up"; 
      var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true, "user", "password"); 

      var oJsonModel = new sap.ui.model.json.JSONModel(); 

      oModel.read("/?", null, null, true, function(oData, response) { 
       oJsonModel.setData(oData); 

      }); 
      sap.ui.getCore().setModel(oJsonModel); 


      // Handling of both confirm and cancel; clear the filter 
      var that = this; 
      var handleClose = function(oEvent) { 

       var oSelectedItem = oEvent.getParameter("selectedItem"); 
       if (oSelectedItem) { 
        that.byId(that.inputId).setValue(oSelectedItem.getTitle()); 
       } 
       oEvent.getSource().getBinding("items").filter([]); 
      }; 

      // Create a SelectDialog and display it; bind to the same 
      // model as for the suggested items 
      if (!this._valueHelpSelectDialog) { 
       this._valueHelpSelectDialog = new sap.m.SelectDialog("valueHelpSelectDialog", { 
        title: "{fullName}", 
        items: { 

         template: new sap.m.StandardListItem({ 
          title: "{fullName}", 
          active: true 
         }) 
        }, 
        search: function(oEvent) { 
         var sValue = oEvent.getParameter("value"); 
         var oFilter = new sap.ui.model.Filter(
          "name", 
          sap.ui.model.FilterOperator.Contains, sValue 
         ); 
         oEvent.getSource().getBinding("items").filter([oFilter]); 
        }, 
        confirm: handleClose, 
        cancel: handleClose 
       }); 

       this._valueHelpSelectDialog.setModel(oJsonModel); 

      } else { 
       this._valueHelpSelectDialog.setModel(oJsonModel); 
      } 
      this._valueHelpSelectDialog.open(); 

     } 
    }); 

    return CController; 

}); 
+0

有人可以幫助我嗎? –

回答

1

從什麼我讀你正在談論一個SAP門戶,我希望你有一個7.3+版本。

我找到了用於查找用戶的SAP文檔,請注意,因爲這不是在門戶網站上運行SAPUI5應用程序的代碼,而是運行在R/3系統上的SAPUI5應用程序的代碼,端點/sap /在NetWeaver門戶上不存在bc/ui2/start_up

你可以做的是開發一個簡單的REST服務(通過深化發展一個Servlet),將發回用戶,並且你需要的所有細節。 這些細節可以在其中持有IUSER對象PortalComponentRequest找到,你可以在我的Git中找到範例門戶Servlet這裏:

https://gitlab.com/Almiriad/sap-portal-samples

您只需發送一個GET請求的URL HTTP [S]:// youserver:你的端口/ IRJ/servlet的/ PRT /門/ prtroot/UserServletSample.UserInfoSampleServlet ,你會得到一個JSO

{ 
    "user": { 
     "user-name":"<LASTNAME>, <FIRSTNAME>", 
     "user-id":"<USER_ID>", 
     "user-email":"<[email protected]>" 
    } 
} 

我希望這會幫助你。

+0

嗨Almiriad,我必須在我的SAP Portal中導入這個servelet嗎? –

+0

你好,是的,你可以在你的門戶上部署它。我想你可以簡單地部署EAR文件,它是UserServletSample文件夾,並且該servlet應該可用。要小心,因爲有一個安全區域「com.almiriad.sap.portal.user.UserInfoSampleServlet」,您必須確保您的用戶有權訪問(通常在您通過身份驗證後應該可以):https://help.sap的.com/saphelp_nw75/helpdata/EN/48/50badbb82971b9e10000000a421937/frameset.htm – Almiriad

0

`

var oUserData; 
      var y = "/sap/bc/ui2/start_up"; 
      var xmlHttp = null; 
      xmlHttp = new XMLHttpRequest(); 
      xmlHttp.onreadystatechange = function() { 
      if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { 
        oUserData = JSON.parse(xmlHttp.responseText); 
       } 
      }; 
      xmlHttp.open("GET", y, false); 
      xmlHttp.send(null); 

`

控制檯oUserData讓誰登錄該用戶的登錄信息。

+1

你好Sriram, 我有把這段代碼放在我的控制器中嗎? –

+0

是把這個代碼放在控制器 –

+0

的onInit函數中,但我怎麼做才能得到用戶的全名? –