Conditionally calling a listener's method within an event

7 views
Skip to first unread message

Phil Ewington - iModel Ltd.

unread,
Nov 9, 2009, 11:07:12 AM11/9/09
to mach-ii-for...@googlegroups.com
Hi All,

Totally new to Mach II, building first app and got a question about the events.

I have an event to create a registration and want to conditionally call another method in my listener if the registration is based upon a referral. The following shows my event-handler, the second notify command being the conditional method...

<event-handler event="createIndividual" access="private">
        <notify listener="IndividualListener" method="createIndividual" />
        <notify listener="IndividualListener" method="createIndividualReferral" />
        <view-page name="home" contentArg="layout.content" />
        <announce event="layoutpage" copyEventArgs="true" />
</event-handler>

My thinking is...

1) I could write the conditional call within my service layer. Not happy about this as the functionality gets 'hidden' away from other developers.
2) I could use a filter and have different event handlers to handle the result. I have lots of these types of conditions in my events and would rather not have a huge collection of event-handlers unless of course I have no option/no better way of doing it.

Is there a specific/preferred way to achieve this using Mach II? Any help will be much appreciated.

Kind regards,

Phil.

Matthew Woodward

unread,
Nov 9, 2009, 11:38:32 AM11/9/09
to mach-ii-for...@googlegroups.com

On Mon, 09 Nov 2009 16:07:12 +0000, "Phil Ewington - iModel Ltd."
<phil.e...@i-model.co.uk> wrote:
> Totally new to Mach II, building first app and got a question about the
> events.

Welcome to Mach-II!

> I have an event to create a registration and want to conditionally call
> another method in my listener if the registration is based upon a
> referral.

If the other method in your listener is never called independently, you
probably want this other method in your service, not in your listener.

> My thinking is...
>
> 1) I could write the conditional call within my service layer. Not happy
> about this as the functionality gets 'hidden' away from other developers.

I would conditionally make a call to your service layer from within your
listener. At least that's what seems right to me based on what you're
saying thus far.

> 2) I could use a filter and have different event handlers to handle the
> result. I have lots of these types of conditions in my events and would
> rather not have a huge collection of event-handlers unless of course I
> have no option/no better way of doing it.

That sounds unnecessarily complicated.

I may not have the full picture, but in your listener method I'd probably
do:
<cfif isReferral> <!--- or however you determine if it's a referral --->
<cfset getMyService().doReferralStuff(event.getArg("arg1"),
event.getArg("arg2")) />
</cfif>

That way you can pass whatever event arguments you need to as part of the
referral bit.

Definitely let me know if I'm missing a piece of the puzzle.
--
Matthew Woodward
ma...@mattwoodward.com
http://mpwoodward.posterous.com
identi.ca/Twitter: @mpwoodward

Please do not send me proprietary file formats such as Word, PowerPoint,
etc. as attachments.
http://www.gnu.org/philosophy/no-word-attachments.html

Phil Ewington - iModel Ltd.

unread,
Nov 9, 2009, 12:01:13 PM11/9/09
to mach-ii-for...@googlegroups.com
Hi Matt,

Thank you for your quick response!

In this instance the method will never get called independently so will move to the service layer as per your suggestion as this makes perfect sense. I will encounter further similar scenarios during development with methods that can be called independently in which case I will call the service layer conditionally.

Thanks for your help.

- Phil.


Matthew Woodward

unread,
Nov 9, 2009, 12:24:04 PM11/9/09
to mach-ii-for...@googlegroups.com

No problem at all. Fire away with other questions as you dig deeper into
Mach-II.

Reply all
Reply to author
Forward
0 new messages