Blog

Tip of the Week: Implicit View Dispatch

Brad Wood December 05, 2012

Spread the word

Brad Wood

December 05, 2012

Spread the word


Share your thoughts

 

In the past we've talked about implicit views in ColdBox which mean that if the action in your event handler doesn't call setView() explicitly, ColdBox will use conventions to try and find the view to render.  Well, ColdBox also supports something called Implicit View Dispatch which goes one step further and allows you to dispatch a view to the user without running any event at all.
 
What are the use cases?  Well, perhaps you have a completely static view like a contact us page and creating a method in a handler somewhere would just be pure boilerplate.  We can tell ColdBox to just send the view directly back to the user (using the default layout). 
 
Or perhaps you're slowly integrating ColdBox into a legacy app and you want to still serve up a legacy CFM page while using ColdBox's routing mechanisms.  Again, we can ease into ColdBox without creating handlers for all those legacy pages yet.
 
So, how does it work?  Very simply, and unsurprisingly similar to how implicit views work.  If ColdBox can't located the package/handler or the action specified by your event, it uses a /views/[package/]handler/action.cfm convention to try and locate a view to return.
 
Consider a URL that looks like this:
 
mySite.com/index.cfm?event=contact.about
 
(Or the following equivalent for you people using the SES Interceptor and rewrites)
 
mySite.com/contact/about
 
If the "contact" handler doesn't exist, or does exist but doesn't have an "about" action, then ColdBox will look for the following view to dispatch directly:
 
/views/contact/about.cfm
 
If you have external view locations defined, ColdBox will check them as well before finally giving up and throwing an error.
 
 
P.S. It is also possible to add SES routes that directly dispatch a view without running an event like so:
 
addRoute(pattern='/AboutUs',view='contact/about');
 
That would make the following URL dispatch the same view as above, but with an even prettier URL:
 
mySite.com/AboutUs
 

Add Your Comment

Recent Entries

ColdBox 7.2.0 Released

ColdBox 7.2.0 Released

ColdBox, a widely used development platform for ColdFusion (CFML), has unveiled version 7.2. Packed with compelling new features, bug fixes, and enhancements, this release is designed to empower developers by boosting productivity, refining scheduled task capabilities, and enhancing the overall reliability and efficiency of application development. This article will delve into the key highlights of ColdBox 7.2 and elucidate how these advancements can positively impact developers in their daily coding endeavors.

Luis Majano
Luis Majano
November 20, 2023
Into the Box 2023 Series on CFCast

Into the Box 2023 Series on CFCast

Excitement is in the air as we unleash the highly anticipated ITB 2023 series exclusively for our valued CFCast subscribers – and the best part? It's FREE for CFCast members! Now is the perfect time if you haven't joined the CFCast community yet. Plus, we've got an incredible End-of-Year deal that's too good to miss

Maria Jose Herrera
Maria Jose Herrera
November 20, 2023
Ortus Deals are Finally Here!

Ortus Deals are Finally Here!

The much-anticipated Ortus End-of-the-Year Sale has arrived, and it's time to elevate your development experience! Whether you're a seasoned developer, a tech enthusiast, or someone on the lookout for top-notch projects, Ortus has something special in store for you. Brace yourself for incredible discounts across a wide array of products and services, including Ortus annual events, books, cutting-edge services, and more.

Maria Jose Herrera
Maria Jose Herrera
November 15, 2023