Skip to Content
Technical Articles

Dynamic Path to Model Data

Introduction

While working with model data in SAPUI5, often we could come across scenarios where it is more comfortable to have our own(custom) data nodes or objects for storing additional properties in the gloabl/application model for further processing later in the application. An example scenario is one described by DJ Adams / Chris Choy is here. It may not have been possible to anticipate all the corresponding objects at build time.

Sample Application

Let us quickly create a sample application. In this application Employee data is shown in a list and based of demand during run time additional information pertaining to their organisation is shown.

Model data:-

Our Model data holds an array with Employee name, Billing Rate and their availability.

View:-

At the view side we would display the Employee list with status in Red if they are not available using Expression Binding.

Controller does not have any role to play for now and the output(as expected) is a simple list with the Employee availability(Green/Red)

Let us quickly check what the model holds for us:-

As expected, the model holds the employee details for us. “Results” was the name given to the model.

Updating the Application

Now that the initial application set up is done, let us quickly try to extend the model at run time. We would add a new button on the view to show more information. Under the event for this button, let us quickly specify a path to set our new data. Base controller used for code guidelines. getModel function is being called from there.

New Button is visible on screen:-

And when this button is being clicked, let us check the model once again in console for additional node containing our new data.

This contains our new data node as expected. The result now shows these additional properties on the screen.

Conclusion

While we were not able to completely extend the model early on, this method could work as a short hand during the development process to hold additional data nodes to the same mode being used across the views/controller. Hope this was useful for beginners in SAPUI5.

Git Repo:https://github.com/jakes2255/UI5-Custom-Model-Data

 

Thank you,

Jakes

5 Comments
You must be Logged on to comment or reply to a post.
  • what’s the point of this blog?

    it just display data from the model, what’s the specialty?

    I feel it will only confuse beginner.

    when u use setProperty with fixed value, your stuff is decided at build time, nothing at runtime.  your two set of data are the same thing, one loaded at beginning, one is just loaded at latter time. technically no difference.

     

    • Hi Jun,

      Agreed, in the example yes, no special conditions were added to make a decision at run time.

      Kindly consider the use case, where based on some condition while the application is running, the model is enhanced with additional properties.

      Thank you for your time to review my content.

      Regards,

      Jakes