Skip to content

How To Use Dynamic View Mappings

dskaggs edited this page Nov 15, 2012 · 1 revision

MG3 is designed to support cases where many customers are running "their own instance" of a common code base and how to support per-customer modification.

Realizing the use case, let's imagine that you host a blog platform. Customers can sign up and immediately have their own blog deployed. Each blog is running the exact same code base, all hosted on the same server/cluster.

Inevitably, a customer will offer to pony up cash to have a few things change. On the service / controller side, MG3 has you covered by allowing ColdSpring-based definition of services and controllers, allowing you to use ColdSpring "overriding" to one-off services and controllers.

For views, however, things were tricky. To support this case, the concept of "dynamic viewMappings" is implemented.

Model-Glue crawls an array of "view mappings" looking for your application's views: it's defined in your app's Coldspring.xml file. With dynamic viewMappings added, you can manipulate this list at runtime.

Let's solve our blog engine case, pretending that customer "acmeCorp" needs a suite of custom views, overriding the default views only when a custom is defined. All we have to do is update the viewMappings inside a listener function whenever the user is from acmeCorp:

<cfset var customViewMappings = user.getCompany().getCustomViewMapping() />

<cfif len(customViewMappings)>
	<cfset event.setValue("viewMappingAdvice", customViewMappings) />	
</cfif>

A common use case is to give all clients a custom URL. As a request comes in to the application, your code can check the url and provide the right set of viewMappings for layering of custom pages and skins. All while keeping your core software free of such knowledge and customizations.

Another use case is to change views dinamically for different browsers/device/OS (mobile, html, ajax etc) in place or in addition to requestFormat setting, getting specific version of your site for different device types.

As MG3 begins the view rendering process, it will look in your mappings (comma delimited list) provided in event.setValue("viewMappingAdvice", "/adobe/coldfusion,/adobe/flex") in canonical order. If the template value (say index.cfm) exists in the path /adobe/coldfusion, MG3 will use that. If not, but index.cfm exists in /adobe/flex, MG3, will use that. If neither exist, MG3 will look in the viewMappings provided in your modelglue.modelGlueConfiguration bean in ColdSpring.xml to find the correct view.

Clone this wiki locally