Skip to Content
0

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

Aug 07, 2017 at 11:54 AM

75

avatar image

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"
						
					}
				}


			}
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Sergio Guerrero Aug 07, 2017 at 07:13 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Sharath M G Aug 08, 2017 at 02:13 AM
0

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

Regards,

Sharath

Show 2 Share
10 |10000 characters needed characters left characters exceeded

It is trying to navigate to Visitor.view.xml while actually it is HTML. So, showing error

0

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

0
saurabh vakil Aug 07, 2017 at 02:48 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded