cancel
Showing results for 
Search instead for 
Did you mean: 

Error in Eclipse while reading NW service

ricky_shaw
Contributor
0 Kudos

Hello Experts, I developed a web service in the backend(SAP). I am planning to use the READ(GET) operation in the SAP UI5 application. However, i got stuck up at an issue which says " Uncaught Error: failed to load 'Zempcrud/EmpDetails.view.js' from ./Zempcrud/EmpDetails.view.js: SyntaxError: Illegal return statement I used an MVC approach and my view name is : EmpDetails and my project name is ZEMPCRUD. I followed the steps as shown in link "http://scn.sap.com/docs/DOC-61821#comment-583702" Can someone tell me what wrong did i do and where to correct it? Thanks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hey, index.html cannot find your view as far as i can understand. The view name in that example is ; empcrud.EmpDetails.The view EmpDetails in empcrud  root folder, is it same in your project. Can you share us your project structure.

ricky_shaw
Contributor
0 Kudos

Failed to load error:

ricky_shaw
Contributor
0 Kudos

Hi Adem, I tried now with a new name altogether. Can you please see the screens below & suggest.

Private_Member_15166
Active Contributor
0 Kudos

Hi,

As i see in your first screen, i am only able to see your index.html. There is no file of controller and views. This means it is not being loaded. This happens if there is some syntax errors in code or wrong returns.

There is some wrong code in your view or there is illegal return or may be your name is different of view.

It would be better to suggest if you share your code agter hiding the important one.

Regards

Dhananjay

Former Member
0 Kudos

Can you check your empDetail view, it looks like it has a syntax error.

ricky_shaw
Contributor
0 Kudos

Hi Dhanajay & Adem,

This is the piece of code that i have in my Index &View

Coding lines 1 -10 in View :

sap.ui.jsview("zhk_ui5_empcrud.EmpDetails", {

return "zhk_ui5_empcrud.EmpDetails"; },

Index Screen shot:

Please suggest .

Private_Member_15166
Active Contributor
0 Kudos

Hey Ricky,

Error is not in index.html.

Error is in your view.

It would be better if you share the code of your view.

Regards

Dhananjay

ricky_shaw
Contributor
0 Kudos

Hi Dhananjay,

Please see the attached screen of my view. As other lines are irrelevant I am posting a screen shot of first few lines here .

I am point an  arrow at the return statement to ask if this is the place where is causing the error?

Also please note that this project is not fully shared to the back end(SAP). Is that  causing to stop show?

Private_Member_15166
Active Contributor
0 Kudos

Hi,

In Table i see that you have defined itemPress event as an aggregation but this is an event.

So here is one error.

you can write this as

itemPress: oController.ItemPress,

or you may pass your controller as well by writing

itemPress: function(oController){                        

oController.ItemPress;

},

No that return is not an error.

The return you are making below to view may be error means you may be returning somthing from content like this.

       createContent : function(oController) {

              var oText = new sap.ui.commons.TextView({

                     text: "Enter your name:"

              });

             

              var oInput = new sap.ui.commons.TextField(this.createId("nameId"),{

                           value: "Dhananjay Choubey"

              });

             

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

                     text: "Submit",

                     press: function(){

                           oController.navigateToView2("view2");

                     }

              });

             

              var ele = [ oText, oInput, oButton ];

             

              return ele;

       }


I am talking about this return return ele;


There may be some more code errors if this doesn't help.


Best Regards

Dhananjay

ricky_shaw
Contributor
0 Kudos

SDhananjay, I am trying to paste the whole code but the format is getting messed up.

Would you mind taking a look at the link "http://scn.sap.com/docs/DOC-61821#comment-583702". Here you just  look at section 3.13 ONLY -"Create a Dashboard for Employee details display". Sorry, to bother you so much.

Private_Member_15166
Active Contributor
0 Kudos

Hi,

Write this code in view and check it's working.

       createContent : function(oController) {

              var oPage = new sap.m.Page({ title : "Employee Details" }); // Table or Dashboard to show Employee Data

              var oTable = new sap.m.Table({

// id : "Employees",

               itemPress : [ oController.ItemPress, oController ],

              columns : [

              new sap.m.Column({

              width: "1em",

              header: new sap.m.Label({ text : "Emp ID"  })

               }),

              new sap.m.Column({

              width: "1em",

              header: new sap.m.Label({ text : "Name"  })

               }),

               new sap.m.Column({

               width: "1em",

               header: new sap.m.Label({ text : "Address"  })

              }),

               new sap.m.Column({

               width: "1em",

               header: new sap.m.Label({ text : "Designation"  })

               }), ]

              });

              oPage.addContent(oTable);

              return oPage;

}



