Skip to Content
0

SimpleForm in XML with OData

Dec 05, 2017 at 04:33 PM

96

avatar image

Hey there,

I don't know what I'm doing wrong.

I have a simpleform and try ti bind it to a oData service.

<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:form="sap.ui.layout.form"
		controllerName="wm_mde.WE_ERFASSEN" xmlns:html="http://www.w3.org/1999/xhtml">
	<Page title="Wareneingang erfassen">
		<content>
		<form:SimpleForm
			layout="ResponsiveGridLayout"
			editable="true"
			id="bestForm" >
			<Label displayOnly="true" wrapping="true" text="Bestellung" for="edtEBELN" required="true"/>
			<Input id="edtEBELN" change="onEbelnChange" valueLiveUpdate="true"></Input>
			<Label displayOnly="true" wrapping="true" text="Lieferschein" for="edtLIEFS" required="true"/>
			<Input id="edtLIEFS" change="onLiefsChange" value="{bestellung>Bktxt}" valueLiveUpdate="true"></Input>
			<Label displayOnly="true" wrapping="true" text="Belegdatum" for="edtBELDAT" required="true"/>
			<Input id="edtBELDAT" change="onBeldatChange" value="{Lfdat}" valueLiveUpdate="true"></Input>
			<Label displayOnly="true" wrapping="true" text="Lagerort" for="edtLGORT"/>
			<Input 
				id="edtLgort"
				editable="false" 
				value="{Lgort}"
				valueLiveUpdate="true" />
			<Label displayOnly="true" wrapping="true" text="Bestelldatum" for="edtBESTDAT"/>
			<Input id="edtBESTDAT" 
				editable="false" 
				value="{Bestdat}" 
				valueLiveUpdate="true"
				/>
				<Label displayOnly="true" wrapping="true" text="Text" for="txt"/>
				<!--<Text id="txt" text="{
  path: '/d/Bestdat',
  type: 'sap.ui.model.type.Date',
  formatOptions: {
  	style: 'long',
  	pattern: 'yyyy/MM/dd'
  }
  
  }" valueLiveUpdate="true"/>-->
				<Text text="{ 
				path: '/d/Bestdat',
				type: 'sap.ui.model.type.Date',
				formatOptions: { pattern: 'yyyy/MM/dd'} }" />
			<Label displayOnly="true" wrapping="true" text="Anforderer" for="edtANFORD"/>
			<Input id="edtANFORD" editable="false" value="{Lgnum}" valueLiveUpdate="true"></Input>
			</form:SimpleForm>
		</content>
		<footer>
			<Toolbar>
				<Button text="Abbruch" type="Reject" press="onCancel"/>
				<ToolbarSpacer/>
				<Button text="Weiter" type="Accept" id="btnOK" press="onOk"/>				
			</Toolbar>
		</footer>
	</Page>
</core:View>

And this is my controller

sap.ui.controller("wm_mde.WE_ERFASSEN", {


/**
* 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 wm_mde.WE_ERFASSEN
*/
	onInit: function() {
		var oModel = new sap.ui.model.odata.v4.ODataModel({
	    	serviceUrl: "http://obelix3.1net.dom:8002/sap/opu/odata/sap/ZWM_MDE_SRV_03/",
	    	synchronizationMode : "None"
	    });
		this.getView().byId("bestForm").setModel(oModel);
	},


/**
* Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered
* (NOT before the first rendering! onInit() is used for that one!).
* @memberOf wm_mde.WE_ERFASSEN
*/
//	onBeforeRendering: function() {
//		
//	},


/**
* Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here.
* This hook is the same one that SAPUI5 controls get after being rendered.
* @memberOf wm_mde.WE_ERFASSEN
*/
//	onAfterRendering: function() {
//
//	},


/**
* Called when the Controller is destroyed. Use this one to free resources and finalize activities.
* @memberOf wm_mde.WE_ERFASSEN
*/
//	onExit: function() {
//
//	}


	onEbelnChange: function(oEvent){
		ebeln=this.getView().byId("edtEBELN").getValue();
		 this.getView().byId("bestForm").bindElement({
				path: "/BESTSet(Ebeln='"+ebeln+"',Lgnum='110')",
		 });
		
		
		this.getView().byId("edtLIEFS").focus();
	},
	
	onLiefsChange: function(oEvent){
		this.getView().byId("edtBELDAT").focus();
	},
	
	onBeldatChange: function(oEvent){
		this.getView().byId("btnOK").focus();
	},
	onCancel: function(){
		app.back();
	},
	
	onOk: function(evt){
	
		
	}
	
});

I always get these two errors!

unbenannt.png (24.6 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Sven Schuberth Dec 06, 2017 at 11:52 AM
0

Seems to be an error in v4.ODataModel!

If I use sap.ui.model.odata.ODataModel instead of v4, everything is fine!

Share
10 |10000 characters needed characters left characters exceeded
Arjun Biswas Dec 06, 2017 at 02:53 AM
0

Hi Sven Schuberth,

It seems you are using the $batch URI which I think is not required for your simple form. Also, for your path, just try to execute the same URL in your netweaver gateway and check if you get a response.

Regards,

Arjun Biswas

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Arjun,

I don't know where $batch is comming from.

I instantiated the model with

var oModel =newsap.ui.model.odata.v4.ODataModel({
	    	serviceUrl:"http://obelix3.1net.dom:8002/sap/opu/odata/sap/ZWM_MDE_SRV_03/",
	    	synchronizationMode :"None"});

As you can see, there is no $batch.

If I execute the URL+Path in Browser I get a valid response:

http://obelix3.1net.dom:8002/sap/opu/odata/sap/ZWM_MDE_SRV_03/BESTSet(Ebeln='45',Lgnum='110')

I don't understand where this $batch is comming from!

0

By default the batch mode is enabled in OData model...It is an optimized and secure way of sending data to backend.

0

Hi

You can use either of these :

var oDataModel = sap.ui.getCore().getModel();
oDataModel.setUseBatch(false);
"models": {
    "default_model": {
        "dataSource" : "default_data_source",
        "settings" : {
          "useBatch" : false
        }
    }
}

Regards,

Arjun Biswas

0