Skip to Content

How to create controls based on backend response in sapui5?

Hello,

I want to generate UI based on backend data provided in service.

My Service will loook like below,

 {
    "ControlData": {
        "results": [{
            "Label": "Gender?",
            "Type": "COMBOBOX"
        }],
        "ControlValues": {
            "results": [{
                    "Key": "M",
                    "Value": "Male"
                },
                {
                    "Key": "F",
                    "Value": "Female"
                }
            ]
        }
    }
}

Here I want to generate ComboBox control with label and values provided in the service dynamically. Please provide me any example or reference to do.

Thank you.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Dec 14, 2018 at 01:23 PM

    Hi Venkatesh,

    before I answer your question I would like to say that I don't think this is the way you should design your UI / backend endpoints. I would highly recommend, that you design the controls in the UI and only transfer the form data to the backend. There are many reasons to do it this way, the most prominent would be the separation of concerns (your backend shouldn't know so many details about the UI). In case this is just for some training/research purposes: go ahead and have fun ��

    Having said that, you could write a custom "wrapper" control which includes all sub-controls (sap.m.ComboBox, sap.m.Input...) as aggregates and only displays one at a time (bind the property visible to 'ControlData-results-type'). Also, bind the properties of the control to 'ControlValue-results'.

    Again, please reconsider to implement this in productive apps.

    Regards,

    Marius

    Add comment
    10|10000 characters needed characters exceeded