Also don't forget to write this code in controller.


sap.ui.controller("demo11.EmpDetails", {

  itemPress: function(oController){

  }

});

Regards

Dhananjay

Private_Member_15166
Active Contributor
0 Kudos

This is your whole code in view and it's working.

       createContent : function(oController) {

              var oPage = new sap.m.Page({ title : "Employee Details" }); // Table or Dashboard to show Employee Data

              var oTable = new sap.m.Table({

// id : "Employees",

               itemPress : [ oController.ItemPress, oController ],

              columns : [

              new sap.m.Column({

              width: "1em",

              header: new sap.m.Label({ text : "Emp ID"  })

               }),

              new sap.m.Column({

              width: "1em",

              header: new sap.m.Label({ text : "Name"  })

               }),

               new sap.m.Column({

               width: "1em",

               header: new sap.m.Label({ text : "Address"  })

              }),

               new sap.m.Column({

               width: "1em",

               header: new sap.m.Label({ text : "Designation"  })

               }), ]

              });

       //Template  to map the data to the respective column     

              var template = new sap.m.ColumnListItem({ 

                     id: "first_template",

                     type: "Navigation",

                     visible: true,

                     cells: [

                             new sap.m.Label("ID", {

                                   text: "{Empid}"               

                                          }),

                             new sap.m.Label({    

                                   text: "{Empname}"

                                          }),              

                             new sap.m.Label({           

                                   text: "{Empadd}"          

                                          }),             

                             new sap.m.Label({       

                                   text: "{Empdes}"

                                          })

                             ]

              });

              var oFilters = null;

              oTable.bindItems("/results",template,null,oFilters);

              oPage.addContent(oTable);

              return oPage;

}


Private_Member_15166
Active Contributor
0 Kudos

Ricky Sh wrote:

SDhananjay, I am trying to paste the whole code but the format is getting messed up.

Copy your code first and paste it to word then copy from word document and paste it here.

It will not messed up.

ricky_shaw
Contributor
0 Kudos

Oh!...I am sorry.. I missed it altogether..I I really thank you so much Dhananjay..

