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

Ortus June 2024 Newsletter!

Ortus June 2024 Newsletter!

Welcome to the latest edition of the Ortus Newsletter! This month, we're excited to bring you highlights from our sessions at CFCamp and Open South Code, as well as a sneak peek into our upcoming events. Discover the latest developments in BoxLang, our dynamic new JVM language, and catch up on all the insightful presentations by our expert team. Let's dive in!

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024
BoxLang June 2024 Newsletter!

BoxLang June 2024 Newsletter!

We're thrilled to bring you the latest updates and exciting developments from the world of BoxLang. This month, we're diving into the newest beta release, introducing a new podcast series, showcasing innovative integrations, and sharing insights from recent events. Whether you're a seasoned developer or just getting started, there's something here for everyone to explore and enjoy.

Maria Jose Herrera
Maria Jose Herrera
June 28, 2024
BoxLang 1.0.0 Beta 3 Launched

BoxLang 1.0.0 Beta 3 Launched

We are thrilled to announce the release of BoxLang 1.0.0-Beta 3! This latest beta version is packed with exciting new features and essential bug fixes, including robust encryption functionality, enhanced Java interoperability, and more efficient event handling. Key highlights include the introduction of query caching capabilities, seamless coercion of Java Single Abstract Method (SAM) interfaces from BoxLang functions, and support for virtual thread executors. So, let’s dive into the details of what’s new in BoxLang 1.0.0-Beta 3 and how you can start leveraging these updates today!

Luis Majano
Luis Majano
June 28, 2024