Why do we use XML views rather JS views in SAPUI5?
A very common issue which many of you also have faced in SAPUI5 developments, specially people who are using javascript view to design the UI5 front end.
Important question arises before starting with SAPUI5 application developments, whether to use XML views or JavaScript views. Here are some points I would like to share which you can go through and think to decide upon.
Mostly XML views are used in SAPUI5 developments rather than JavaScript views because:
- To protect MVC (Model-View-Controller) guidelines: If a developer uses JavaScript views, then there is chance of putting processing code in the view itself, which violates the MVC principle.
- As XML is not a programming language, there is no way you can put processing logic inside XML views. So, in that case, you will always use controller to put your processing logic following MVC architecture.
- XML is the industry standard to put views in a UI based application.
- The SAP Web IDE includes a WYSIWYG(What you see is what you get) graphical layout editor that works only with XML views.
- Using XML views, you can use Layout Editor means Editor that allows you to easily drag and drop UI controls on the screen/page and it’s ready-made code will get available automatically to you.
- Parsing of XML in devices is faster than JavaScript.
- XML views are more attractive when compared to JS based view.
- SAP ships all Fiori apps using XML views. So, as a SAPUI5 developer, better to have atleast the knowledge in how to read XML based views also along with JS views.
- SAP recommendation is to use XML views instead of JS, as it is better in terms of maintainability and readability.
- You can easily find out the structure and hierarchy of UI controls that are laid out within each other.
MVC architecture:
Everything has its own advantage and disadvantages, you may find those points for both type of views, but it’s in the developer’s hand to decide whichever he/she finds more comfortable.
The main advantage of using XML view is its compatibility to be processed by all the platforms, devices and programming languages.
Moreover, the beauty of XML view is SAPUI5 libraries like sap.ui.core, sap.ui.commons etc. mentioned in a namespace gets loaded by the view itself.(But usually we put those libraries in a Bootstrap code inside index.html).
THINK! and DECIDE! or Just Give it a TRY! 🙂
Be open for new things!!
Well done. A blog that I can refer to in the future to answer the 'Why XML?' question.
well i do agree on this, SAP recommendation is to use XML views instead of JS.. still many of them using JS and not following SAP standards. thank you for sharing list, this will help us to show / discuss further Why XML?
The problem is, XML views don't allow you to use dynamic filtering in your binding.
I started creating bindings inside XML views, then realized I need my filters to be set to a dynamic value from oData model. I had to move EVERYTHING from XML to the controller.
I really wish they would let you use a controller function in the XML binding:
This would save me hours of javascript coding. I could leave everything in XML, and just a dynamic filter in the controller.