• sap.ui.jsview("zhk_ui5_empcrud.EmpDetails", { • • /** 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 zhk_ui5_empcrud.EmpDetails • */ • getControllerName : function() { • return "zhk_ui5_empcrud.EmpDetails"; • }, • • /** 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 zhk_ui5_empcrud.EmpDetails • */ • createContent : function(oController) { • var oPage = new sap.m.Page({ • title : "Employee Details", • }); • // Table or Dashboard to show Employee Data • var oTable = new sap.m.Table({ • id : "Employees", • itemPress : [ oController.ItemPress,oController ], • columns : [ • new sap.m.Column({ • width: "1em", • header: new sap.m.Label({ • text : "Emp ID"  }) }), • new sap.m.Column({ • width: "1em", • header: new sap.m.Label({ • text : "Name"  }) }), • new sap.m.Column({ • width: "1em", • header: new sap.m.Label({ • text : "Address"  }) }), • new sap.m.Column({ • width: "1em", • header: new sap.m.Label({ • text : "Designation"  }) }), •             ] • }) • • } • • }); • • //Template  to map the data to the respective column      • • var template = new sap.m.ColumnListItem({ • •               id: "first_template", •               type: "Navigation", •             visible: true, •               cells: [ •               new sap.m.Label("ID", { •               text: "{Empid}" •                 }), • •               new sap.m.Label({ •               text: "{Empname}" •                       }), • •               new sap.m.Label({ •               text: "{Empadd}" •                 }), • •               new sap.m.Label({ •               text: "{Empdes}" •                 }) •                 ]      • • }); • • var oFilters = null; • oTable.bindItems("/results",template,null,oFilters); • oPage.addContent(oTable); • return oPage;

Private_Member_15166
Active Contributor
0 Kudos

your code is resolved now??

ricky_shaw
Contributor
0 Kudos

No. its NOT resolved..i am thanking for your sincere efforts for me  🙂

Are you able to see the code clearly..?

former_member182372
Active Contributor
0 Kudos

error clearerly says - syntax error in EmpDetails.view.js

post code here and we tell you whats wrong right away

ricky_shaw
Contributor
0 Kudos

Hey Maksim, Please see the code below: For some reason the advanced editor here is messing up the format. sap.ui.jsview("zhk_ui5_empcrud.EmpDetails", { /** 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 zhk_ui5_empcrud.EmpDetails */ getControllerName : function() { return "zhk_ui5_empcrud.EmpDetails"; }, /** 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 zhk_ui5_empcrud.EmpDetails */ createContent : function(oController) { var oPage = new sap.m.Page({ title : "Employee Details", }); // Table or Dashboard to show Employee Data var oTable = new sap.m.Table({ id : "Employees", itemPress : [ oController.ItemPress,oController ], columns : [ new sap.m.Column({ width: "1em", header: new sap.m.Label({ text : "Emp ID"  }) }), new sap.m.Column({ width: "1em", header: new sap.m.Label({ text : "Name"  }) }), new sap.m.Column({ width: "1em", header: new sap.m.Label({ text : "Address"  }) }), new sap.m.Column({ width: "1em", header: new sap.m.Label({ text : "Designation"  }) }),             ] }) } }); //Template  to map the data to the respective column      var template = new sap.m.ColumnListItem({               id: "first_template",               type: "Navigation",             visible: true,               cells: [               new sap.m.Label("ID", {               text: "{Empid}"                 }),               new sap.m.Label({               text: "{Empname}"                       }),               new sap.m.Label({               text: "{Empadd}"                 }),               new sap.m.Label({               text: "{Empdes}"                 })                 ]      }); var oFilters = null; oTable.bindItems("/results",template,null,oFilters); oPage.addContent(oTable); return oPage;

ricky_shaw
Contributor
0 Kudos

sap.ui.jsview("zhk_ui5_empcrud.EmpDetails", { /** 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 zhk_ui5_empcrud.EmpDetails */ getControllerName : function() { return "zhk_ui5_empcrud.EmpDetails"; }, /** 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 zhk_ui5_empcrud.EmpDetails */ createContent : function(oController) { var oPage = new sap.m.Page({ title : "Employee Details", }); // Table or Dashboard to show Employee Data var oTable = new sap.m.Table({ id : "Employees", itemPress : [ oController.ItemPress,oController ], columns : [ new sap.m.Column({ width: "1em", header: new sap.m.Label({ text : "Emp ID"  }) }), new sap.m.Column({ width: "1em", header: new sap.m.Label({ text : "Name"  }) }), new sap.m.Column({ width: "1em", header: new sap.m.Label({ text : "Address"  }) }), new sap.m.Column({ width: "1em", header: new sap.m.Label({ text : "Designation"  }) }),            ] }) } }); //Template  to map the data to the respective column      var template = new sap.m.ColumnListItem({              id: "first_template",              type: "Navigation",              visible: true,              cells: [              new sap.m.Label("ID", {                text: "{Empid}"                  }),              new sap.m.Label({                text: "{Empname}"                        }),              new sap.m.Label({                text: "{Empadd}"                  }),              new sap.m.Label({              text: "{Empdes}"                })                ]      }); var oFilters = null; oTable.bindItems("/results",template,null,oFilters); oPage.addContent(oTable); return oPage;

Also same code is in attached document.

Private_Member_15166
Active Contributor
0 Kudos

You have some irrelevant closing tags means ")" and this "})".

I have commented it.

• sap.ui.jsview("zhk_ui5_empcrud.EmpDetails", { • • /** 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 zhk_ui5_empcrud.EmpDetails • */ • getControllerName : function() { • return "zhk_ui5_empcrud.EmpDetails"; • }, • • /** 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 zhk_ui5_empcrud.EmpDetails • */


This will be code after this.


      createContent : function(oController) {

             var oPage = new sap.m.Page({

                   title : "Employee Details",  });

             // Table or Dashboard to show Employee Data •

             var oTable = new sap.m.Table({

                   id : "Employees",

                   itemPress : [ oController.ItemPress,oController ],

                   columns : [

                              new sap.m.Column({

                                    width: "1em",

                                    header: new sap.m.Label({ text : "Emp ID" })

                              }),

                              new sap.m.Column({

                                    width: "1em",

                                    header: new sap.m.Label({ text : "Name"  })

                              }),

                              new sap.m.Column({

                                    width: "1em",

                                    header: new sap.m.Label({ text : "Address" })

                              }),

                              new sap.m.Column({

                                    width: "1em",

                                    header: new sap.m.Label({

                                          text : "Designation"  })

                              }),

                              ]

//          })         // Comment This

//          }                // Comment This

      });

//Template  to map the data to the respective column     

            var template = new sap.m.ColumnListItem({

                  id: "first_template",

                  type: "Navigation",

                  visible: true,

                  cells: [

                          new sap.m.Label("ID", {

                              text: "{Empid}"

                                    }),

                          new sap.m.Label({

                              text: "{Empname}"

                                    }),

                          new sap.m.Label({

                              text: "{Empadd}"               

                                    }),

                          new sap.m.Label({

                              text: "{Empdes}"

                                    })

                          ]

            });

            var oFilters = null;

            oTable.bindItems("/results",template,null,oFilters);

            oPage.addContent(oTable);

            return oPage;

//    }                             // Comment This

      }

});


I have commented the unwanted closing tags by // Comment This.

Just copy and paste this code in view after deleting everything after this.

• sap.ui.jsview("zhk_ui5_empcrud.EmpDetails", { • • /** 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 zhk_ui5_empcrud.EmpDetails • */ • getControllerName : function() { • return "zhk_ui5_empcrud.EmpDetails"; • }, • • /** 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 zhk_ui5_empcrud.EmpDetails • */



This is the attached screenshot.


Regards

Dhananjay

ricky_shaw
Contributor
0 Kudos

Thanks Dhanajay, I will try and let you know after some more time. You rock .. Hey tell me how did you copy paste the code in this editor so clearly..I tried copy pasting in MS word an then again copy paste to this editor. Thank again. Thanks

former_member182372
Active Contributor
0 Kudos

sap.ui.jsview("zhk_ui5_empcrud.EmpDetails", {

  /** 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 zhk_ui5_empcrud.EmpDetails

  */

  getControllerName : function() {

  return "zhk_ui5_empcrud.EmpDetails";

  },

  /** 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 zhk_ui5_empcrud.EmpDetails

  */

  createContent : function(oController) {

  var oPage = new sap.m.Page({

  title : "Employee Details",

  });

  // Table or Dashboard to show Employee Data

  var oTable = new sap.m.Table({

  id : "Employees",

  itemPress : [ oController.ItemPress,oController ],

  columns : [

  new sap.m.Column({

  width: "1em",

  header: new sap.m.Label({

  text : "Emp ID"  }) }),

  new sap.m.Column({

  width: "1em",

  header: new sap.m.Label({

  text : "Name"  }) }),

  new sap.m.Column({

  width: "1em",

  header: new sap.m.Label({

  text : "Address"  }) }),

  new sap.m.Column({

  width: "1em",

  header: new sap.m.Label({

  text : "Designation"  }) }),

             ]

  });

  //Template  to map the data to the respective column     

  var template = new sap.m.ColumnListItem({

   id: "first_template",

   type: "Navigation",

  visible: true,

   cells: [

   new sap.m.Label("ID", {

    text: "{Empid}"

  }),

   new sap.m.Label({

    text: "{Empname}"

    }),

   new sap.m.Label({

    text: "{Empadd}"

  }),

   new sap.m.Label({

   text: "{Empdes}"

  })

  ]     

  });

  var oFilters = null;

  oTable.bindItems("/results",template,null,oFilters);

  oPage.addContent(oTable);

  return oPage;

  }

});

Private_Member_15166
Active Contributor
0 Kudos

Use this code in your view.

You have used some unwanted closing tags.

Regards

Dhananjay

Private_Member_15166
Active Contributor
0 Kudos

Hey tell me how did you copy paste the code in this editor so clearly..I tried copy pasting in MS word an then again copy paste to this editor.

Mine works in the same way as i said.

Answers (3)

Answers (3)

navn_metts
Active Participant
0 Kudos

Hello Ricky,

when i started UI5 i got this error. your "EmpDetails.controller.js" will have the syntax errors.

This errors may be using of unexpected tokens, and from your message i can say that you are using some illegal return statement

Please correct those errors first then you will not get this error.

Br,

Navn

Former Member
0 Kudos

Hello,

The below link may help you,

Private_Member_15166
Active Contributor
0 Kudos

Hi Ricky,

Are you able to see your view name in webcontent folder of your project??

From your error it's looking like your view is not been loaded in the application. Check the exact name of view which you have given with same uppercase and lowercase.

If the problem still persist then share the code in index.html and your view.

This might help. javascript - Error loading view in SAPUI5 - Stack Overflow

Regards

Dhananjay