Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 2740

Re: Views and Controllers Loading Confusion

$
0
0

Controller1:

 

sap.ui.controller("ajax.InputForm", {

 

 

/**

* Called when a controller is instantiated and its View controls (if available) are already created.

* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.

* @memberOf ajax.InputForm

*/

// onInit: function() {

//

// },

 

 

/**

* Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered

* (NOT before the first rendering! onInit() is used for that one!).

* @memberOf ajax.InputForm

*/

// onBeforeRendering: function() {

//

// },

 

 

/**

* Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here.

* This hook is the same one that SAPUI5 controls get after being rendered.

* @memberOf ajax.InputForm

*/

// onAfterRendering: function() {

//

// },

 

 

/**

* Called when the Controller is destroyed. Use this one to free resources and finalize activities.

* @memberOf ajax.InputForm

*/

// onExit: function() {

//

// }

  search: function()

  {

  app = sap.ui.getCore().byId("appid");

  app.to("idOutput");

  }

 

 

});

 

 

 

InputForm --> View1

 

sap.ui.jsview("ajax.InputForm", {

 

 

  /** Specifies the Controller belonging to this View.

  * In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.

  * @memberOf ajax.InputForm

  */

  getControllerName : function() {

  return "ajax.InputForm";

  },

 

 

  /** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed.

  * Since the Controller is given to this method, its event handlers can be attached right away.

  * @memberOf ajax.InputForm

  */

  createContent : function(oController) {

  var oMatrix = new sap.ui.commons.layout.MatrixLayout({

  id : 'matrix4',

  layoutFixed : true,

  width : '1000px',

  //columns : 5,

  // widths : ['150px', '250px'],

  hAlign: "Center"});

 

 

  var oCell = new sap.ui.commons.layout.MatrixLayoutCell({

  // colSpan: 5,

  hAlign: "Center"

  });

 

 

// var oTV = new sap.ui.commons.TextView({

// id : 'TV-Head',

// text : 'Search report',

// design : sap.ui.commons.TextViewDesign.H3,

// });

 

 

 

 

  // oCell.addContent(oTV);

  // oMatrix.createRow(oCell);

 

 

  oCell = new sap.ui.commons.layout.MatrixLayoutCell();

  oCell1 = new sap.ui.commons.layout.MatrixLayoutCell({

  // rowSpan : 10

  });

 

  oMatrix.createRow( oCell, oCell1);

  oLabel = new sap.ui.commons.Label({

  id : 'L-Object',

  text : 'Object Type' }).setDesign(sap.ui.commons.LabelDesign.Bold);

 

 

  oLabel.addStyleClass("myPanel");

 

 

  oCB = new sap.ui.commons.ComboBox({

  id : 'TF-Object',

  tooltip : 'What Object are you looking',

 

  value : '',

  width: "16em" });

 

  oLabel.setLabelFor(oCB);

 

  var oItem = new sap.ui.core.ListItem({

  id : 'LI1',

  text : 'CO' });

 

  oCB.addItem(oItem);

 

  var oItem = new sap.ui.core.ListItem({

  id : 'LI2',

  text : 'Premise' });

 

  oCB.addItem(oItem);

 

  var oItem = new sap.ui.core.ListItem({

  id : 'LI3',

  text : 'Contract' });

  oCB.addItem(oItem);

  var oItem = new sap.ui.core.ListItem({

  id : 'LI4',

  text : 'Installation' });

 

  oCB.addItem(oItem);

  oMatrix.createRow(oLabel, oCB);

 

 

  oLabel = new sap.ui.commons.Label({

  id : 'Changed-byid',

  text : 'Changed By' }).setDesign(sap.ui.commons.LabelDesign.Bold);

 

 

  oLabel.addStyleClass("myPanel");

 

  oTF = new sap.ui.commons.TextField({

  id : 'TF-Changed',

  width: "16em",

  tooltip : 'Who Changed?',

 

  value : ''

  });

 

 

  oLabel.setLabelFor(oTF);

  oMatrix.createRow(oLabel, oTF);

 

 

 

 

  oLabel1 = new sap.ui.commons.Label({

  id : 'datelabelid1',

  text : 'Date From' }).setDesign(sap.ui.commons.LabelDesign.Bold);

 

 

  oLabel1.addStyleClass("myPanel");

 

  oDP1 = new sap.ui.commons.DatePicker({

  id : 'dateinputid1',

  width: "16em",

  tooltip : 'Search by date',

         pattern : "MM/dd/yy"

  });

 

 

  oLabel1.setLabelFor(oDP1);

  oMatrix.createRow(oLabel1, oDP1, oCell);

 

 

 

  oLabel2 = new sap.ui.commons.Label({

  id : 'datelabelid2',

  text : 'Date To' }).setDesign(sap.ui.commons.LabelDesign.Bold);

 

  oLabel2.addStyleClass("myPanel");

 

 

      oDP2 = new sap.ui.commons.DatePicker({

  id : 'dateinputid2',

  width: "16em",

  tooltip : 'Search by date'

 

  });

    

 

  oLabel2.setLabelFor(oDP2);

  oMatrix.createRow(oLabel2, oDP2, oCell);

 

 

 

 

  oLabel3 = new sap.ui.commons.Label({

  id : 'datetimeid1',

  text : 'Time From' }).setDesign(sap.ui.commons.LabelDesign.Bold);

 

  oLabel3.addStyleClass("myPanel");

 

  var oType = new sap.m.DateTimeInput({

  id: "timeid1",

  width: "16em",

 

  type: "Time"

  });

 

 

  oLabel3.setLabelFor(oType);

  oMatrix.createRow(oLabel3,oType);

 

 

 

 

  oLabel4 = new sap.ui.commons.Label({

  id : 'datetimeid2',

  text : 'Time To' }).setDesign(sap.ui.commons.LabelDesign.Bold);

 

 

 

 

  var oType = new sap.m.DateTimeInput({

  id: "timeid2",

  width: "16em",

 

  type: "Time"

  });

  oLabel4.setLabelFor(oType);

  oMatrix.createRow(oLabel4,oType);

 

  oLabel = new sap.ui.commons.Label({

  id: "noid",

  text: ""

  });

 

 

 

  var oButton2 = new sap.ui.commons.Button({

  id : 'searchid',

  tooltip : "Press this button to search. But as long as we don't know where to search the data is not really searched.",

  text : 'Search',

  width : '16em',

  press : function()

  {

  oController.search();

  }

  });

 

 

 

 

  oLabel.setLabelFor(oButton2);

  oMatrix.createRow(oLabel,oButton2);

 

 

 

  oMatrix.addStyleClass("myPanel");

 

  oPage = new sap.m.Page({

  title: "Metropolitan Utilities District of Omaha",

  showHeader: true,

  showFooter: true,

  content: [oMatrix]

  });

               

  //oPage.addStyleClass("myPanel");

 

  return oPage;

 

      

  }

 

 

 

 

});

 

 

 

