cancel
Showing results for 
Search instead for 
Did you mean: 

Data not getting displayed in second view in UI5

Former Member
0 Kudos

Hi Gurus,

I am facing few issue in developing an application in UI5 for which i need some help.

1. When i am navigating from first view(input.view.xml) to second view(plant.view.xml) data is not getting displayed from local json file.

2. I cannot navigate back from second view to first view and also not getting any error in developer console.Please find the attached code for your reference.

Plant.view.xml

<mvc:View
   controllerName="stock.controller.plant"
   xmlns="sap.m"
   xmlns:viz="sap.viz.ui5.controls"
   xmlns:l="sap.ui.layout"
   xmlns:mvc="sap.ui.core.mvc">
   <MessagePage
      showNavButton="true"
      navButtonPress="onNavBack"/>
      
    <Table id="idProductsTable"
        inset="false"
        items="{
            path: '/ProductCollection',
            sorter: {
                path: 'Name'
            }
        }">
        <headerToolbar>
            <Toolbar>
                <Title text="Products" level="H2"/>
            </Toolbar>
        </headerToolbar>
        <columns>
            <Column
                width="12em">
                <Text text="Product" />
            </Column>
            <Column
                minScreenWidth="Tablet"
                demandPopin="true">
                <Text text="Supplier" />
            </Column>
            <Column
                minScreenWidth="Tablet"
                demandPopin="true"
                hAlign="End">
                <Text text="Dimensions" />
            </Column>
            <Column
                minScreenWidth="Tablet"
                demandPopin="true"
                hAlign="Center">
                <Text text="Weight" />
            </Column>
            <Column
                hAlign="End">
                <Text text="Price" />
            </Column>
        </columns>
        <items>
            <ColumnListItem>
                <cells>
                    <ObjectIdentifier
                        title="{Name}"
                        text="{ProductId}"/>
                    <Text
                        text="{SupplierName}" />
                    <Text
                        text="{Width} x {Depth} x {Height} {DimUnit}" />
                    <ObjectNumber
                        number="{WeightMeasure}"
                        unit="{WeightUnit}"
                        state="{
                            parts: [
                                {path: 'WeightMeasure'},
                                {path: 'WeightUnit'}
                            ],
                            formatter: 'stock.Formatter.weightState'
                        }" />
                    <ObjectNumber
                            number="{
                                parts:[{path:'Price'},{path:'CurrencyCode'}],
                                type: 'sap.ui.model.type.Currency',
                                formatOptions: {showMeasure: false}
                            }"
                            unit="{CurrencyCode}" />
                </cells>
            </ColumnListItem>
        </items>
    </Table>            
</mvc:View>

Plant.controller.js

sap.ui.define([
    'sap/ui/core/mvc/Controller',
    'jquery.sap.global',
    'stock/Formatter',
    'sap/ui/core/routing/History',
    'sap/ui/model/json/JSONModel'
], function (Controller, jQuery, Formatter, History,JSONModel) {
    "use strict";
    var TableController =  Controller.extend("stock.controller.plant", {
        
        onInit: function () {
            // set explored app's demo model on this sample
            var oModel = new JSONModel(jQuery.sap.getModulePath("sap.ui.demo.mock", "/products.json"));
            this.getView().setModel(oModel);
        },
        
        getRouter : function () {
            return sap.ui.core.UIComponent.getRouterFor(this);
        },
        
        
        onNavBack: function () {
            var oHistory, sPreviousHash;
            oHistory = History.getInstance();
            sPreviousHash = oHistory.getPreviousHash();
            if (sPreviousHash !== undefined) {
                window.history.go(-1);
            } else {
                this.getRouter().navTo("input", {}, true);
            }
        }
    });
    return TableController;
});

Manifest.json

{
  "_version": "1.1.0",
  "sap.app": {
    "_version": "1.1.0",
    "id": "stock",
    "type": "application",
    "i18n": "i18n/i18n.properties",
    "title": "{{appTitle}}",
    "description": "{{appDescription}}",
    "applicationVersion": {
      "version": "1.0.0"
    }
  },
  "sap.ui": {
    "_version": "1.1.0",
    "technology": "UI5",
    "deviceTypes": {
      "desktop": true,
      "tablet": true,
      "phone": true
    },
    "supportedThemes": [
      "sap_belize"
    ]
  },
"sap.ui5": {
    "_version": "1.1.0",
    "rootView": "stock.view.input",
    "dependencies": {
      "minUI5Version": "1.30",
      "libs": {
        "sap.m": {}
      }
    },  
  
    "models": {
      "i18n": {
        "type": "sap.ui.model.resource.ResourceModel",
        "settings": {
          "bundleName": "stock.i18n.i18n"
        }
      }
    },
    "routing": {
            "config": {
                "routerClass": "sap.m.routing.Router",
                "viewType": "XML",
                "viewPath": "stock.view",
                "controlId": "app",
                "controlAggregation": "pages",
                "transition": "slide",
                "bypassed": {
                    "target": [
                        "notFound"
                    ]
                },
                "async": true
            },
            "routes": [
                 {
                "pattern": "",
                "name": "input",
                "target": "input"
                },
                
                {        
                    "pattern": "plant",
                    "name": "plant",
                    "target": "plant"
                }
            ],
            "targets": {                                
                    "input": {
                    "viewName": "input",
                    "viewId": "App",
                    "viewLevel" : 1
                },
                
                    "plant": {
                    "viewName": "plant",
                    "viewId": "plant",
                    "viewLevel": 2,
                    "title": "{i18n>materialDetail}"
                }
            }
        }    
    }
 }

Component.js

sap.ui.define(["sap/ui/core/UIComponent",
    "sap/ui/core/mvc/XMLView",
    "sap/ui/model/json/JSONModel"],
    function(UIComponent,JSONModel,XMLView) {
    "use strict";

    var Component = UIComponent.extend("stock.Component", {

        metadata : {
        manifest: "json",
            getTable : function () {
                return this._rootView.getContent()[0];
            }
                },
                publicMethods : [
                    "getTable"
                ],
                dependencies : {
                    libs : [
                        "sap.m",
                        "sap.ui.layout"
                    ]
                },
                
            rootView : "stock.view.input",
            config : {
                sample : {
                    files : [
                        "view.input.view.xml",
                        "controller.main.controller.js",
                        "Formatter.js"
                        // "Dialog.fragment.xml"
                    ],
                    description : "In this example assisted input is provided with table-like suggestions where several columns can display more details."
                }
            },
    
    init : function () {
        // call the init function of the parent
        UIComponent.prototype.init.apply(this, arguments);
           this.getRouter().initialize();
    }
    });
    
    Component.prototype.createContent = function () {
        this._rootView = sap.ui.xmlview({ viewName : "stock.view.input" });
        return this._rootView;
    };

    return Component;
});
Former Member
0 Kudos

Hi All,

Can anyone please provide some help on the above issue.

Regards,

Ajay

Accepted Solutions (0)

Answers (0)