0
votes

i'm working in a project on a master/detail template, i created a button in my Master.view.xml, i'm still new to SAPUI5 and SAP Web IDE developement, when i click the button nothing happens actually, even thought when i debugg on chrome, i find no errors,here is my Master.view.xml

<sap.ui.layout:content>
                <Button text="Ajouter" enabled="{appView&gt;/addEnabled}" width="100px" id="addButton" icon="sap-icon://add" press="onAdd" activeIcon="sap-icon://accept"/>
            </sap.ui.layout:content>

this is my Master Controller Method:

onAdd : function(){     
        this.getRouter().getTargets().display("create");    
                  },

this is my Component.js routing

    routing: {

        config: {
            routerClass: com.emi.MyRouter,
            viewType: "XML",
            viewPath: "com.emi.view",
            targetAggregation: "detailPages",
        //  controlId: "idAppControl",
        //  targetControl: "idAppControl",
            controlAggregation: "detailPages",
            clearTarget: false
        },
        routes: [




            {
                pattern: "",
                name: "main",
                view: "Master",
                targetAggregation: "masterPages",
                targetControl: "idAppControl",
                subroutes: [
                    {
                        pattern: "{entity}/:tab:",
                        name: "detail",
                        view: "Detail"

                    }
                    , {
                        pattern: "{entity}/:tab:/{item}",
                        name: "userDetails",
                        view: "UserDetails"
                        },
                            {
                        pattern: "create",
                        name: "createEntity",
                        view: "CreateEntity",
                        target: "create"
                        }


                ]
            },


            {
                name: "catchallMaster",
                view: "Master",
                targetAggregation: "masterPages",
                targetControl: "idAppControl",
                subroutes: [
                    {
                        pattern: ":all*:",
                        name: "catchallDetail",
                        view: "NotFound",
                        transition: "show"
                    }
                ]

            }
        ],
        targets:    {
            master: {
                viewName: "Master",
                viewLevel: 1,
                viewId: "master",
                controlAggregation: "masterPages"
            //  controlId: "idAppControl"
            },
            object: {
                viewName: "Detail",
                viewId: "detail",
                viewLevel: 2
            },
            create: {
               // viewPath: "sap.ui.com.emi.view.CreateEntity",
                viewName: "CreateEntity",
                targetAggregation: "pages",
                viewLevel: 1,
                controlAggregation: "detailPages",
                transition: "show",
                controlId:"idAppControl"

            }   
            }


    }

    },

and finaly this is my oninit method, in CreateEntity.Controller.js

onInit: function() {

  var oRouter, oTarget;
        oRouter = this.getRouter();
        oTarget = oRouter.getTargets().getTarget("create");


},

but when i click the button, nothing happens, and when i debugg code i find there are no errors, which means my view is there but not displayed. i doubt there is a problem in my oninit function, can u help me please ? Thank YOU

1
Did you do the tutorial on routing or just copy paste some code from the web?Marc
I did follow the tutorial on routing, and did copy some code on oninit functionMETTAIBI
If you put a breakpoint on the onAdd method. does it stop?Tiago A.

1 Answers

1
votes

Please do the following:

Ensure that the onAdd event is being triggered by an alert alert("reached the onAdd event"); for example at the beginning of the onAdd event.

If the onAdd event is being fired then your navigation should be done using the .getRouter().navTo("create"); command. For correct usage of the oRouter.getTargets().getTarget("create"); please refer to Step 5 of the Binding walkthrough

Finally your routing config is best pushed into your manifest.json. That said the routes section should only have the following properties: pattern, name and target. in your case:

pattern: "create",
name: "createEntity",
target: "create"

You will also need to adjust the other entries - refer again to the navigation walkthrough linked to above.

Finally your targets section could read very simply as below:

"createEntity": {
    "viewPath": "com.emi.view.CreateEntity",
    "viewName": "CreateEntity",
      "viewLevel" : 2

Hope this helps. Highly recommend doing the walkthrough provided by SAP linked to above!!!