Controller2:

 

sap.ui.controller("ajax.Sample", {

 

 

/**

* Called when a controller is instantiated and its View controls (if available) are already created.

* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.

* @memberOf ajax.Sample

*/

// onInit: function() {

//

// },

 

 

/**

* Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered

* (NOT before the first rendering! onInit() is used for that one!).

* @memberOf ajax.Sample

*/

// onBeforeRendering: function() {

//

// },

 

 

/**

* Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here.

* This hook is the same one that SAPUI5 controls get after being rendered.

* @memberOf ajax.Sample

*/

// onAfterRendering: function() {

//

// },

 

 

/**

* Called when the Controller is destroyed. Use this one to free resources and finalize activities.

* @memberOf ajax.Sample

*/

// onExit: function() {

//

// }

  initModel : function() { 

  

    var Object    =  sap.ui.getCore().getElementById('TF-Object').getValue();

  var changedBy =  sap.ui.getCore().getElementById('TF-Changed').getValue();

// var dateFrom  =  sap.ui.getCore().getElementById('dateinputid1').getValue();

// var dateTo    =  sap.ui.getCore().getElementById('dateinputid2').getValue();

// var timeFrom  =  sap.ui.getCore().getElementById('timeid1').getValue();

// var timeTo    =  sap.ui.getCore().getElementById('timeid2').getValue();

  

  

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

         var aData = jQuery.ajax({

             type : "GET",

             contentType : "application/json",

             url: "http://sagslh21.mudomaha.com:8030/sap/opu/data/sap/YZ_AUDIT_SRV_02/FormSetSet/?$filter=ChangedBy eq "+changedBy+" and ObjectType eq "+Object+"&$format=json",

         //    url : "http://sagslh21.mudomaha.com:8030/sap/opu/odata/sap/YZ_AUDIT_SRV_02/FormSetSet/?$filter=ChangedBy eq 'E1069996' and ObjectType eq 'CO' and DateFrom eq datetime'2015-11-16T01:00:00' and DateTo eq datetime'2015-11-16T02:00:00'&$format=json",

             dataType : "json",

             async: false,

             success : function(data,textStatus, jqXHR) {

                 oModel.setData({modelData : data});

                 //alert(data);

             }

 

 

         });

    //     sap.ui.getCore().byId("tableid").getModel().refresh(true);

 

 

         return oModel; 

   },

  

   onNavigation: function(){

  app = sap.ui.getCore().byId("appid");

  app.to("idInput");

 

  }

 

 

});

 

 

