hello people ,
I am preparing one small practice application, where i am trying to enter values into 4 fields and add them to my database table (also displayed on scree in my application).
Please see the PIC attached of my base application i am trying to do.Just a starter
When i am trying to save the data entered into the fields, it throws the error(when i do inspect element) as :
" POST http://dewdfcto021.wdf.sap.corp:1080/sap/opu/odata/SAP/ZUI5_APP1_SRV/testSet 500 (Internal Server Error) "
please let me know what to do ?
find my code for controller and view below :
CONTROLLER
onInit: function() {
var oModel = new sap.ui.model.odata.ODataModel( "http://DEWDFCTO021.WDF.sap.corp:1080/sap/opu/odata/SAP/ZUI5_APP1_SRV",true);
//Set the Model to the Table
var oTable_M = sap.ui.getCore().byId("EMPTableID");
oTable_M.setModel(oModel);
// Filter the DATA
//var FilterOperator = sap.ui.model.FilterOperator;
//var filter = new sap.ui.model.Filter("EMPID",FilterOperator.EQ, "846453");
//Bind the Data to the Table
oTable_M.bindRows("/testSet", null, null,null );
},
Create:function(){
var oEmpID_var = sap.ui.getCore().getControl("tEmpID").getValue();
var oEmpName_var = sap.ui.getCore().getControl("tEmpName").getValue();
var oUserID_var = sap.ui.getCore().getControl("tUserId").getValue();
var oTeam_var = sap.ui.getCore().getControl("tTeam").getValue();
OData.request
({
requestUri:"http://DEWDFCTO021.WDF.sap.corp:1080/sap/opu/odata/SAP/ZUI5_APP1_SRV/testSet('846453')",
method : "GET", headers:
{
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"DataServiceVersion": "2.0",
"X-CSRF-Token":"Fetch"
} },
function (data,response)
{
header_xcsrf_token = response.headers['x-csrf-token'];
OData.request
({
requestUri:
"http://DEWDFCTO021.WDF.sap.corp:1080/sap/opu/odata/SAP/ZUI5_APP1_SRV/testSet",
method: "POST",
headers: { "X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"DataServiceVersion": "2.0",
"Accept": "application/atom+xml,application/atomsvc+xml,application/xml",
"X-CSRF-Token": header_xcsrf_token },
data:
{
EMPID: oEmpID_var,
EMPNAME: oEmpName_var,
USERID: oUserID_var,
TEAM: oTeam_var,
}
},
function (data,response)
{
document.location.reload(true);
$("<div>Returned data " + window.JSON.stringify(data) + "</div>").appendTo($("#MessageDiv"));
},
function (err)
{
$("<div>Returned error " + window.JSON.stringify(err.response) + "</div>").appendTo($("#MessageDiv"));
}
);
},
function (err)
{
var request = err.request; // the request that was sent.
var response = err.response; // the response that was received.
alert("Error in Get -- Request "+request+" Response "+response);
}
);
}
************************************
VIEW
createContent : function(oController) { | |||
var oBack_image = new sap.ui.commons.layout.AbsoluteLayout({width: "1000px", height: "800px"}); | |||
oBack_image.addContent(new sap.ui.commons.Image({src: "images/Background1.jpg"})); | |||
var oHome_page = new sap.ui.commons.layout.MatrixLayout({ | |||
id : "home", | |||
layoutFixed : false | |||
}); | |||
var oEmpID_l = new sap.ui.commons.Label({text:"EmpId"}); | |||
var oEmpID_t = new sap.ui.commons.TextField("tEmpID",{width:"190px"}); | |||
oEmpID_l.setLabelFor(oEmpID_t); | |||
oHome_page.createRow( oEmpID_l,oEmpID_t ); | |||
var oEmpName_l = new sap.ui.commons.Label({text:"EmpName"}); | |||
var oEmpName_t = new sap.ui.commons.TextField("tEmpName",{height:"250px" , width:"190px"}); | |||
oEmpName_l.setLabelFor(oEmpName_t); | |||
oHome_page.createRow( oEmpName_l,oEmpName_t ); | |||
var oUserID_l = new sap.ui.commons.Label({text:"UserID"}); | |||
var oUserID_t = new sap.ui.commons.TextField("tUserId",{height:"250px" , width:"190px"}); | |||
oUserID_l.setLabelFor(oUserID_t); | |||
oHome_page.createRow( oUserID_l,oUserID_t ); | |||
var oTeam_l = new sap.ui.commons.Label({text:"Team"}); | |||
var oTeam_t = new sap.ui.commons.TextField("tTeam",{height:"250px" , width:"190px"}); | |||
oTeam_l.setLabelFor(oTeam_t); | |||
oHome_page.createRow( oTeam_l,oTeam_t ); | |||
var oSaveButton = new sap.ui.commons.Button({text:"Save Data",width:"133px", |
press:function() {
oController.Create(); |
}});
var oBlank_l = new sap.ui.commons.Label({text:""}); | |||
oHome_page.createRow(oBlank_l,oSaveButton); | |||
oBack_image.addContent(oHome_page); | |||
oBack_image.placeAt("content"); | |||
// table coding begins | |||
var oPanel_Table = new sap.ui.commons.Panel('Panel_table', { | |||
text : "Employee Details", | |||
}); | |||
var oTable = new sap.ui.table.DataTable({ | |||
id : "EMPTableID", | |||
//title: "UI5 CRUD Application", | |||
width : "100%", | |||
visibleRowCount: 10, | |||
selectionMode : sap.ui.table.SelectionMode.Single, | |||
//setEditable : false, | |||
rowSelectionChange : function(oEvent) {}, | |||
toolbar: new sap.ui.commons.Toolbar({ | |||
// | items: [ | ||
// | new sap.ui.commons.Button({ | ||
// | text: "Create", | ||
// | press: function() { | ||
// | oController.Create(); | ||
// | } | ||
// | }), | ||
// | |||
// | ] | ||
}) | |||
}); | |||
oTable.addColumn(new sap.ui.table.Column({ | |||
label : new sap.ui.commons.Label({ | |||
text : "EMP ID" | |||
}), | |||
template : new sap.ui.commons.TextField().bindProperty("value", | |||
"EMPID"), | |||
sortProperty : "EMPID" | |||
})); | |||
oTable.addColumn(new sap.ui.table.Column({ | |||
label : new sap.ui.commons.Label({ | |||
text : "EMP NAME" | |||
}), | |||
template : new sap.ui.commons.TextField().bindProperty("value", | |||
"EMPNAME"), | |||
sortProperty : "EMPNAME" | |||
})); | |||
oTable.addColumn(new sap.ui.table.Column({ | |||
label : new sap.ui.commons.Label({ | |||
text : "USER ID" | |||
}), | |||
template : new sap.ui.commons.TextField().bindProperty("value", | |||
"USERID"), | |||
sortProperty : "USERID" | |||
})); | |||
oTable.addColumn(new sap.ui.table.Column({ | |||
label : new sap.ui.commons.Label({ | |||
text : "TEAM name" | |||
}), | |||
template : new sap.ui.commons.TextField().bindProperty("value", | |||
"TEAM"), | |||
sortProperty : "TEAM" | |||
})); | |||
// Add table to the Panel | |||
oPanel_Table.addContent(oTable); | |||
var oBlank_l2 = new sap.ui.commons.Label({text:""}); | |||
oHome_page.createRow(oBlank_l2,oTable); | |||
} | |||
});
*****************
Please don't mind the length of this post .
do let me know what should i do in this case.
Regards,
Amritansh