cancel
Showing results for 
Search instead for 
Did you mean: 

Navigation between xml views

Former Member
0 Kudos

Hi Guys,

I have 3 XML views. The first one is a login screen, followed by two other screens. In successful login i want to navigate to the second xml which is a splitapp view. My manifest.json code is attached for the reference.

On pressing the login button it should navigate to SplitApp view. The controller code is also attached which I have tried for navigation.

Still I am not able to navigate to the other page. When this code is added I get an error saying "navTo is not a function". Please provide your suggestions, it is an immediate requirement.

I have followed the below discussions, but still not able to navigate.

1.

2.

3. SAPUI5 SDK - Demo Kit

Thanks,

Srinivasan

Accepted Solutions (0)

Answers (2)

Answers (2)

jamie_cawley
Advisor
Advisor
0 Kudos

To get access to the router try using

var oRouter = this.getOwnerComponent().getRouter();

and correct the case of the target

oRouter.navTo("splitapp");

Regards,

Jamie

SAP - Technology RIG

Former Member
0 Kudos

Hi Jamie,

I have tried your code. I am able to see the that the it goes to my controller from the console but the xml does not get replaced with the new view.

Regards,

Srinivasan

vijay_kumar49
Active Contributor
0 Kudos

Please refer the example code. it should be useful.


Application Structure :


Index.html

<!DOCTYPE HTML>

<html>

    <head>

        <meta http-equiv="X-UA-Compatible" content="IE=edge">

        <meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

        <script src="resources/sap-ui-core.js"

                id="sap-ui-bootstrap"

                data-sap-ui-libs="sap.m"

                data-sap-ui-theme="sap_bluecrystal">

        </script>

        <!-- only load the mobile lib "sap.m" and the "sap_bluecrystal" theme -->

        <script>

                sap.ui.localResources("sapui5_navigation_xml");

                var appPage = sap.ui.view({

                    id:"idApp",

                    viewName:"sapui5_navigation_xml.AppView",

                    type:sap.ui.core.mvc.ViewType.JS});   

               

                appPage.placeAt("content");

        </script>

    </head>

    <body class="sapUiBody" role="application">

        <div id="content"></div>

    </body>

</html>


AppViewView.Js

sap.ui.jsview("sapui5_navigation_xml.AppView", {

    /** 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 sapui5_navigation_xml.AppView

    */

    getControllerName : function() {

        return "sapui5_navigation_xml.AppView";

    },

    /** 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 sapui5_navigation_xml.AppView

    */

    createContent : function(oController) {

       

        var app = new sap.m.App("myApp",{initialPage:"idfirstView1"});       

        var page = sap.ui.view({id:"idfirstView1", viewName:"sapui5_navigation_xml.firstView", type:sap.ui.core.mvc.ViewType.XML});       

        var secpage = sap.ui.view({id:"idsecondView", viewName:"sapui5_navigation_xml.secondView", type:sap.ui.core.mvc.ViewType.XML});       

        var thrPage = sap.ui.view({id:"idThrView", viewName:"sapui5_navigation_xml.thirdView", type:sap.ui.core.mvc.ViewType.XML});

       

        app.addPage(page);

        app.addPage(secpage);

        app.addPage(thrPage);   

       

        return app;

       

         /*return new sap.m.Page({

            title: "App View",

            content: [app]

        });*/

    }

});


AppView.controller.js

No code required Here


firstView.view.xm

<Page title="Welcome to First View">

        <content>

        <Input id="usrId" placeholder="user name"/>

        <Input ip="pwdId" placeholder="password" type="Password"/>       

        </content>

       

        <footer>

       

        <Bar>

        <contentMiddle>

        <Button xmlns="sap.m" id="id" type="Accept" text="Login" width="10%" icon="" press="oNavigationLog"/>

        <BusyDialog xmlns="sap.m" id="BusyDialogId" busy="true" busyIndicatorDelay="1000"

                    visible="true" text="Hello Text" title="Hello Tittle"     close="">

        </BusyDialog>

        </contentMiddle>

        </Bar>       

       

        </footer>

       

    </Page>

firstView.controller.js

sap.ui.controller("sapui5_navigation_xml.firstView", {

/**

* 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 sapui5_navigation_xml.firstView

*/

    oNavigationLog:function(){      

        sap.ui.getCore().byId("myApp").to("idsecondView","flip");       

    }

secondView.view.xml

<Page title="Second View" showNavButton="true" navButtonPress="oNavigationBackFirstView">

        <content>

        </content>

       

        <footer>

            <Bar>

                <contentMiddle>

                    <Button xmlns="sap.m" id="secId" type="Accept" text="Go 3rd View"

                        width="10%" icon="" press="oNavigationto3rd" />

                </contentMiddle>

            </Bar>

        </footer>

    </Page>


secondView.controller.js


sap.ui.controller("sapui5_navigation_xml.secondView", {

/**

* 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 sapui5_navigation_xml.secondView

*/

    oNavigationBackFirstView:function(){

        //app.to(page);

        //sap.ui.getCore().byId("mainApp").to("page");

        sap.ui.getCore().byId("myApp").back();

    },

    oNavigationto3rd:function(){

        //app.to(thrPage);       

        //app.back(); // Back to Navigation View

        sap.ui.getCore().byId("myApp").to("idThrView");

    } 

});



Kindly let me know if you need any more information

Former Member
0 Kudos

Hi Srinivasan,

Can you please share your code on Create a new Gist · GitHub as it's not always possible to fetch and open code from zip.

Regards,

Devaarth

Former Member
0 Kudos

Hi Devaarth,

Codes for SCN Discussion · GitHub

The code is shared in the above link for your reference.

Thanks,

Srinivasan