So, to distill your question down even further, you are basically asking how
small the units of work should be in your controller.

In the first example, your broadcasts put a single concept into the event. (
User, UserDepartments, UserRegions) In the second example your broadcasts,
puts several concepts into the event.

Generally, I would use both techniques as appropriate. If we can be sure
we'll never need to get at the User Departments on their own, then there's
no point in having a specific broadcast/controller method to load them.

If we aren't sure, or if they will stand on their own at some point, I'd
break them out.

The refactor path from multi-concept loading to single concept loading isn't
that difficult normally so it's not much of a pain if you choose
incorrectly.


DW

On Tue, Jan 18, 2011 at 11:53 AM, [email protected] <[email protected]>wrote:

> I've been using model-glue for a while and have started to wonder how
> other people would structure their event handlers, message listeners
> and controllers.  Here's the example problem and 2 different way's
> I've figured out how to solve it.
>
> The scenario is a typical user edit form. We'll need to lookup a user
> record and populate 2 select boxes with queries, one for department
> and one for region.
>
> <event-handler name="user.edit">
>  <broadcasts>
>    <message name="needUser" />
>    <message name="needUserDepartments" />
>    <message name="needUserRegions" />
>  </broadcasts>
>  <results />
>  <views>
>    <include template="/user/edit_form.cfm" />
>  </views>
> </event-handler>
>
> In the Controller each of the messages will call a function that will
> load the proper query into the event.
>
> The 2nd way I've figured out how to do it is:
> <event-handler name="user.edit">
>  <broadcasts>
>    <message name="needUserEditData" />
>  </broadcasts>
>  <results />
>  <views>
>    <include template="/user/edit_form.cfm" />
>  </views>
> </event-handler>
>
> Where the user edit function will look like:
> <cffunction name="user_edit_form">
>  <cfargument name="event" />
>  <cfset event.setValue('userObj', transfer.get('user',
> event.getValue('user_id'))>
>  <cfset event.setValue('regionsQry', transfer.list('regions'))>
>  <cfset event.setValue('departmentsQry',
> transfer.list('departments'))>
> </cffunction>
>
> I can see advantages and disadvantages to each way, but was wondering
> what the community prefers and why.
>
> --
> 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




-- 
Plutarch - "The mind is not a vessel to be filled but a fire to be kindled."

-- 
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