on 2024 Oct 17 9:58 AM
Hi,
As you can see, the ui5 app appears empty. Have someone an idea to solve this issue?
View
<table:Table id="table" selectionMode="Single" rows="{myODataModel>/ZEMPLOYEEDATASet}" enableColumnReordering="false">
<!-- columns for customer name, address, and email -->
<table:columns>
<table:Column id="idColumn3" width="50%">
<table:label>
<Label id="idLabel3" text="ID"/>
</table:label>
<table:template>
<Text id="idText3" text="{myODataModel>Id}"/>
</table:template>
</table:Column>
<table:Column id="idColumn1" width="20%">
<table:label>
<Label id="idLabel1" text="Name"/>
</table:label>
<table:template>
<Text id="idText1" text="{myODataModel>Name}"/>
</table:template>
</table:Column>
<table:Column id="idColumn2" width="30%">
<table:label>
<Label id="idLabel2" text="Address"/>
</table:label>
<table:template>
<Text id="idText2" text="{myODataModel>Address}"/>
</table:template>
</table:Column>
<table:Column id="idColumn4" width="50%">
<table:label>
<Label id="idLabel4" text="Phone Number"/>
</table:label>
<table:template>
<Text id="idText4" text="{myODataModel>phonenumber}"/>
</table:template>
</table:Column>
</table:columns>
</table:Table>
controller
onInit: function () {
// Wait for the view to fully render
this.getView().addEventDelegate({
onAfterRendering: function () {
// OData model instance
var oModel = new sap.ui.model.odata.v2.ODataModel("/sap/opu/odata/SAP/Z_EMPLOYEE_SRV/");
this.getView().setModel(oModel);
// Get the table instance
var oTable = this.getView().byId("table");
if (oTable) {
// Bind the rows of the table to the OData entity set
oTable.bindRows({
path: "/ZEMPLOYEEDATASet", // OData entity set
parameters: {
select: "Id,Name,Address,Phonenumber" // Select fields
}
});
} else {
console.error("Table not found");
}
}.bind(this)
});
}
manifest file
"sap.app": {
............
.......
"dataSources": {
"mainService": {
"uri": "/sap/opu/odata/SAP/Z_EMPLOYEE_SRV/",
"type": "OData"
}
}
},
"sap.ui5": {
"models": {
.....
"myODataModel": {
"type": "sap.ui.model.odata.v2.ODataModel",
"dataSource": "mainService",
"settings": {
"defaultBindingMode": "TwoWay",
"defaultCountMode": "Inline"
}
}
},
}
Thank you
Mahmood
Request clarification before answering.
Can you please tell use why do use the onInit und AfterRendering anyway? You can just use the default model without any JavaScript Code.
To make it more simple you can just this in the xml view:
<table:Table id="table" selectionMode="Single" rows="{/ZEMPLOYEEDATASet}" enableColumnReordering="false">
<!-- columns for customer name, address, and email -->
<table:columns>
<table:Column id="idColumn3" width="50%">
<table:label>
<Label id="idLabel3" text="ID"/>
</table:label>
<table:template>
<Text id="idText3" text="{Id}"/>
</table:template>
</table:Column>
<table:Column id="idColumn1" width="20%">
<table:label>
<Label id="idLabel1" text="Name"/>
</table:label>
<table:template>
<Text id="idText1" text="{Name}"/>
</table:template>
</table:Column>
<table:Column id="idColumn2" width="30%">
<table:label>
<Label id="idLabel2" text="Address"/>
</table:label>
<table:template>
<Text id="idText2" text="{Address}"/>
</table:template>
</table:Column>
<table:Column id="idColumn4" width="50%">
<table:label>
<Label id="idLabel4" text="Phone Number"/>
</table:label>
<table:template>
<Text id="idText4" text="{phonenumber}"/>
</table:template>
</table:Column>
</table:columns>
</table:Table>
and in the manifest json make the OData Model the default like this and remove the name "myODataModel":
"sap.ui5": {
"models": {
.....
"": {
"type": "sap.ui.model.odata.v2.ODataModel",
"dataSource": "mainService",
"settings": {
"defaultBindingMode": "TwoWay",
"defaultCountMode": "Inline"
}
}
},
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
check your ui5.yaml file, do you have something like this?
server:
customMiddleware:
- name: fiori-tools-proxy
afterMiddleware: compression
configuration:
ignoreCertError: true
backend:
- path: /sap
url: "https://******"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
server:
customMiddleware:
- name: fiori-tools-proxy
afterMiddleware: compression
configuration:
ignoreCertError: true
ui5:
path:
- /resources
- /test-resources
url: https://ui5.sap.com
server:
customMiddleware:
- name: fiori-tools-proxy
afterMiddleware: compression configuration:
ignoreCertError: true
ui5: path:
- /resources
- /test-resources
url: https://ui5.sap.com
backend:
- path: /sap
url: "http://....8000" # SAP system URL from the image
your table already has binding, why you do the binding in your controller again?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Mahmood99 ,
Here the application does not know where is from your oData service.
If it's an external one, you should define the model in this way:
var oModel = new ODataModel("http://services.odata.org/Northwind/Northwind.svc/");
But you will have a security issue, and you need to change your configuration files.
The best approach as I see you are using the manifest, is to define the destination.
Here some blog and answers can help you:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
12 | |
9 | |
8 | |
7 | |
5 | |
4 | |
4 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.