Hello Chaps,

 

I've been working with both CS and MG for a while now and we're getting on
famously together, It took me a while to feel comfortable with relinquishing
that control over to the frameworks, but once done I can genuinely feel the
development benefits, it's quite amazing.

 

This past weekend I've made my first ventures into studying the benefits of
the AOP concepts which are available to me in CS, and they have gotten me
quite excited to say the least, however trying to find some good working
examples of how to apply them within a MG/CS application is becoming quite
tricky and I'm struggling to figure this stuff out, so thought I'd come
looking for a little help.

 

For the sake of argument and example, let's take a simple task like
validating some data which is being passed to a service object. I'll give
some basic mocked examples of my controller and advice object that I have at
the moment.

 

Controller:

 

<cffunction name="registerUser" access="public" output="false"
returntype="any">

      <cfarguments name="Event" type="any" required="true" hint="I'm the
event" />

 

            <!--- Create New User --->

            <cfset var NewUser =
VARIABLES.Instance.UserService.create(ARGUMENTS.Event.getValue("name")) />

 

      <cfreturn ARGUMENTS.Event />

</cffunction>

 

Now obviously that's very stripped down version of my controller method, but
for the sake of argument let keep it as simple as possible. Now, I need to
validate that 'name' variable to ensure that it doesn't have any numbers in
it, if it does then I want to throw the user back to the form page with an
error message. Take a look at my basic advice object below:

 

Advice Object:

 

<!--- Advice Method --->

<cffunction name="invokeMethod" access="public" returntype="any" hint="I
supply the advice to the method call">

      <cfargument name="methodInvocation"
type="coldspring.aop.MethodInvocation" required="false" />

 

            <!--- Create Temporary Local Structure --->

            <cfset var LOCAL = structNew() />

 

            <!--- Validate Data --->

<cfif refind("[0-9]", arguments.methodInvocation.getArguments().Name)>

      <!--- Data Not Valid --->

<cfelse>

      <!--- Data Valid --->

</cfif>

      

      <!--- Return Out --->

      <cfreturn />

</cffunction>

 

Now this is where I become a little confused, see, in the old days I would
validate the data inside my controller, and if the data failed validation I
would add a result of 'failed' and update the viewstate with an error
message, then use the events xml definition to pass the user back to the
form if the result of 'failed' was present.

 

However, from what I can see here I have no access to the event object from
my advice object, so I'm not able to add results or update the view state,
All I can do is simply return a value, is that correct? How do I use the
advice object to control the user back to the form with an error message?
I'm feeling a little confused about it.

 

Thanks for any 'advice' guys, I really appreciate your time.

 

Rob



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Get the answers you are looking for on the ColdFusion Labs
Forum direct from active programmers and developers.
http://www.adobe.com/cfusion/webforums/forum/categories.cfm?forumid-72&catid=648

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:290526
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to