配置 SAP Gateway 服务以忽略负载中未定义的属性
Configure SAP Gateway service to ignore properties from payload that are not defined
场景很简单:我有一个产品列表,在前端我在 oData 模型(“EditMode”)中动态创建了一个 属性。我仅将此 属性 用于 enable/disable 某些输入字段的前端。
当我执行更新(POST)时,网关请求失败(400 错误请求),因为“EditMode”未在产品实体上定义。
如何配置网关以忽略未定义的属性并仅从负载中获取它需要的内容?
在发送请求之前从 oData 模型中删除此 属性 会产生开销,它还会影响 UI... :(
谢谢!
我认为将不属于数据模型的属性发送到服务器是一种非常糟糕的方法。 OData 4.0 spec 表示(尽管 SAP GW 仍然是 OData 2.0):
6.2 Payload Extensibility
OData supports extensibility in the payload, according to the specific
format. Regardless of the format, additional content MUST NOT be
present if it needs to be understood by the receiver in order to
correctly interpret the payload according to the specified
OData-Version header. Thus, clients and services MUST be prepared to
handle or safely ignore any content not specifically defined in the
version of the payload specified by the OData-Version header.
SAP GW 通过取消请求并发回错误的请求响应来“处理”意外属性。我相信没有改变这种行为的选择,它也会破坏“OData”。
我假设您在前端使用 SAPUI5。有很多方法可以实现您真正想要的 - 我对此非常确定。但是在我的案例中从来不需要更改“真实”数据,即通过添加“附加”属性。一种方法是将控件的可编辑 属性 绑定到类似
的东西
"{view>/editmode}"
如您所料,这是一个视图模型,也称为“视图模型模式”。这仅意味着您在控制器中(即在 onInit 中)创建一个 JSONModel,然后调用
this.getView().setModel(oModel, "view");
每当您想 disabled/enable 编辑一组控件时,只需调用一次:
var bEditable = ...; // true or false
//...
this.getView().getModel("view").setProperty("/editMode", bEditable);
另一种选择是有 2 个不同的 views/targets,一个用于编辑模式,一个用于显示模式。如果您想遵循 Fiori 指南,我认为您应该使用此选项。由你决定...
这些选项假定您仅使用一个标志来使“所有”控件可编辑或不可编辑。
如果您需要一些额外的建议,请确保 post 一些代码可以更好地说明您的问题。
场景很简单:我有一个产品列表,在前端我在 oData 模型(“EditMode”)中动态创建了一个 属性。我仅将此 属性 用于 enable/disable 某些输入字段的前端。
当我执行更新(POST)时,网关请求失败(400 错误请求),因为“EditMode”未在产品实体上定义。
如何配置网关以忽略未定义的属性并仅从负载中获取它需要的内容?
在发送请求之前从 oData 模型中删除此 属性 会产生开销,它还会影响 UI... :(
谢谢!
我认为将不属于数据模型的属性发送到服务器是一种非常糟糕的方法。 OData 4.0 spec 表示(尽管 SAP GW 仍然是 OData 2.0):
6.2 Payload Extensibility
OData supports extensibility in the payload, according to the specific format. Regardless of the format, additional content MUST NOT be present if it needs to be understood by the receiver in order to correctly interpret the payload according to the specified OData-Version header. Thus, clients and services MUST be prepared to handle or safely ignore any content not specifically defined in the version of the payload specified by the OData-Version header.
SAP GW 通过取消请求并发回错误的请求响应来“处理”意外属性。我相信没有改变这种行为的选择,它也会破坏“OData”。
我假设您在前端使用 SAPUI5。有很多方法可以实现您真正想要的 - 我对此非常确定。但是在我的案例中从来不需要更改“真实”数据,即通过添加“附加”属性。一种方法是将控件的可编辑 属性 绑定到类似
的东西"{view>/editmode}"
如您所料,这是一个视图模型,也称为“视图模型模式”。这仅意味着您在控制器中(即在 onInit 中)创建一个 JSONModel,然后调用
this.getView().setModel(oModel, "view");
每当您想 disabled/enable 编辑一组控件时,只需调用一次:
var bEditable = ...; // true or false
//...
this.getView().getModel("view").setProperty("/editMode", bEditable);
另一种选择是有 2 个不同的 views/targets,一个用于编辑模式,一个用于显示模式。如果您想遵循 Fiori 指南,我认为您应该使用此选项。由你决定...
这些选项假定您仅使用一个标志来使“所有”控件可编辑或不可编辑。
如果您需要一些额外的建议,请确保 post 一些代码可以更好地说明您的问题。