I prefer results over forwards because it gives me greater control in the
event handler over how the different outcomes are treated. In particular,
there are two features of results that I like to use:

   1. A <result> element can queue an event without a redirect.
   2. An event handler can ignore a result issued by a controller by not
   defining a named <result> element for it.

Many of my event handlers tend to look like this (apart from the names):

<event-handler name="my.form-processor">
    <broadcasts>
        <message name="handleFormProcessing" />
    </broadcasts>
    <results>
        <result name="formHasErrors" do="my.error-event" redirect="true" />
        <result do="my.success-event" />
    </results>
</event-handler>

In this case I'd likely declare the "my.success-event" event handler as
access="private" so that it cannot be invoked directly.

I'd still have my controller call event.addResult("formProcessingSuccess")
even if this handler doesn't need it, as the cost of adding an unused result
should be small and a future event handler might have a use for it.

One situation where I do use forward() is security controllers, because many
of my event handlers must broadcast security messages and all security
violations are redirected to the same event in the application. Using
forward() saves me from having to scatter something like <result
name="notAuthorized" do="security.accessDenied" redirect="true" /> all
around my ModelGlue.xml. I do however support an optional message argument
to let event handlers forward security violations to a different event.

Cheers,

-- Dennis

On Mon, Mar 15, 2010 at 11:35 PM, Matt Quackenbush <[email protected]>wrote:

> Consider the use case of form processing in MG3.  The request should be
> redirected based upon the success or failure of the processing.
>
> Which of the following is your preferred method, and why?
>
> <!--- Scenario #1: Controller (pseudo-code) --->
> <cffunction name="doSomething">
>     <cfargument name="Event" />
>
>     <cfscript>
>         if ( beans.myService.success() ) {
>             forward("my.success-event");
>         } else {
>             forward("my.error-event");
>         }
>     </cfscript>
> </cffunction>
>
>
> <!--- Scenario #2: ModelGlue.xml --->
> <event-handler name="my.form-processor">
>     <broadcasts>
>         <message name="handleFormProcessing" />
>     </broadcasts>
>     <results>
>         <result name="formHasErrors" do="my.error-event" redirect="true" />
>         <result name="formProcessingSuccess" do="my.success-event"
> redirect="true" />
>     </results>
> </event-handler>
>
> Thanks in advance.
>
> --
> Model-Glue Sites:
> Home Page: http://www.model-glue.com
> Documentation: http://docs.model-glue.com
> Bug Tracker: http://bugs.model-glue.com
> Blog: http://www.model-glue.com/blog
>
> You received this message because you are subscribed to the Google
> Groups "model-glue" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<model-glue%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/model-glue?hl=en

-- 
Model-Glue Sites:
Home Page: http://www.model-glue.com
Documentation: http://docs.model-glue.com
Bug Tracker: http://bugs.model-glue.com
Blog: http://www.model-glue.com/blog

You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

Reply via email to