Wow.. Thanks for the prompt response..I'm really enjoying model-glue and the supportive community..
Looking forward to coding it all in tomorrow.. Cliff Sent from my iPad On Aug 24, 2010, at 9:03 PM, Dennis Clark <[email protected]> wrote: > Hi Clifford, > > There are many different ways to go about this, with many variations. I will > give just one approach. > > If you need to tell whether a save was an update or a create, I suggest > modifying the saveHonors() method to return a value that indicates this. For > example: > > <cffunction name="saveHonors" access="public" returntype="boolean" > output="false" hint="Return true if create, false if update"> > <cfargument name="Honors" type="any" required="true"/> > > <cfif val( Honors.getID() ) GT 0 ><!--- Update ---> > <cfset getHonorsDAO().update( arguments.Honors ) /> > <cfreturn false /> > <cfelse><!--- Insert ---> > <cfset getHonorsDAO().create( arguments.Honors ) /> > <cfreturn true /> > </cfif> > </cffunction> > > Next, modify your HonorsFormSubmitted method to record the save status and > the saved HonorsBean into the event context: > > <cfset var HonorsCreated = "" /> > <cfif isValid > > <cfset HonorsCreated = HonorsService.saveHonors( > HonorsBean ) /> > <cfset arguments.event.setValue("HonorsCreated", > HonorsCreated ) /> > <cfset arguments.event.setValue("HonorsBean", > HonorsBean ) /> > <cfset arguments.event.addResult("Success") /> > <cfelse> > <cfset arguments.event.setValue("ErrorStruct", > ErrorStruct) /> > <cfset arguments.event.addResult("Failure") /> > </cfif> > > Now, define a controller method called "emailSavedHonors" that uses > arguments.event.getValue("HonorsBean") and > arguments.event.getValue("HonorsCreated") to generate an email. Ideally the > code that actually does the <cfmail> will be in a service CFC retrieved from > ColdSpring, e.g. getModelGlue().getBean( "EmailService"). Remember to define > an <message-listener> for the controller method. > > Next, define a private event handler to broadcast the new message: > > <event-handler name="EmailSavedHonors" access="private"> > <broadcasts> > <message name= "emailSavedHonors" /> > </broadcasts> > </event-handler> > > Finally, add a result to your existing event handlers to queue this new event > on success: > > <event-handler name="SubmitHighSchoolFormData" type="templatedPage"> > <broadcasts> > <message name= "HonorsFormSubmitted" /> > </broadcasts> > <results> > <result name="success" do="EmailSavedHonors" /> > <result name="success" > do="HighSchoolApplicationResponse" /> > <result name="failure" do="highschool" /> > </results> > </event-handler> > > With all that in place, your HonorsFormSubmitted controller method should put > all the data needed for emailing into the event context, and the event > handler should queue one event to send the email and another event to return > a response to the client. > > We'll be here if you have any further questions. Good luck! > > -- Dennis > > On Tue, Aug 24, 2010 at 5:36 PM, Clifford Moon <[email protected]> > wrote: > Greetings, > > I'm working on our first ModelGlue app, and have modeled it pretty > much identical to the tutorial that Dan has on the NoDans.com > website. I'm saving a form using the controller.cfc, and utilizing > Service/Gateway/DAO breakdown as was setup in the tutorial. Here is a > snippet of the controller.cfc code where I'm actually saving the form. > <cffunction name="HonorsFormSubmitted" access="public" > returnType="void" output="false" hint="???"> > <cfargument name="event" type="any"> > <cfset var HonorsBean = getModelGlue().getBean("HonorsBean") / > > > <cfset var HonorsService = > getModelGlue().getBean( "HonorsService") /> > <cfset var HonorsList = HonorsService.getHonorsListActive() /> > <cfset var ErrorStruct = structNew() /> > <cfset var isValid = false /> > > <cfset arguments.event.makeEventBean( HonorsBean ) /> > <cfset isValid = HonorsBean.validate (ErrorStruct) /> > > <cfif isValid > > <cfset HonorsService.saveHonors( HonorsBean ) /> > <cfset arguments.event.addResult("Success") /> > <cfelse> > <cfset arguments.event.setValue("ErrorStruct", > ErrorStruct) /> > <cfset arguments.event.addResult("Failure") /> > </cfif> > > </cffunction> > > My Issue is that after I save this form, I need to email several > individuals various files/data that they will need. If the data > validates and then saves, I'm confused how to get the ID of the record > that was just saved, and where I need to place the call to the EMAIL > function. We are using an Oracle Database for this application. > Should the call to EMAIL be in the isValid CFIF above, and if so, how > do I pass something back from the DAO file that can tell me that it > was CREATED and not UPDATED. > > Hope I haven't confused anyone, and thanks in Advance for any help. > I'm still floundering with the ModelGlue concepts, but reading the > tutorials and newsgroups have given us lots of help. > > I'm including the BEAN, DAO, GW,MODELGLUE.XML and SERVICE Files in > case they are needed.. > > -- > 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 -- 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