Final view --> View2

 

sap.ui.jsview("ajax.Sample", {

 

 

  /** Specifies the Controller belonging to this View.

  * In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.

  * @memberOf ajax.Sample

  */

  getControllerName : function() {

  return "ajax.Sample";

  },

 

 

  /** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed.

  * Since the Controller is given to this method, its event handlers can be attached right away.

  * @memberOf ajax.Sample

  */

 

 

  createContent : function(oController) {

 

  var model = oController.initModel();

  var json = model.getJSON();

  var jsonObj = JSON.parse(json);

 

 

  for(i in jsonObj.modelData.d.results[0]){

  console.log(i+": "+ jsonObj.modelData.d.results[0][i]);

  }

 

  var resultsData = jsonObj.modelData.d.results;

 

  //create JSON model

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

  oModel.setData({modelData: resultsData});

 

  var oTable = sap.ui.table.Table("tableid",{

  visibleRowCount: resultsData.length,

  editable: false

  });

 

 

  oTable.addColumn(new sap.ui.table.Column({

  label: new sap.ui.commons.Label({text:"User Name"}),

  visible: true,

  template: new sap.ui.commons.TextField().bindProperty("value", "Username")

  }));

  oTable.addColumn(new sap.ui.table.Column({

  label: new sap.ui.commons.Label({text:"Date To"}),

  visible: true,

  template: new sap.ui.commons.TextField().bindProperty("value", "Udate")

  }));

  oTable.addColumn(new sap.ui.table.Column({

  label: new sap.ui.commons.Label({text:"Time"}),

  visible: true,

  template: new sap.ui.commons.TextField().bindProperty("value", "Utime")

  }));

  oTable.addColumn(new sap.ui.table.Column({

  label: new sap.ui.commons.Label({text:"New Value"}),

  visible: true,

  template: new sap.ui.commons.TextField().bindProperty("value", "FNew")

  }));

  oTable.addColumn(new sap.ui.table.Column({

  label: new sap.ui.commons.Label({text:"Old Value"}),

  visible: true,

  template: new sap.ui.commons.TextField().bindProperty("value", "F Old")

  }));

  oTable.addColumn(new sap.ui.table.Column({

  label: new sap.ui.commons.Label({text:"Lastname"}),

  visible: true,

  template: new sap.ui.commons.TextField().bindProperty("value", "Lastname")

  }));

 

 

 

  oTable.setModel(oModel);

  oTable.bindRows("/modelData");

 

 

 

     return [ oTable ];

  oModel.refresh(true);

 

  }

 

 

});

 

 

 

 

Should I delete 1 controller? If yes, then which one so that flow doesn't break?

 

Frank - I can call my data directly into controller 2 isn't it? I have experienced it before.

 

 

Model with the hard-coded values is working fine but I want it to be dynamic and take values from view1.

Thanks for help.


Viewing all articles
Browse latest Browse all 2740

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>