event-bean with ORM?

9 views
Skip to first unread message

Mike Rogers

unread,
Oct 27, 2009, 1:15:02 PM10/27/09
to Mach-II for CFML
All,

I've been looking over the tickets and documentation for the mach-ii
event-bean config tag, and I was wondering if an extra attribute would
have any value:

<event-bean name="user" type="project.model.User" factory-
method="newUser"/>

My project is using Transfer, and my Model is a thin proxy over
Transfer. For example, project.model.User has the getNewUser() method
which returns transfer.new("project.User"), and saveUser() takes a
TransferObject as an argument and runs transfer.save(arguments.user).
Fairly straightforward, but it completely abstracts away the ORM.

I was also wondering whether I'm 'correct' in my desire to use ORM
objects as event-beans, or whether I should be creating beans
specifically for form interaction and using a transformation method to
populate the ORM objects, probably in the Listener. This approach
seems like it would require a lot of extra code over my ORM/Event dual
beans.

Thoughts?

I apologize for the rambling tone. If I need to clarify something
please let me know.

Thanks,

-Mike Rogers

Jorge Loyo

unread,
Oct 27, 2009, 1:49:27 PM10/27/09
to Mach-II for CFML
Mike,

I also use Transfer and I've been using a filter to create the
transfer bean and put it in the event scope. I think that there was
some discussion about in the future possibly supporting factories, but
I can't recall exactly where that talk ended. I would definitely be
interested in having something like this.

Mike Rogers

unread,
Oct 27, 2009, 3:34:02 PM10/27/09
to Mach-II for CFML
That's a fantastic idea. Since I'm using ColdSpring as well as
Transfer (and all my Transfer proxies are defined in ColdSpring), I
wrote the following little filter to put a ColdSpring bean (grabbed
via factory method discussed in my previous email) into the event
object. Not sure how useful it is to anyone but me, but I figured I'd
throw it out there anyway:

<cfcomponent displayname="CreateColdSpringEventBeanFilter"
extends="MachII.framework.EventFilter"
output="false"
hint="Uses a factory/facade method to put an empty bean into the
event">

<!--- INITIALIZATION / CONFIGURATION --->
<cffunction name="configure" access="public" returntype="void"
output="false"
hint="Configures the filter.">
<!--- Put custom configuration for this filter here. --->
</cffunction>

<!--- PUBLIC FUNCTIONS --->
<cffunction name="filterEvent" access="public" returntype="boolean"
output="false"
hint="I am invoked by the Mach II framework.">
<cfargument name="event" type="MachII.framework.Event"
required="true"
hint="I am the current event object created by the Mach II
framework." />
<cfargument name="eventContext"
type="MachII.framework.EventContext" required="true"
hint="I am the current event context object created by the Mach II
framework." />
<cfargument name="paramArgs" type="struct" required="false"
default="#structNew()#"
hint="I am the structure containing the parameters specified in the
filter invocation in mach-ii.xml." />

<cfset var bean = paramArgs.bean />
<cfset var beanName = paramArgs.name />

<cfset var propManager = eventContext.getAppManager
().getPropertyManager() />
<cfset var csProp = propManager.getProperty("coldspringProperty") /
>

<cfset var eventBean = '' />
<cfset var beanFactory = '' />

<cfif IsStruct(csProp)>
<cfset beanFactory = getProperty(csProp.getParameter
("beanFactoryPropertyName")) />
<cfif IsStruct(beanFactory) AND StructKeyExists(beanFactory,
"getBean" )>
<cfset eventBean = beanFactory.getBean(bean) />
</cfif>
</cfif>

<cfset event.setArg(beanName, eventBean) />

<cfreturn true/>
</cffunction>

</cfcomponent>


Here's an example from mach-ii.xml:

<event-handler event="login.action" access="public">
<event-mapping event="pass" mapping="main.redirect"/>
<event-mapping event="fail" mapping="home.redirect"/>
<filter name="createColdSpringEventBeanFilter">
<parameter name="bean" value="blankUserObject"/>
<parameter name="name" value="user"/>
</filter>
<event-bean name="user" type="@cf.app.root@.model.UserModel"
reinit="false"
fields="email,password"/>
<notify listener="userListener" method="login"/>
</event-handler>

If anyone finds this helpful please let me know. I don't want to fill
up the group with useless garbage!

Thanks,

-Mike Rogers

Peter J. Farrell

unread,
Oct 27, 2009, 4:25:41 PM10/27/09
to mach-ii-for...@googlegroups.com
Mike,

This topic would make a great addition to the wiki.  Would you do us the favor of writing a short entry with your code as well?

Best,
.Peter

Mike Rogers said the following on 10/27/2009 02:34 PM:

Kurt Wiersma

unread,
Oct 27, 2009, 8:46:10 PM10/27/09
to mach-ii-for...@googlegroups.com
Another way to solve this would be use the new call-method command
which lets you call out to a service from a ColdSpring bean factory
and place the result in the event scope where the event-bean command
can access it. I think it makes more sense to use either this method
or the filter method rather then baking something more limited into
the event-bean command. If you try either of these out and run into
problems let us know.

--Kurt

Mike Rogers

unread,
Oct 27, 2009, 9:47:07 PM10/27/09
to Mach-II for CFML
I've replaced the following code:

<filter name="createColdSPringEventBeanFilter">
<parameter name="bean" value="blankUserObject"/>
<parameter name="name" value="user"/>
</filter>

... with ...

<call-method bean="userModel" method="getNewLogin"
resultArg="user"/>

... and the code is throwing an error: A call-method commands was
encountered that did not have a bean named
'cfCallMethodCommand2ecfc1771628066$funcGETBEANID@3e77f8' autowired
into it.

"Autowired to it" is a phrase I found on the Call-Method M2SFP page
(http://greatbiztoolsllc.trac.cvsdude.com/mach-ii/wiki/
MachII1.8CallMethodCommand) in a comment by Peter: "Call-method will
call anything that get's auto-wired into it so if say in this example
it is in a ColdSpring bean factory -- it can be loaded into the call-
method command".

Apparently I'm missing some sort of auto-wiring, but I haven't found
this in any docs. Could someone point me in the right direction?

Thanks,

-Mike Rogers

Peter J. Farrell

unread,
Oct 27, 2009, 10:02:23 PM10/27/09
to mach-ii-for...@googlegroups.com
Doesn't look like your CS managed beans are being auto-wired into the call-method.  Are you using the ColdSpringProperty that is bundled *with* Mach-II (not the CS package).  I would bet the ColdSpring property you're using is the one in the ColdSpring bundle.  You'll need to use the one bundled with Mach-II.

Also, is there a bean with the "id" of "UserModel" in your ColdSpring config file?

.pjf

Mike Rogers said the following on 10/27/2009 08:47 PM:

Peter J. Farrell

unread,
Oct 27, 2009, 10:09:47 PM10/27/09
to mach-ii-for...@googlegroups.com
If my suggestions don't fix it, I'll need a stack trace or a snapshot of exception you're getting.

.pjf

Peter J. Farrell said the following on 10/27/2009 09:02 PM:

Jorge Loyo

unread,
Oct 28, 2009, 11:40:49 AM10/28/09
to Mach-II for CFML
Hi all,

I also have a filter that looks into the relationships of a transfer
object and creates the object with the associations. I use this filter
instead of the <event-bean> to include my transfer objects in the
event scope.

Would anyone be interested in the .CFC to perhaps compare all
different approaches and possibly combine solutions into one more
complete one?
Reply all
Reply to author
Forward
0 new messages