Visit Sponsor

Written by 8:20 pm ColdFusion, Model-Glue, Rapid Development, Tutorials

So you want to create a ModelGlue:Unity application? ( Part 5 )

Previously in this series, we installed the ModelGlue:Unity framework and the ColdSpring framework. We used the ModelGlueApplicationTemplate as the skeleton, added our basic flow and navigation. We can save and list contacts and our validation is working nicely,

In this section of our Contact-O-Matic, we will pull out the contact types values from coldspring and used them to add defined categories to our contacts. In a previous segment, we added the Contact Types as a ‘map’ in ColdSpring, now we will pull out the values and add them to our form.

Inside the *ContactManagerMG/Config/ColdSpring.xml file the bean definition for ContactService.cfc looks like this:


Friend
Co-Worker
Enemy

In order to provide a proper separation in our code, we add a new ‘message-listener’ tag with the message attribute of ‘needContactTypes’ and the function attribute of ‘getContactTypes’.



Then in our ‘contact.view’ event-handler, add a new message tag inside broadcasts tag. Your ‘contact.view’ event-handler should look as follows:








<include name="body" template="frmContact.cfm">

</include>





Note: If copying this code directly, you must change the & lt; to a proper <

Next, in our *ContactManagerMG.controller.controller.cfc, we add a new function called ‘getContactTypes’. This function will pull out the ‘ContactTypes’ map, or struct, from our ContactService and place them in the event.







Finally, we open our form, located at *ContactManagerMG/views/frmContact.cfm. Pull out the ContactTypes from the event and loop through to create a select box of values. Your completed form should look like this:






  • #ErrorStruct[ errorType ]#


  • Name:

    Type:



    Once you reset your application and click the ‘contact’ tab, you should have a functional select box in your form.

    Look Ma, a select box

    Proper application design would most likely not include storing the data for your select boxes inside coldspring. After all, that is what a database is for. The purpose of this exercise is to show how to retrieve data from ColdSpring to use in your applications.

    A practical use of ColdSpring would be to define an email service inside ColdSpring to operate in two modes, production and development. In production mode, the email service would send emails to each email it was passed. In development mode, the email service would send an email to a developer email address. Thus, changing from development mode to production mode is as easy as changing a line in your ColdSpring.xml file.

    If you have ever accidently spammed your users whilst testing application email functionality, you can appreciate the benefits ColdSpring offers.

    The fruits of our labor

    Yay! data integrity

    Visited 8,946 times, 1 visit(s) today
    [mc4wp_form id="5878"]
    Close