Skip to Content

How to use different types of views in same SAPUI5 Application.

Hello,

I want to use XML and HTML views in same SAPUI5 Application. How can I achieve this from Routing. I am trying below code but it is not working.

routing: {
			config: {
				routerClass: "sap.m.routing.Router",
				viewType: "XML",
				viewPath:  "executive.WebContent.view",
				controlId: "app",
				controlAggregation: "pages",
					
				},


			routes: [{
				"pattern": "",
				"name": "View1",
				"viewPath": "executive.WebContent.view",
				"viewType": "XML",
				"target": "View1"
				},
				{
				"pattern": "Login",
				"name": "View2",
				"viewPath": "executive.WebContent.view",
				"viewType": "XML",
				"target": "View2"
				},
				
				{
				"pattern": "Visitor",
				"name": "View3",
					
				 "viewPath": "executive.WebContent.view",
				 "viewType": "HTML",
				"target": "View3"
						
						
				}],


			targets: {
				"View1": {
					"viewName": "Main"
						
					},
				"View2":
					{
					"viewName": "Login"
						
					},
				"View3":
					{
					"viewName": "Visitor"
						
					}
				}


			}
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Aug 07, 2017 at 07:13 PM

    it is not recommended - please use XML views as per best practices, better readability, easier to maintain

    Add comment
    10|10000 characters needed characters exceeded

  • Aug 08, 2017 at 02:13 AM

    Interesting. When you tried the config, what is the error you received from the framework, int he console?

    Regards,

    Sharath

    Add comment
    10|10000 characters needed characters exceeded

    • Not sure, but seems like the framework decides one of the views to be called? It has automatically assigned the file type as XML even though as per your code(pasted) it is defined as HTML.

      As mentioned by others, it is not a good practice to have multiple view file types.

      The purpose of the view is to ensure that it is de-coupled from the controller. By making view itself based on multiple types, you complicate the architecture. In this scenario, the framework may be stopping you from that. I am sure, there could be some workaround to make this work but it's futile.

      The who application is built to meet a customer/client requirement. By complicating it no one will want to have that and neither will SAP support it.

      Recommendations are your guides on this journey. It makes life easier as these recommendations are based on SAP's years of experience. I suggest you stick to it as much as you can unless there is need to deviate.

      Regards,

      Sharath

  • Aug 07, 2017 at 02:48 PM

    Why are you trying to have multiple view types in the app? I don't think this is really a good/recommended programming practice.

    Add comment
    10|10000 characters needed characters exceeded