Hi, all,
My mind is swimming with various thoughts around MVC, OO design
practices and Model-Glue... I've searched around quite a bit before
posting here. I'm primarily looking for Model-Glue usage advice here,
as I'm still a bit new to MG and also know that Gesture has some
significant changes, but please speak up if my design sounds way off
to you. (BTW, I'm using Gesture, bleeding edge release from SVN.) Any
suggestions would be very much appreciated. So, here's my situation...
I have a registration of sorts and I need to send a confirmation e-
mail upon successful registration. It will be a multi-part message
(using cfmailpart tags for text and html versions) with some dynamic
content. I wrote a little EmailUtility.cfc that makes it easy to pass
in arguments for a multi-part message, along with any other attributes
to be passed through to cfmail. I can't help but think that my mail
part arguments are essentially rendered views -- in fact, that's
exactly what they are. As a matter of fact, to test I simply commented
out my MG event's <results> section so my e-mail body view would
render to my browser screen.
That said, I don't want to have my view responsible for sending the e-
mail, because the view should just be responsible for that one piece
of the puzzle (the html or text body for the e-mail -- not other
cfmail attributes that come from domain objects).
Okay, so I was all excited and thought I'd just have a few events
chained via results and have a notification controller just grab the
two views for the e-mail body parts and pass them along as arguments
to my e-mail service. But I always seemed to get an empty string when
calling arguments.event.getView('htmlBody') in my controller method.
Ray Camden seemed to have a similar question a while back, but no
response here:
http://www.nabble.com/odd-issue-with-event.getView-td9743691.html
Searching some more, I've learned (I think) that views are not
rendered until all results have been handled, which is why my rendered
view is not available to the controller. Now, I also realize that this
is breaking MVC a bit by having the controller layer dealing with the
view layer, but it seemed like a reasonable use case.
So, I searched yet some more and found a really slick solution by Sean
Corfield, to nearly my exact problem:
http://corfield.org/blog/index.cfm/do/blog.entry/entry/ModelGlue_and_PostProcessing_Views
Finally, on to my ultimate question... Is Sean's solution the one I
should bear in mind as I solve my current problem, or have there been
significant changes to Model-Glue (since Sean's 2005 post) that would
provide another path? I'm also still trying to fully wrap my head
around Sean's solution, but I think I follow how he's injecting a
callback for a view. That said, I think I'd need a pseudo-layout view
for my situation, which would be able to access both my htmlBody and
textBody views, right? I wonder if that nice new MG3 event types
feature might be useful here?
FWIW, here's a ModelGlue.xml snippet to demonstrate the idea I had
(which, remember, does not work, other than sending a blank e-mail
confirmation!):
<event-handler access="public" name="register.save">
<broadcasts>
<message name="needRegistrationSaved" />
</broadcasts>
<views>
<include name="pageTopMessage" template="includes/
pageTopMessage.cfm" />
</views>
<results>
<result name="saveRegistration.success"
do="register.prepareConfirmation" />
<result name="saveRegistration.fail" do="register.main" />
</results>
</event-handler>
<event-handler access="private" name="register.prepareConfirmation">
<views>
<include name="htmlBody" template="pages/
registerConfirmationHtml.cfm" />
<include name="textBody" template="pages/
registerConfirmationText.cfm" />
</views>
<results>
<result do="register.sendConfirmation" />
</results>
</event-handler>
<event-handler access="private" name="register.sendConfirmation">
<broadcasts>
<message name="needRegistrationConfirmationSent" />
</broadcasts>
<results>
<result do="register.login" />
</results>
</event-handler>
Thanks a ton, in advance, to anyone who's made it through my lengthy
post and might actually be kind enough to reply :)
Best,
Jamie