openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

v2.ODataListBinding - Cannot change 'custom' parameter

Open fabiopagoti opened this issue 6 years ago • 4 comments

This is a feature request.

Summary: It's not possible to change the parameters of class sap.ui.model.odata.v2.ODataListBinding after the object is created, more specifically the custom parameter.

Background [back end]: I created a CDS view for Material search and I'm fine-tuning a OData service using it. So, by using the custom search URL parameter, I can perform a fuzzy search based on material ID or name.

Example: GET /sap/opu/odata/sap/YMY_SERVICE/Products?$top=20&search=1234

Background [front end]: I created a SelectDialog bound to this entity (Products) and I want to call the service passing the custom 'search' URL parameter using sap.ui.model.odata.v2.ODataListBinding

OpenUI5 version: 1.64.0 (but tested in 1.44.7)

Browser/version (+device/version): ANy

Any other tested browsers/devices(OK/FAIL): n/a

URL (minimal example if possible):

User/password (if required and possible - do not post any confidential information here):

Steps to reproduce the problem:

  1. Create a SelectDialog
<SelectDialog 
        title="Select Product" 
        search="onSearch" 
        items="{
			path: '/Products'
		}">
    	<items>
	        <StandardListItem 
		     title="{MaterialId}" 
	            description="{MaterialName}"  />
    	</items>
    </SelectDialog>
  1. Implement 'search' event handler
onSearch: function (oEvent) {
    var oParameters = oEvent.getParameters();
    var oListBinding = oParameters.itemsBinding;
    var sSearchTerm = oParameters.value;

    var oSource = oEvent.getSource();
    var oModel = oSource.getModel();

    var sCustomParams = oModel.createCustomParams({
        custom: {
            search: sSearchTerm
        }
    });
     // touching internal variable from class
    // this is what I would like to avoid
    oListBinding.sCustomParams = sCustomParams;

    // There is no alternative similar the one below
    /*
    oListBinding.setCustomParams({
     search: sSearchTerm
    });
    */

    oListBinding.refresh();
    
}
  1. The only way I could make things work without touching in the sCustomParams is by using a "manual" read to the oDataModel and transfer it to a JSONModel
onSearch: function (oEvent) {
    var oParameters = oEvent.getParameters();
    var oListBinding = oParameters.itemsBinding;
    var sSearchTerm = oParameters.value;

    var oSource = oEvent.getSource();
    var oModel = oSource.getModel();

    function onSuccess(oData, response) {
        this._oSomeJSONModel.setData(oData.results);
    }

    var mOptions = {
        urlParameters: {
            search: oParameters.value,
            "$top": 50
        },
        success: onSuccess.bind(this)
    };

    oModel.read("/Products", mOptions);
},

What is the expected result? Have a method in class sap.ui.model.odata.v2.ODataListBinding to change custom parameters values.

What happens instead? I had to touch the internal variable sCustomParams or replicate data to a JSONModel

Any other information? (attach screenshot if possible) The same limitation happens for any other parameters of this class which are available in its constructor.

fabiopagoti avatar Apr 18 '19 18:04 fabiopagoti

Yes.

I haven't used the v4 namespace for that but what I understood from the docs is exactly why I would like to see in v2 as well.

fabiopagoti avatar May 07 '19 13:05 fabiopagoti

Hello @fabiopagoti,

Thank you for share your enhancement proposal. I've created an internal incident 1980305271. The status of the issue will be updated here in GitHub.

Regards, Alexandar Mitsev

alexandar-mitsev avatar May 23 '19 15:05 alexandar-mitsev

This issue will be covered in backlog item CPOUI5MODELS-73.

flovogt avatar Mar 04 '22 09:03 flovogt