Model Glue

Embed Size (px)

Citation preview

  • 8/3/2019 Model Glue

    1/69

    Model-Glue

  • 8/3/2019 Model Glue

    2/69

  • 8/3/2019 Model Glue

    3/69

    Table Of ContentsRead me first! .......................................................................................................1

    Don't Panic! .......................................................................................................1Installing Model-Glue ............................................................................................3

    Installing Model-Glue.........................................................................................3Prerequisites..................................................................................................3To Install Model-Glue on a Default Installation of ColdFusion (No mappingsrequired!): ......................................................................................................3To Install Model-Glue using ColdFusion mappings:.......................................4

    Quickstart..............................................................................................................5Quickstart ..........................................................................................................5Quickstart 1: Creating a New Application ..........................................................5Quickstart 2: Modeling our Application..............................................................6Quickstart 3: Building a Form Event ..................................................................7Quickstart 4: Handling a Form...........................................................................9

    Quickstart 5: Validating a Form .......................................................................13Quickstart 6: Adding a Site-Wide Template.....................................................15

    How To's.............................................................................................................17How To Add Custom Configuration.................................................................17

    How To Add Custom Configuration .............................................................17How To Use Generic Database Messages .....................................................18

    How To Use Generic Database Messages..................................................18modelglue.GenericCommit ..........................................................................19modelglue.GenericDelete ............................................................................22modelglue.GenericList .................................................................................22modelglue.GenericRead..............................................................................24

    How To Use Scaffolds.....................................................................................26How To Use Scaffolds .................................................................................26How To Add A Scaffold................................................................................26Adding Specific Event Handlers...................................................................27Using Broadcasts, Results and Views in Scaffolds......................................27Customizing Generated CFML ....................................................................28Customizing Scaffold .XSL Files..................................................................29

    Reference Materials............................................................................................31Reference Materials ........................................................................................31Model-Glue XML Reference............................................................................31

    Model-Glue XML Reference ........................................................................31

    Tags.............................................................................................................31ColdSpring XML Reference.............................................................................38

    ColdSpring XML Reference .........................................................................38Model-Glue Configuration Setting Definitions ..............................................39Reactor Configuration Setting Definitions ....................................................41

    Controller API..................................................................................................42Controller API ..............................................................................................42Adding a Message Listener Function...........................................................42

    iii

  • 8/3/2019 Model Glue

    4/69

    Printed Documentation

    AddToCache(name:string, value:any, [timeout:numeric]) ............................43GetFromCache(name:string) .......................................................................43GetModelGlue() ...........................................................................................43

    Model-Glue API...............................................................................................44Model-Glue API ...........................................................................................44

    GetBean(string:name) .................................................................................44GetConfigBean(string:name) .......................................................................44GetOrmService()..........................................................................................45

    Event API ........................................................................................................45Event API.....................................................................................................45AddResult(name:string) ...............................................................................45ArgumentExists(string:name).......................................................................45Forward(eventhandler:string [, append:list]) ................................................46GetAllValues()..............................................................................................46GetAllValues()..............................................................................................47GetArgument(name:string [, default:any])....................................................47

    GetValue(name:string [, default:any]) ..........................................................48GetView(name:string) ..................................................................................48MakeEventBean(type:any, [fields:list]).........................................................48Trace(name:string, value:any) .....................................................................49ValueExists(string:name).............................................................................49

    View API..........................................................................................................49View API ......................................................................................................49ViewCollection .............................................................................................50ViewCollection.Exists(name:string)..............................................................50ViewCollection.GetView(name:string)..........................................................51Viewstate .....................................................................................................51Viewstate.Exists(name:string)......................................................................51Viewstate.GetAll() ........................................................................................51Viewstate.GetValue(name:string [, default:any])..........................................52

    Upgrading From Model-Glue 1............................................................................53Upgrading_From_Model-Glue_1.....................................................................53

    Reverse Compatibility..................................................................................53Creating New Applications...........................................................................53

    Index...................................................................................................................55

    iv

  • 8/3/2019 Model Glue

    5/69

    Read me first!

    Don't Panic!

    Ah, you see, now you've gone and done it. You've either downloaded (or you'reshowing interest in downloading) a framework. Some would have you think thatyou're adding unnecessary complication to your development life, or that you'reabout to box yourself in with a set of rules.

    That's just silly hogwash.

    Welcome to Model-Glue. It's tidy, small, and simple to learn. Its rules don't existto confine you. Instead, they simply ask that you put certain kinds of code incertain places, and for very good reasons. By organizing your code a bit, you'll

    find that you start reusing more code, writing less bugs, and overall, having a lotless headaches and lot more time for things like walks in the park.

    1

  • 8/3/2019 Model Glue

    6/69

  • 8/3/2019 Model Glue

    7/69

    Installing Model-Glue

    Installing Model-Glue

    To install Model-Glue, all you need to do is copy a few files and possibly make afew mappings.

    Prerequisites

    Model-Glue 2.0 requires a few other bits to run. Installation is painless, andshould take about five minutes.

    1. The ColdSpring Framework must be downloaded and installed. It'savailable at www.coldspringframework.org. At present (Model-Glue 2.0Public Beta 1), ColdSpring's current version is Release Candidate 1.

    2. If you want to do any of the automated database interaction, such asscaffolding, the Reactor Framework must be downloaded and installed. Atpresent (Model-Glue 2.0 Public Beta 1), Reactor is not available as a .ZIP.For your convenience, it is included with the Model-Glue distribution .ZIP

    in the /Reactor directory. For the latest version, seehttp://trac.reactorframework.com.

    Note: If you want to use asynchronrous abilities inside of Model-Glue, you'll alsoneed own ColdFusion Enterprise as well as download/install the Concurrency

    Library fromhttp://www.corfield.org. You know who you are, and you're prettyadvanced.

    To Install Model-Glue on a Default Installation of ColdFusion (Nomappings required!):

    A default installation of ColdFusion is what you've got if you've simply installedColdFusion and used your existing Web root, like "c:\inetpub\wwwroot" as thelocation of your documents. In a default installation with a Web root of"c:\inetpub\wwwroot," a ColdFusion component named

    "ModelGlue.Util.GenericCollection" would be in the"c:\inetpub\wwwroot\ModelGlue\Util" directory.

    1. Unzip the Model-Glue distribution .zip2. Copy the ModelGlue folder into your Web root

    That's it.

    3

  • 8/3/2019 Model Glue

    8/69

    Printed Documentation

    To Install Model-Glue using ColdFusion mappings:

    1. Unzip the Model-Glue distribution .zip

    2. Put the ModelGlue folder somewhere permanent.3. Map /ModelGlue to wherever you've moved the ModelGlue folder.

    That's it.

    4

  • 8/3/2019 Model Glue

    9/69

    Quickstart

    Quickstart

    Why isn't there a book on Model-Glue? There are a few on Fusebox, right?

    It's because there's really not that much in Model-Glue. Its purpose is simple: tolet you write you application's logic in Object-Oriented ColdFusion Components,and then provide a way for you to connect a browser-based interface to thosecomponents. That shouldn't be a complicated task, so it's not a very complicatedframework, and this isn't really a long set of documentation.

    There are, however, a few things to learn: how to create an application, how tomove data back and forth between the interface and your components, and how

    to control the flow of your application. So that's what we're about to work on.

    This guide is a step-by-step guide to building a small translation application.We'll start with simple things: how to build a form, act on its data, and displayresults. Then, we'll see how the flexibility of Model-Glue's implementation ofMVC and Implicit Invocation make modifying and enhancing your application abreeze.

    Read carefully, there's a quiz at the end.

    Quickstart 1: Creating a New ApplicationAll Model-Glue applications start by creating a new copy of the "applicationtemplate." That's the directory named "modelglueapplicationtemplate" that camein your Model-Glue .zip.

    To deploy a new copy of the template, follow these steps:

    1. Create a new directory called "translator" under your Web root.2. Copy the contents of the /modelglueapplicationtemplate directory to the

    /translator directory.3. Open /translator/config/ColdSpring.xml4. Do a find and replace, changing "modelglueapplicationtemplate" to

    "translator"5. Open /translator/config/ModelGlue.xml6. Do a find and replace, changing "modelglueapplicationtemplate" to

    "translator"7. Open /translator/Application.cfm

    5

  • 8/3/2019 Model Glue

    10/69

    Printed Documentation

    8. Do a find and replace, changing "modelglueapplicationtemplate" to"translator"

    9. Open http://localhost/translator. You'll get a message saying that "Model-Glue is up and running!" If you don't, and you can't figure out why, now'sa good time to sign up for the Model-Glue listserv and post a question.

    Quickstart 2: Modeling our Application

    The "Model" for our application will consist of a single CFC that translates aphrase into, well, something else. In this case, we'll start with pig latin. To createa CFC-based Model for our application, do the following:

    1. Create a file in /translator/model called PigLatinTranslator.cfc2. Open the file, and paste in the following code. You'll see that it's a simple

    CFC with a constructor function named "init" that receives what letters areconsidered vowels. It only has one other function, "translate," which changes aphrase into Pig Latin.

    6

  • 8/3/2019 Model Glue

    11/69

    Quickstart

    And that's it. Our entire Model. It doesn't know anything about a user interface,or form variables, or session, or any of that stuff, so it's very, very reusable.

    Quickstart 3: Building a Form Event

    Model-Glue doesn't have "pages." Instead, it has "events." When you read"event" or "event handler," think "page." To access a given event handler (page!)in a Model-Glue application, you add ?event=eventHandlerNameto the URL.

    Ok, so to create a new event handler (page!), we add it to ModelGlue.xml. We'regoing to want to create an event handler that displays a form where the user canenter a phrase to translate.

    First, we need to create a .CFM file known as a "view". To do this, follow thesesteps:

    1. Create a file named "frmPhrase.cfm" in /translator/views.2. Paste the following code into the file. We'll explain a few odd parts in just

    a moment.

    Ok - what's with this "viewstate" stuff?

    Whenever you're writing a .CFM view, there are two variables always available:"viewstate" and "viewcollection." We'll get to viewcollection in a bit, but here's

    the rundown on viewstate:

    It contains all the variables FORM and URL scopes as well as any other valuesadded by the framework, like a query from a database or (big surprise) thetranslated version of the phrase that we're asking to user to enter.

    To get to one of the variables, you ask the viewstate variable to "get its value"with the getValue() function.

    There are a few "default" variables added to viewstate you need to be aware of:

    7

  • 8/3/2019 Model Glue

    12/69

    Printed Documentation

    "myself" is the URL of the current page with "?event=" added to it, such as"index.cfm?event="

    "self" is the URL of the current page without the "?event=" bit, such as"index.cfm"

    "event" is the name of the current event. Don't worry about this one. "eventValue" is the name of the URL variable that contains the current

    event. Don't worry about this one much, either.

    Therefore, the first line in that frmPhrase.cfm says "set the value of the submitvariable, which is the action value of the form, to whatever URL you get whenyou combine index.cfm?event= with the value of a viewstate variable named'xe.translate'"

    So what's with this "xe.translate" value? "XE" stands for "eXit Event," and hasemerged as a best practice in Model-Glue applications (because it's taken from a

    best practice in Fusebox!). It lets us reuse this view in multiple places becausewe determine the action page of the form at runtime, instead of hard coding it intoour .CFM template.

    So where does the value of xe.translate come from? It's time to learn a bit ofModel-Glue XML. (Don't worry! I just wrote the entire tag reference, and it's onlysixteen tags! And about five of them are just placeholders that contain othertags!)

    To create the actual event handler to display the form, do the following:

    Open /translator/config/ModelGlue.xml

    In the block, add a new event handler tag and give it a nameattribute of "translationForm". You should have this:

    Now, we need to add a "views" block to the event handler. This declares what.CFM templates should be included as part of this event handler. Adding theviews block and an tag (see, it's almost just like !) to theprior XML, we have this:

    8

  • 8/3/2019 Model Glue

    13/69

    Quickstart

    Now, we need to provide the value for "xe.translate." We do this with the (veryaptly named!) tag:

    Finally, run the page by visitinghttp://localhost/translator/index.cfm?event=translationForm . You should seeyour form. Viewing its source, you'll see that its action page isindex.cfm?event=translationFormAction.

    You've just learned about a quarter of the Model-Glue framework. Not too bad,eh?

    Quickstart 4: Handling a Form

    Ok, we've built a form. It submits to an event handler named"translationFormAction." Now, we need to create that event.

    Let's do it now. Add the following new event handler XML to/translator/config/ModelGlue.xml:

    9

  • 8/3/2019 Model Glue

    14/69

    Printed Documentation

    Ok, fire up a browser, go to

    http://localhost/translator/index.cfm?event=transationForm, fill in a phrase, andclick Ok.

    Not much happened, eh?

    Obviously, we need to tell the application to translate the phrase that's beenentered. Our first step is to add a message to the translationFormAction. Amessage is like a town crier: it's the event handler's way of saying "I need thephrase to be translated!" The event handler itself doesn't care who does thetranslation.

    Let's add the message:

    Try the form again if you like. Still nothing. That's because the event handlercan ask for translations until it's blue in the face (or view), but nothing's going tohappen unless something listensto the message.

    At the top of ModelGlue.xml, there's a block we haven't talkedabout yet. It declares a list of , which in turn contain a list of.

    It sounds complicated, but it isn't.

    You'll see that each tag has a TYPE attribute. That attribute pointsto a CFC known as a "Controller CFC". When Model-Glue starts, it creates aninstance of each Controller CFC listed.

    The tags simply tell the controller "Whenever an eventhandler broadcasts a message named MESSAGE, execute your function namedFUNCTION."

    So, to get something to translate, we need to tell our Controller to listen for theNeedTranslation message. Add a new tag to the default block, making it look like this:

    10

  • 8/3/2019 Model Glue

    15/69

    Quickstart

    Ok, now try the form. Again.

    Still nothing? There's one last piece to the puzzle: write a TranslatePhrasefunction in the Controller that asks our Model to translate a phrase! That's easyenough - just open /translator/controller/Controller.cfc and add the following:

    So what does all that do?

    First, arguments.event is like the twin sibling of the viewstate variable in a view.It has a getValue() method to get variables from the FORM and URL scopes.However, it also has a setValue() method that can set values into the viewstate,

    readable in views or later message listener functions.

    Second, it creates an instance of our application's Model CFC:

    Third, it gets the value of FORM.phrase

    11

  • 8/3/2019 Model Glue

    16/69

    Printed Documentation

    Fourth, it asks the model to translate the phrase:

    Fifth, it adds the results of the translation to the Model-Glue debugging output, so

    that we can see that it's been translated properly:

    Last, it sets the results of the translation into the viewstate so that our viewtemplates can display the data:

    Ok, finally, run the form! Seriously, something will happen this time! You won'tget much, but you'll see a line in the Model-Glue debugging trace labelled

    "TranslatePhrase Results" that shows the translated phrase.

    As a last step, let's add a view that shows our translated phrase. That'd probablymake users happy, because we'll turn the debugging trace off when we deploythis application.

    Following the same steps as we did when we built the form, first add adspPhrase.cfm file to /translator/views. You'll notice that we again use an eXitEvent, this time to build a link back to the translation form. To the link, weappend the "phrase" value. If you look back at frmPhrase.cfm, the VALUEattribute of our tag was set to viewstate.getValue("phrase").getValue(), by default, returns an empty string if a value is not defined. By

    appending the phrase to the URL, we can set the default value of the input box.

    Translated Phrase: #translatedPhrase#
    Translate Again.

    Second, tell the event handler to the view:

    12

  • 8/3/2019 Model Glue

    17/69

    Quickstart

    Wow. You now know about half of Model-Glue. There's really only anotherquarter or so that's fundamental knowledge, and the remaining bit after that is

    just icing on the cake that you'll use every now and then.

    Quickstart 5: Validating a Form

    Our translation form doesn't require the user to enter a value. Our applicationdoesn't fail, but it'd be nice to server-side validate the form.

    (Actually, it's not just nice, it's something you should do for every form, everytime.)

    Using the translateForm function, it's easy to check if the form has been filled out.However, how do we alert the user? How do we take them back to the form,

    instead of showing the result?

    The tag has a third child tag, , that's custom made forthings like this.

    Adding a and tag to our translationFormAction event handler,we end up with the following xml:

    13

  • 8/3/2019 Model Glue

    18/69

    Printed Documentation

    What does that tag mean? It means that if I somehow state that theevent has a validation error, immediately stop processing the event and redirectto the translationForm event.

    So how do we indicate that there's a validation error? We test a condition in ourcontroller, and if necessary, add the result to arguments.event:

    Doing this, the TranslatePhrase function now reads:

    Try the submitting the form without filling in a phrase. You'll wind up right back atthe form. That's OK, but we need to provide an error message.

    Remember, we can use controller functions to add values to the viewstate thatview templates can display. Let's first add an error message to TranslatePhrase:

    14

  • 8/3/2019 Model Glue

    19/69

    Quickstart

    Then, change frmPhrase.cfm to display the phrase error, if one has been set:

    #viewstate.getValue("phraseError")#

    Quickstart 6: Adding a Site-Wide TemplateIn Quickstart 5, we looked at how tags with a NAME attribute can beused to conditionally run other event handlers.

    However, what if we always want to run an additional event handler? Easy:don't give it a NAME attribute.

    If you look at your ModelGlue.xml file, there's an event handler named"view.template." It doesn't do much: no messages, no results, just a single.

    The include, though, is special. Open it up. (/translator/views/dspTemplate.cfm).

    See Line #13? "viewcollection.getView('body')"? What's with that?

    Model-Glue makes it easy to display the rendered HTML from one view inside ofanother. In all of your .CFM view templates, a variable named "viewcollection" is

    15

  • 8/3/2019 Model Glue

    20/69

    Printed Documentation

    available. To display the rendered HTML from a prior view, simply run getView(),passing it the value of the desired view's NAME attribute.

    In English: because we named our for frmPhrase.cfm anddspPhrase.cfm "body", we could use this event-handler to display a "wrapper"

    around their content.

    If only we could tell Model-Glue to run the view.template event handler aftertranslationForm and translationFormAction.

    Well, we could use a result tag, give it a name of "doTemplate," and always addthe result in a Controller function. But that'd be tedious.

    Instead, we can use an unnamedresult. Any unnamed result is considered"implicit," and will always be executed.

    So, if we add the following tag to our ModelGlue.xml event handlers forthe translation form and its action page, we can cause the view.template eventhandler to execute:

    I'd show you the XML, but I did say there was a quiz at the end. When you'veadded the result and gotten the sitewide template to work, you've finished theQuickstart!

    16

  • 8/3/2019 Model Glue

    21/69

    How To's

    How To Add Custom Configuration

    How To Add Custom Configuration

    Often, your application will need to know some configuration information, such asdatasource names or mailservers. For the sake of example, let's pretend thatyour application needs to use the tag, and you'd like to be able to storethe servername, username, and password settings in a file outside of yoursource code. That's just good practice.

    In Model-Glue:Unity, it's also really easy.

    Every Model-Glue:Unity application (that's not an upgrade from 1.x) has aColdSpring.xml that's intended to serve as the central store of all configurationinformation for your application.

    The file is organized into a series of tags. Each bean represents a CFCthat you can ask for inside of your Model-Glue application. Full use ofColdSpring is beyond the scope of this document - it's capable of a lot more thanwe're about to cover.

    Model-Glue:Unity comes with a bean(ModelGlue.Bean.CommonBeans.SimpleConfig) that's well suited for common

    configuration chores. It has a single property (config) that is a structure setthrough the setConfig() function. This structure serves as a "registry" ofconfiguration settings. Each setting can be requested through the bean'sgetConfigSetting() function by passing the name of the setting to retrieve.

    To apply this to the scenario of a mail server, we could add the following toColdSpring.xml:

    mail.mydomain.com

    smtpUsername

    smtpPassword

    17

  • 8/3/2019 Model Glue

    22/69

    Printed Documentation

    After the configuration XML is added to ColdSpring, using the configuration

    settings is easy. Below is an example listener function that uses theconfiguration settings in a tag:

    #message#

    How To Use Generic Database Messages

    How To Use Generic Database Messages

    One of the most compelling features of Model-Glue:Unity is its automateddatabase capabilities. By using the Reactor framework, Model-Glue:Unityautomates the creation and execution of common database tasks, such as singletable CRUD (create, read, update, delete) and basic listing (SELECT).

    The framework accomplishes this by automatically loading a controller (the"DataController") that listens for what are known as the "Generic DatabaseMessages" (GDMs) These are a set of commands you can use inside yourModelGlue.xml file to invoke automatic database functions.

    The GDMs also provide all data access functionality for event handlers createdthrough the tag.

    The four GDMs that the DataController is configured to listen for are as follows:

    18

  • 8/3/2019 Model Glue

    23/69

    How To's

    1. modelglue.GenericList

    When this message is broadcast, the DataController will attempt to listrecords from a given table.

    2. modelglue.GenericRead

    When this message is broadcast, the DataController will attempt to reada specific record from a given table.

    3. modelglue.GenericCommit

    When this message is broadcast, the DataController will attempt to savea record to a given table.

    4. modelglue.GenericDelete

    When this message is broadcast, the DataController will attempt to deletea record from a given table.

    modelglue.GenericCommit

    When this message is broadcast, the DataController will attempt to save arecord to a given table.

    It performs this action by doing the following:

    1. Loading an existing record to perform updates, or creating a new record toinsert of none matches the criteria specified.

    2. Updating the record's field values. By default, any field with acorresponding value in the viewstate (the combination of FORM and URLscopes) will be set to the value in the viewstate.

    This means that for a given contact, the value of a form input named"firstname" will automatically populate the Firstname property of a contact

    record.

    By default, the DataController will attempt to populate all fields from anylike-named values in the viewstate. To control which properties topopulate, use the "properties" argument as documented below.

    3. Validating the record by calling its Validate() method.4. If the record is valid, the DataController will save its data to the database

    19

  • 8/3/2019 Model Glue

    24/69

    Printed Documentation

    5. Last, the DataController adds one of two results: "commit" or"validationError". Adding result mappings for these result namesworks in the same manner as any other result mapping.

    This message is configured by using the following tags:

    1. Object (Required) - The name of the table to which to commit a record.2. Criteria (Required) - A list of viewstate values to use as filters. Any value

    listed whose name matches a column in the target table will be used as afilter in the query's WHERE clause. This will most often be set to a list ofthe table's primary keys. If left empty, a new record will be created. If agiven record matches the criteria specified, the record will be updated.Otherwise, a new record will be inserted.

    3. RecordName (Optional) - The name of the viewstate value to set theresultant record into. Defaults to Object & "Record".

    4. ValidationName (Optional) - The name of the viewstate value to set a

    collection of validation errors into. Defaults to Object & "Validation".5. Properties (Optional) - The names of the Record's fields to attempt topopulate from like-named values in the viewstate. Defaults to all of therecord's fields.

    Examples

    A Basic Generic Commit

    To perform a basic commit on the Contact table, the following tagcould be added to an :

    A View could then the record by performing the following code:

    A View could then any validation messages by performing thefollowing code:

    Assuming an event-handler name of "contact.commit", visiting the event handlerwith the following URL would result in updating ContactId 42's first name to"Fred".

    index.cfm?event=contact.commit&contactId=42&firstname=Fred

    20

  • 8/3/2019 Model Glue

    25/69

    How To's

    Customizing the Viewstate value name

    To perform a basic commit on the Contact table and specify viewstate valuenames for both the record and its validation, the following tag couldbe added to an :

    A View could then the record by performing the following code:

    A View could then any validation messages by performing the

    following code:

    Assuming an event-handler name of "contact.commit", visiting the event handlerwith the following URL would result in updating ContactId 42's first name to"Fred".

    index.cfm?event=contact.commit&contactId=42&firstname=Fred

    Committing Specific Properties

    To perform a basic commit on the Contact table where only the Firstname wouldbe updated, the following tag could be added to an :

    A View could then the record by performing the following code:

    A View could then any validation messages by performing thefollowing code:

    Assuming an event-handler name of "contact.commit", visiting the event handlerwith the following URL would result in updating ContactId 42's first name to"Fred" but not updating the lastname to "Finklebuster"

    21

  • 8/3/2019 Model Glue

    26/69

    Printed Documentation

    index.cfm?event=contact.commit&contactId=42&firstname=Fred&lastname=Fin

    klebuster

    modelglue.GenericDelete

    When this message is broadcast, the DataController will attempt to delete arecord from a given table.

    This message is configured by using the following tags:

    1. Object (Required) - The name of the table from which to delete.2. Criteria (Required) - A list of viewstate values to use as filters. Any value

    listed whose name matches a column in the target table will be used as a

    filter in the query's WHERE clause.

    Examples

    A Basic Generic Delete

    To perform a basic delete on the Contact table, the following tagcould be added to an :

    Assuming an event-handler name of "contact.delete", visiting the event handlerwith the following URL would result in deleting the contact with a ContactId of 42.

    index.cfm?event=contact.delete&contactId=42

    modelglue.GenericList

    When this message is broadcast, the DataController will attempt to list recordsfrom a given table.

    This message is configured by using the following tags:

    1. Object (Required) - The name of the table to list.

    22

  • 8/3/2019 Model Glue

    27/69

    How To's

    2. QueryName (Optional) - The name of the viewstate value to set theresultant query into. Defaults to Object & "Query".

    3. Criteria (Optional) - A list of viewstate values to use as filters. Any valuelisted whose name matches a column in the target table will be used as afilter in the query's WHERE clause.

    4. OrderBy (Optional) - A single column name by which to order the query.5. Ascending (Optional) - If set to true, order will be ascending. If set tofalse, order will be descending.

    Examples

    A Basic Generic List

    To perform a basic list on a Contact table, the following tag could beadded to an :

    A View could then the query by performing the following code:

    Customizing the Viewstate value name

    To perform a basic list on a Contact table and set it into a specific value in theViewstate, the following tag could be added to an :

    A View could then the query by performing the following code:

    Applying a Filter

    To perform a basic list on a Contact table that would filter on the viewstate'scurrent Firstname value, the following tag could be added to an:

    23

  • 8/3/2019 Model Glue

    28/69

    Printed Documentation

    Assuming an event-handler name of "contact.list", visiting the event handler withthe following URL would result in only contacts with a Firstname of "Fred" beingselected:

    index.cfm?event=contact.list&firstname=Fred

    Ordering

    To perform a basic list on a Contact table ordered by Lastname (ascending), thefollowing tag could be added to an :

    To reverse the order, the following argument tag could be added:

    A View could then the query by performing the following code:

    modelglue.GenericRead

    When this message is broadcast, the DataController will attempt to read aspecific record from a given table.

    This message is configured by using the following tags:

    1. Object (Required) - The name of the table from which to read.2. RecordName (Optional) - The name of the viewstate value to set the

    resultant record into. Defaults to Object & "Record".3. Criteria (Optional) - A list of viewstate values to use as filters. Any valuelisted whose name matches a column in the target table will be used as afilter in the query's WHERE clause. This will most often be set to a list ofthe table's primary keys. If left empty, a new record will be created.

    Examples

    24

  • 8/3/2019 Model Glue

    29/69

    How To's

    A Basic Generic Read

    To perform a basic read on a Contact table, the following tag couldbe added to an :

    A View could then the record by performing the following code:

    Note: Because no criteria were specified, this would return a new, empty record.

    Customizing the Viewstate value name

    To perform a basic read on a Contact table and set it into a specific value in the

    Viewstate, the following tag could be added to an :

    A View could then the record by performing the following code:

    Note: Because no criteria were specified, this would return a new, empty record.

    Reading a Specific Record

    To perform a basic read of a Contact record that would filter on the viewstate'scurrent ContactId value, the following tag could be added to an:

    Assuming an event-handler name of "contact.read", visiting the event handlerwith the following URL would result in reading a contact with a ContactId value of42.

    index.cfm?event=contact.read&contactId=42

    25

  • 8/3/2019 Model Glue

    30/69

    Printed Documentation

    How To Use Scaffolds

    How To Use Scaffolds

    Scaffolds are a tool by which you can very rapidly create basic user interfaces forediting the contents of a database table. By default, a single scaffold createsevents that can do the following:

    Display a "master list" of records in a table Display an editing form capable of editing both a record's data and its

    relations to other tables (one-to-many and many-to-many) Display a read-only view of a record Update a record's data Delete a record

    By learning to properly use scaffolds and modify the code they produce, you cangreatly reduce your development time for database-driven tasks.

    How To Add A Scaffold

    To add a scaffold:

    1. Add a table to your database. At present, it (and any tables it uses inrelationships) may only have one column acting as a primary key. For thesake of example, we'll pretend we've added a table named "Contact"

    2. If the table is related to other tables in a one-to-many or many-to-manymanner, add those relationships to the Reactor.xml file using ,, , and related tags. Full documentation for this isavailable in Reactor's documentation.

    3. Add the following tag to your ModelGlue.xml:

    By default, this will create the following event handlers:

    1. Contact.List - Lists all contacts from the contact table2. Contact.View - Displays a specific contact in a read-only manner3. Contact.Edit - Provides a form to edit a contact4. Contact.Commit - Saves a contact to the database5. Contact.Delete - Deletes a given contact

    26

  • 8/3/2019 Model Glue

    31/69

    How To's

    Adding Specific Event Handlers

    By default, the tag adds five event-handlers: table.list, table.view,table.edit, table.commit, table.delete.

    However, you may not want all of these added by default. To adjust the list ofscaffolds to automatically create, change the value of the DefaultScaffoldsproperty of the ModelGlueConfiguration bean in ColdSpring.xml. For example, toonly automatically create view and list scaffolds, the tag would be changed to thefollowing:

    list,view

    Edit, commit, delete, and delete scaffolds are still available, but would need to bespecified in the scaffold tag's TYPE attribute (see below).

    Using the TYPE attribute

    For a given scaffold tag, you may specify the list of event-handlers to create byusing the TYPE attribute of the scaffold tag. This is especially useful for applyingfunctionality such as security.

    For example, in a given application where anyone can view contacts but only

    administrators can update contacts, we could use the following XML inModelGlue.xml to protect the edit, commit, and delete event handlers fromunauthorized access (assuming a message listener for"UserMustBeAdministrator" performs security functionality and adds a resultnamed "SecurityViolation" in the event of bad access):

    Using Broadcasts, Results and Views in Scaffolds

    27

  • 8/3/2019 Model Glue

    32/69

    Printed Documentation

    As we've seen in "How To Add A Scaffold," a single scaffold tag simply serves todefine multiple event handlers. In order to keep the Model-Glue XML formateasy to learn, the scaffold tag supports the same child tags (broadcasts, views,and results) as an event handler tag.

    Any broadcasts, views, or results tags added beneath a scaffold tag are appliedto all event handlers a given scaffold creates. (To learn more about creatingbroadcasts, views, and results see the Quickstart guide).

    This allows us to extend the functionality of scaffolds in powerful ways.

    For example, to apply the sitewide template from the Model-Glue ApplicationTemplate to all of the event handlers created by a given scaffold, we can simplyadd a result tag:

    By splitting the types of scaffolds created amongst multiple scaffold tags for thesame object, we can even apply message broadcasts to specific scaffold-generated event handlers.

    In a given application where anyone can view contacts but only administratorscan update contacts, we could use the following XML in ModelGlue.xml to protectthe edit, commit, and delete event handlers from unauthorized access (assuming

    a message listener for "UserMustBeAdministrator" performs security functionalityand adds a result named "SecurityViolation" in the event of bad access):

    Customizing Generated CFML

    28

  • 8/3/2019 Model Glue

    33/69

    How To's

    Scaffold tags cause certain files to be generated, such as lists, views, and editforms. This generated code is placed into a directory governed by theScaffoldPath property of the ModelGlueConfigurationBean in ColdSpring.xml.

    Advanced note: The value of this setting is appended to the ViewMappings

    setting, making this directory the last-searched directory when an include tag isencountered.

    By default, the following .CFM templates are generated for each scaffolded table:

    1. dspTableList.cfm - Displays a list of records from the table2. dspTable.cfm - Displays a single record from the table3. frmTable.cfm - Displays an edit form for a single record from the table

    To customize the generated CFML, you cannot edit these files directly. Thiswould cause them to be overwritten the next time the framework is reloaded.

    To edit a view, simply copy it into the /views directory of your application. At thatpoint, your copy will not be overwritten. If additional database columns areadded, you'll be able to use the generated code as a source from which you cancopy and paste the new column's CFML.

    Advanced note: They can alternatively be copied into any directory listed in theViewMappings setting

    Customizing Scaffold .XSL Files

    It's possible to entirely change the View CFML that scaffold tags generate. Allinvolve editing .XSL files, which is way beyond the scope of this guide, but notaltogether complicated.

    There are three ways to customize the .XSL:

    Editing Default .XSL files

    If you explore the /ModelGlue/unity/xsl directory, you'll see that there are .XSLfiles that define the CFML to be generated when a like-named scaffold is added

    to an application.

    Editing these directly changes the behavior of all of your Model-Glueapplications.

    Creating New .XSL files

    29

  • 8/3/2019 Model Glue

    34/69

    Printed Documentation

    By creating your own .XSL files, you can again change the behavior of allscaffolds in all Model-Glue applications. To "tell" a given scaffold to use yourcustom .XSL file, do the following:

    1. Open /ModelGlue/unity/config/Configuration.xml

    2. Find the "eventHandlerFactory" bean3. In the map that defines the EventHandlerTypes constructor argument,change the .xsl files listed to point to your custom .XSL files

    Editing these directly changes the behavior of all of your Model-Glueapplications.

    Application-specific .XSL files

    To change the .XSL files used by a single Model-Glue applications, copy the

    entire EventHandlerFactory bean from /ModelGlue/unity/config/Configuration.xmlinto your application's ColdSpring.xml file.

    Then, follow the instructions in "Creating New .XSL Files," editing yourColdSpring.xml's EventHandlerFactory settings instead of those found in

    /ModelGlue/unity/config/Configuration.xml.

    30

  • 8/3/2019 Model Glue

    35/69

    Reference Materials

    Reference Materials

    It's only taken a year and a half to finally materialize, but this is a reference guidefor developing applications in the Model-Glue framework.

    It is not a thrilling read. It may be useful for learning the framework, but it'smainly a place to look things up.

    Model-Glue XML Reference

    Model-Glue XML Reference

    All Model-Glue applications are configured via at least one XML file that followsthe "Model-Glue" XML format described in this document.

    Tags

    A string value passed to a function registered to listen for a given message aspart of the function's Event argument. Its value can be acessed through the

    Event API's getArgument() method.

    Attributes

    1. Name (Required) - Defines the name of the argument.2. Value (Required) - Defines the value of this argument.

    Child Tags

    None

    Contains a list of tags. The tags will be broadcast in theorder in which they are defined.

    Attributes

    31

  • 8/3/2019 Model Glue

    36/69

    Printed Documentation

    None

    Child Tags

    1.

    Used in Model-Glue XML fragments to define additional settings and by legacyModel-Glue 1.x applications to define settings.

    This tag is largely unused in Model-Glue 2.0+!

    Attributes

    None

    Child Tags

    1.

    Defines a CFC that will act as a Controller in the application.

    Attributes

    1. Name (Required) - A unique name for this controller. A Model-Glueapplication where multiple controllers are added with the same name willcurrently confuse the framework (as of 2.0 Beta 1). This will eventually beresolved.

    2. Type (Required) - The CFC to use for a controller in the same format thatyou'd use in a CreateObject() call, such as"myapplication.controller.MyController"

    Child Tags

    None

    Contains a list of tags.

    32

  • 8/3/2019 Model Glue

    37/69

    Reference Materials

    Attributes

    None

    Child Tags

    1.

    Defines an event or "page" in the application.

    Attributes

    1. Name (Required) - A unique name for the event handler. This defineshow the event will be accessed through the URL, such as

    "index.cfm?event=MyEvent".

    If an is added whose NAME attribute is in use by anotherevent-handler, it will overwrite the previous event-handler, except in thecase of the predefined modelglue.onRequestStart,modelglue.onQueueComplete, and modelglue.onRequestEnd event-handlers. In this case, any messages, views, or results defined will beadded to the predefined event handlers.

    2. Access (Optional, defaults to "public") - If set to "private," the eventhandler cannot be accessed directly through the URL.

    Child Tags

    1. 2. 3.

    Contains a list of child tags that define the events in the application.

    Attributes

    None

    Child Tags

    33

  • 8/3/2019 Model Glue

    38/69

    Printed Documentation

    1. 2.

    Defines a path to another Model-Glue XML file to include.

    Useful for breaking up large Model-Glue XML files into multiple fragments.

    Attributes

    1. Template (Required) - The path to the file to include. ColdFusion will useexpandPath() to turn this into an absolute path to a file.

    Child Tags

    None

    Defines a .CFM template to , creating HTML that will be viewable bythe user.

    Model-Glue will search the mappings listed in the ViewMappings setting (definedin the application's ColdSpring.xml file) in order, searching for the templatedefined in the TEMPLATE attribute.

    Attributes

    1. Name (Required) - The name by which the rendered content will be knownin the ViewCollection

    2. Template (Required) - The filename of a .CFM template inside one of thedirectories in the ViewMappings setting

    3. Append (Optional, default = "false") - If an include by this NAME hasalready been rendered, should the content from this include be appendedto the existing content or should it overwrite the existing content? (Falsewill overwrite, True will append.)

    Child Tags

    1.

    Relates a inside of a Controller CFC to a message that is broadcastvia a tag inside of an 's block.

    34

  • 8/3/2019 Model Glue

    39/69

    Reference Materials

    Attributes

    1. Message (Required) - The name of a message for which to listen, definedby the tag's NAME attribute.

    2. Function (Required) - The name of a public on the relatedController CFC to execute whenever a is broadcast whoseNAME attribute matches the value of the MESSAGE attribute

    Child Tags

    None

    Defines a message to be broadcast during the execution on an event handler.Messages are broadcast in the order in which they are defined.

    Attributes

    1. Name (Required) - The name of the message. The same message maybe broadcast multiple times during a single event handler, with or withoutdifferent sets of arguments. Any message-listener tags whose MESSAGEattribute value matches the value of attribute will execute the functionregistered via their FUNCTION attribute.

    Child Tags

    1.

    Declares the root of a Model-Glue XML file.

    Attributes

    Child Tags

    1. 2. 3. 4.

    35

  • 8/3/2019 Model Glue

    40/69

    Printed Documentation

    Defines an additional event-handler to execute as part of the current request.Can use the NAME attribute to determine whether or not a certain result should

    be executed, and the REDIRECT attribute to abort the current request andredirect to a different event handler.

    Model-Glue will search the mappings listed in the ViewMappings setting (definedin the application's ColdSpring.xml file) in order, searching for the templatedefined in the TEMPLATE attribute.

    Attributes

    1. Do (Required) - The NAME attribute of an event handler to add to thisrequest.

    2. Name (Optional) - If not set or set to an empty string, the event handlerdeclared in the DO attribute will always be added to the request. If notempty, the event handler declared will only execute if a function in aController CFC uses the addResult() method of the Event API to add aresult with the value of the NAME attribute.

    3. Redirect (Optional, default = "false") - If true, a redirect will immediatelyredirect the entire request to the event handler declared in the DOattribute. All state value will be maintained if session is enabled.

    4. Append (Optional, default = ) - Used to define a list of value names(from the viewstate) that should be appended to the URL.

    Example: If APPEND is set to articleId and DO is set to article, theredirect URL would be index.cfm?event=article&articleId=[value ofarticleId].

    Advanced, rarely used attributes:

    5. PreserveState (Optional, default = "true") - If set to false and REDIRECTis set to true, the all state values will removed before redirecting to theevent handler declared in the DO attribute

    6. Reset (Optional, default="false") - If set to true, any previously declaredresults of the same name will be erased. This is only useful for redefiningresults added by scaffolds.

    Child Tags

    None

    Contains a list of tags.

    Attributes

    36

  • 8/3/2019 Model Glue

    41/69

    Reference Materials

    None

    Child Tags

    1.

    Automatically defines and creates user interface for listing and editing data froma database table. By default, creates object.list, object.view, object.edit,object.commit, and object.delete event-handlers, where objectis the value of theOBJECT attribute. This list of event-handlers to create is controlled by the TYPEattribute.

    Attributes

    1. Object (Required) - The name of the database table to scaffold2. Type (Optional, defaults to "list,view,edit,commit,delete") - What types of

    event-handlers to create

    Child Tags

    1. 2. 3.

    Used in Model-Glue XML fragments to define additional settings and by legacyModel-Glue 1.x applications to define settings.

    This tag is largely unused in Model-Glue 2.0+!

    Special Behavior

    A setting tag with a NAME attribute value of "viewMappings" will append its value

    to the list of existing viewMappings.

    A setting tag with a NAME attribute value of "beanMappings" will (ColdSpring)load the file defined into the BeanFactory or (ChiliBeans) append its value to thelist of existing beanMappings.

    All other settings are simply set.

    37

  • 8/3/2019 Model Glue

    42/69

    Printed Documentation

    Attributes

    1. Name (Required) - The name of the setting to set2. Value (Required) - The value of the setting

    Child Tags

    None

    A string value to set into the ViewState before the .CFM template in the currentinclude is rendered. Its value may be accessed through the ViewState object inthe View API.

    Attributes

    1. Name (Required) - Defines the name of the argument.2. Value (Required) - Defines the value of this argument.3. Overwrite (Optional, default = "true") - If set to true, this value will

    overwrite an existing same-named value in the ViewState.

    Child Tags

    None

    Contains a list of tags. The tags will be run in the order inwhich they are defined.

    Attributes

    None

    Child Tags

    1.

    ColdSpring XML Reference

    ColdSpring XML Reference

    38

  • 8/3/2019 Model Glue

    43/69

    Reference Materials

    Model-Glue:Unity introduces the ColdSpring.xml file to the Application Template.

    This file replaces the block that was at the top of 1.x ModelGlue.xmlfiles.

    It acts as a place to both configure your application and define additional beansaccessed through the GetBean() method of the Model-Glue API.

    By default, it contains two beans:1. ModelGlueConfiguration - the settings for the Model-Glue framework

    instance in your application. Each setting is explained in the "Model-GlueConfiguration Setting Definitions" section of this reference.

    2. ReactorConfiguration - if the Reactor framework is installed (necessary forautomated database access and scaffolding), these are the settings thatwill be used to configure Reactor in place of a block at the top ofReactor.xml. Each setting is explained in the "Reactor Configuration

    Setting Definitions" section of this reference.

    Model-Glue Configuration Setting Definitions

    Configuration Setting Definitions

    In your ColdSpring.xml file, the modelGlueConfiguration bean definesenvironment parameters for the instance of Model-Glue framework that runs theapplication.

    Changing these parameters alters the behavior of the framework.

    This document explains each setting and its behavior.

    Debug

    Debug can be set to TRUE or FALSE.

    Setting to TRUE will cause the Model-Glue debugging trace to be displayed atthe bottom of every page.

    DefaultCacheTimeout

    The default cache timeout variable for controller-based caching.

    DefaultExceptionHandler

    The name of an event handler tag to run in the event of an exception.

    39

  • 8/3/2019 Model Glue

    44/69

    Printed Documentation

    When an exception is detected, a new value named "exception" is added to theviewstate containing the cfcatch structure from the exception.

    DefaultScaffolds

    The list of scaffold types to generate when no TYPE attribute is specified for agiven scaffold tag.

    DefaultTemplate

    The name of the .CFM file that all requests use. Defaults to "index.cfm".

    EventValue

    The name of the URL variable that contains the event handler tag to execute.

    Defaults to "event."

    If changed to "do," the url "index.cfm?do=somePage" would execute the"somePage" event handler.

    GeneratedViewMapping

    The directory in which to put all view .CFM templates generated via scaffold tags.

    Reload

    The reload setting can be set to TRUE or FALSE.

    When TRUE, the application will re-read the ModelGlue.xml, ColdSpring.xml andReactor.xml files on each request, reloading the framework and using anychanges made to these files.

    When FALSE, the application will not reload the framework or detect changes tothese files.

    It is imperative that any application deployed in a production environment havereload set to FALSE.

    ReloadKey

    The name of the URL variable used to force reloading of the framework. When aURL variable by this name is added to the query string with a value matchingRELOADPASSWORD's setting, the framework will reload regardless of itsRELOAD setting value.

    40

  • 8/3/2019 Model Glue

    45/69

    Reference Materials

    This can be used to force the framework to reload in a production environment.

    Using the default values for RELOADKEY and RELOADPASSWORD, this wouldbe done by appending ?init=true to the URL.

    ReloadPassword

    The value of the URL variable named by the RELOADKEY setting. When a URLvariable by this name is added to the query string with a value matchingRELOADPASSWORD's setting, the framework will reload regardless of itsRELOAD setting value.

    This can be used to force the framework to reload in a production environment.

    Using the default values for RELOADKEY and RELOADPASSWORD, this wouldbe done by appending ?init=true to the URL.

    Rescaffold

    Rescaffold may be set to TRUE or FALSE.

    Generating scaffolds in a processor-intensive process. As more scaffolds areadded, the framework may be slow to respond when the RELOAD setting is setto TRUE. By setting RESCAFFOLD to FALSE, changes to ModelGlue.xml,ColdSpring.xml, and Reactor.xml will be detected, but scaffolds will not be re-generated, and changes to scaffold tags will not be detected.

    StatePrecedence

    Possible values are FORM and URL.

    Model-Glue combines all values from FORM and URL into a single structurecalled the viewstate. If STATEPRECEDENCE is set to FORM, FORM variableswill overwrite like-named URL variables. If set to URL, the opposite will occur.

    ViewMappings

    The list of directories in which .CFM templates to use as views will be found. Thelist is searched in order.

    Reactor Configuration Setting Definitions

    DSN

    The datasource name reactor is to use.

    41

  • 8/3/2019 Model Glue

    46/69

    Printed Documentation

    Mapping

    The directory in which to place generated CFC files.

    Mode

    Possible values are PRODUCTION, DEVELOPMENT, and ALWAYS.

    PRODUCTION will never inspect database tables for changes.

    DEVELOPMENT will inspect database table for changes and regenerate files asnecessary.

    ALWAYS will regenerate files on every request to the ReactorFactory.

    PathToConfigXML

    The path (acted upon by expandPath()) to the Reactor.xml file used to relateobjects.

    Project

    The name of this project. This will be the name of a subdirectory in/reactor/project.

    Type

    The database type to use, such as mysql or mssql. See Reactor'sdocumentation for all available values.

    Controller API

    Controller API

    A Controller in a Model-Glue application extends the ModelGlue.Core.ControllerCFC.

    The base controller contains a set of functions known as the Controller API.

    These functions are available inside all controllers and provide controller-relatedfunctionality.

    Adding a Message Listener Function

    42

  • 8/3/2019 Model Glue

    47/69

    Reference Materials

    To add a function that can be registered via a tag, thefunction must have a RETURNTYPE attribute of VOID, and a single argument oftype "any".

    AddToCache(name:string, value:any, [timeout:numeric])

    Description

    Adds the value passed to the controllers internal cache, using the name passedas a key. If timeout is passed, it is the lifespan, in minutes, of the value passed.

    Returns

    Void

    Arguments

    Name (Required) - The key by which to identify this value in the cache.Value (Required) - The value to cacheTimeout (Optional) - The number of minutes to store the value in the cache.Defaults to the DefaultCacheTimeout setting set the ModelGlueConfiguration

    bean in ColdSpring.xml.

    GetFromCache(name:string)

    Description

    Gets a value from the cache with a matching name. If the value does not exist,an error of type ModelGlue.Util.TimedCache.ItemNotFound will be thrown.

    Returns

    Any

    Arguments

    Name (Required) - The key of the value to retrieve.

    GetModelGlue()

    Description

    Returns the Model-Glue framework itself

    Returns

    43

  • 8/3/2019 Model Glue

    48/69

    Printed Documentation

    ModelGlue.unity.framework.ModelGlue

    Arguments

    None

    Model-Glue API

    Model-Glue API

    Inside of a controller, calling getModelGlue() will return an instance of the Model-Glue framework.

    Of the (many) public methods returned, the only commonly used method isGetConfigBean().

    GetBean(string:name)

    Description:

    Returns a CFC instance from the IoC container.

    Returns:

    A CFC Instance

    Arguments:

    Name (Required) - The name of the bean to create. If ColdSpring is used, thename listed is the ID attribute of the bean to be created. If ChiliBeans is used,the name passed is the name of an XML file to be found in one of the directorieslisted by the beanMappings setting.

    GetConfigBean(string:name)

    Deprecated in favor of GetBean(). Still functional to support reversecompatibility.

    44

  • 8/3/2019 Model Glue

    49/69

    Reference Materials

    GetOrmService()

    Description:

    Returns the ORM service Model-Glue is configured to use for automated

    database access. By default, this will return reactor.ReactorFactory.

    Returns:

    A CFC Instance

    Arguments:

    None

    Event API

    Event API

    When a function in a controller is called as a result of a tag,it is passed an instance of the ModelGlue.unity.eventrequest.EventContext CFC.

    This CFC contains a series of functions known as the Event API that are usefulto getting and setting values in the viewstate as well as event-related utilities.

    AddResult(name:string)

    Adds a result by the given name. If a tag exists in the currentlyexecuting whose NAME attribute matches the value passed, the declared in its DO attribute will be added to the request.

    Returns:

    Void

    Arguments:

    Name (Required) - The name of the result to add

    ArgumentExists(string:name)

    Description:

    Does a value of the given name exist in the current message tag's argumentsblock?

    45

  • 8/3/2019 Model Glue

    50/69

    Printed Documentation

    Returns:

    Boolean

    Arguments:

    Name (required) - The name of the argument to check

    Forward(eventhandler:string [, append:list])

    Description:

    Immediately redirects the request to the event handler named. All values in theviewstate are maintained across the redirect if session is enabled.

    Returns:

    Void. The function call never completes - a interrupts its execution.

    Arguments:

    EventHandler (Required) - The name of the event handler to redirect toAppend (Optional) - Will append the list of values passed in append to theresultant URL.

    Example:

    GetAllValues()

    Description:

    Returns the structure that contains all argument members by reference.

    Returns:

    Struct

    Arguments:

    46

  • 8/3/2019 Model Glue

    51/69

    Reference Materials

    None

    GetAllValues()

    Description:

    Returns the structure that contains all viewstate members by reference.

    Returns:

    Struct

    Arguments:

    None

    GetArgument(name:string [, default:any])Description:

    Returns a value from the current message tag's arguments block.

    Returns:

    Any

    Arguments:

    Name (required) - The name of the argument to retrieveDefault (optional) - If the argument does not exist, a default value to return. It isnotset into the argument collection - the collection is read-only.

    Example:

    47

  • 8/3/2019 Model Glue

    52/69

    Printed Documentation

    GetValue(name:string [, default:any])

    Description:

    Returns a value from the viewstate, such as a form or url variable.

    Returns:

    Any

    Arguments:

    Name (required) - The name of the value to retrieveDefault (optional) - If the value does not exist, a default value to set into theviewstate and then return

    GetView(name:string)

    Description:

    Returns the rendered content of a view.

    Returns:

    String

    Arguments:

    Name (required) - The name of the view to retrieve

    MakeEventBean(type:any, [fields:list])

    Description:

    Loops over a CFC instance, looking for any methods whose names start with

    set. For any setter methods where a like-named value exists in the viewstate,the setter will be called, passing this value.

    Returns:

    CFC Instance

    Arguments:

    48

  • 8/3/2019 Model Glue

    53/69

    Reference Materials

    Type (Required) - If a string is passed, it will instantiate a CFC of the type passedand attempt to call a function named "init" if one exists. If a CFC instance ispassed, it will use the instance.Fields (Optional) - If a list of fields is passed, it will only attempt to set theproperties listed.

    Trace(name:string, value:any)

    Description:

    Adds the value to the debugging trace and gives it the name passed. If acomplex value is passed, the result of its is displayed.

    Returns:

    Void

    Arguments:

    Name (Required) - A label to identify the value in the debugging traceValue (Required) - The value to display in the debugging trace. If a complexvalue is passed, the result of its is displayed.

    ValueExists(string:name)

    Description:

    Does a value of the given name exist in the viewstate?

    Returns:

    Boolean

    Arguments:

    Name (required) - The name of the value to check

    View API

    View API

    49

  • 8/3/2019 Model Glue

    54/69

    Printed Documentation

    Inside of a .CFM template used as a view, two CFC instances are available in theunnamed or "variables" scope: viewstate and viewcollection.

    Viewstate is used to access values from the viewstate.

    Viewcollection is used to access the rendered HTML of prior views.

    ViewCollection

    In a .CFM template used as a View in a Model-Glue Application, the"viewcollection" variable gives access to the rendered results of prior views.

    This can be used to "stack" views. The following example shows a simple eventhandler in which one view, dspBody.cfm, is used inside of another(dspTemplate.cfm):

    Hi, I'm dspBody.cfm!

    dspTemplate.cfm#viewcollection.getView("body")#

    ViewCollection.Exists(name:string)

    Description:

    Does a view of the given name exist in the viewcollection?

    Returns:

    Boolean

    Arguments:

    50

  • 8/3/2019 Model Glue

    55/69

    Reference Materials

    Name (required) - The name of the view to check

    ViewCollection.GetView(name:string)

    Description:

    Returns the rendered results of a prior rendered view whose NAME attribute isthe name argument passed. If the view does not exist, returns an empty string.

    Returns:

    String

    Arguments:

    Name (required) - The name of the view's content to retrieve

    Viewstate

    In a .CFM template used as a View in a Model-Glue Application, the "viewstate"variable gives access to form and url data, along with any values added in acontroller function through the Event.SetValue() method of the Event API.

    Viewstate.Exists(name:string)Description:

    Does a value of the given name exist in the viewstate?

    Returns:

    Boolean

    Arguments:

    Name (required) - The name of the value to check

    Viewstate.GetAll()

    Description:

    Returns the structure that contains all viewstate members by reference.

    51

  • 8/3/2019 Model Glue

    56/69

    Printed Documentation

    Returns:

    Struct

    Arguments:

    None

    Viewstate.GetValue(name:string [, default:any])

    Description:

    Returns a value from the viewstate, such as a form or url variable.

    Returns:

    Any

    Arguments:

    Name (required) - The name of the value to retrieveDefault (optional) - If the value does not exist, a default value to set into theviewstate and then return

    52

  • 8/3/2019 Model Glue

    57/69

    Upgrading From Model-Glue 1

    Upgrading_From_Model-Glue_1

    This document is intended for developers already using Model-Glue 1.x. It's notan introduction to Model-Glue, and serves only to outline differences betweeen1.x and 2.x.

    Reverse Compatibility

    Applications written for Model-Glue 1.x should be 100% reverse compatible whenupgraded to the Model-Glue 2.x codebase. If, for some reason, your applicationis not, please post a ticket to http://trac.model-glue.com immediately. Reveresecompatibility issues are given the highest priority.

    Creating New Applications

    When you create a new application using the Model-Glue 2.x applicationtemplate, you'll immediately notice that there is no longer a single ModelGlue.xmlfile in the /config directory. Instead, there are three files:

    1. ModelGlue.xml2. ColdSpring.xml3. Reactor.xml

    The largest different you'll notice is that the block is no longer inModelGlue.xml. Instead, the settings for the framework are in ColdSpring.xml.The XML format is a little different, but still self-explanatory. The settings are

    named the same, and still perform the same function. There are a few newsettings, such as "rescaffold." Explanation of each setting can be found in theColdSpring XML Reference section of the Reference Materials documentation.

    53

  • 8/3/2019 Model Glue

    58/69

  • 8/3/2019 Model Glue

    59/69

    Index

    1

    1.x 171.x ModelGlue.xml 3822.x. 53442

    ContactId 2242&firstname 19AAcessed 31Adding

    dspPhrase.cfm file 9Message Listener Function 42Site-Wide Template 15Specific Event Handlers 27

    Adding 9Adding 15Adding 27Adding 42AddResult 35, 45AddToCache 43Aeiou 9, 13

    AListOfContacts 22ALWAYS 42APPEND 35Application Template 38Application-specific 29Applying

    Filter 22Applying 22Argument 31ArgumentExample 47ArgumentExists 45Arguments.event 13Arguments.event.getArgument 47Arguments.event.getValue 9, 13, 17Arguments.phrase 6Arguments.vowels 6Article&articleId 35Article, 35Article.view 46

    Article.view&articleId 46

    ArticleId 35value 35ArticleId 35ArticleId 46Asynchronrous 3BBasic Generic Commit 19Basic Generic Delete 22Basic Generic List 22Basic Generic Read 24BeanFactory 37

    BeanMappingsexisting 37BeanMappings 37BeanMappings 44Beta 32Betweeen 1.x 53Br 9Broadcasts 31Building

    Form Event 7Building 7

    C

    CallinggetModelGlue 44

    Calling 44Cause

    view.template 15Cause 15Cfargument 6, 9, 13, 17CFC

    Defines 32instantiate 48points 9represents 17Returns 44use 32

    CFC 6CFC 9CFC 17CFC 32

    55

  • 8/3/2019 Model Glue

    60/69

    Printed Documentation

    CFC 42CFC 44CFC 45CFC 48CFC 49

    CFC Instance 44, 45, 48Cfcatchviewstate containing 39

    Cfcatch 39CFC-based Model

    create 6CFC-based Model 6Cfcomponent 6Cfdump 19, 22, 24, 49Cfdump var 19, 22, 24Cfelseif len 6

    Cfform 7, 13Cffunction 6, 9, 13, 17, 34Cfif 6, 13Cfif len 6Cfif viewstate.exists 13Cfinclude 7, 34Cfinput 7, 9, 13Cflocation 46CFM 7, 28, 34, 38, 40, 41, 49, 50, 51CFM file 7, 40CFM view 7, 15Cfmail 17CFML

    define 29CFML 28CFML 29Cfoutput 9, 50Cfoutput>#viewcollection.getView 50Cfoutput>

  • 8/3/2019 Model Glue

    61/69

    Index

    ContactId 24ContactId 42's

    updating 19ContactId 42's 19ContactQuery 22

    ContactRecord 19, 24ContactValidation 19Controller 9, 13, 15, 18, 32, 34, 35,

    42, 44, 45, 51Controller API 42Controller CFC 9, 34, 35Controller contains 42Controller functions 13Controllers 43Controller-based 39Controller-related 42

    CopyModelGlue 3Copy 3CreateObject 9, 13, 32Creating

    CFC-based Model 6New 29New Application 5New Applications 53

    Creating 5Creating 6Creating 29Creating 53Creating New 29CRUD 18Customizing

    Generated CFML 28Scaffold 29

    Customizing 28Customizing 29DDatabase-driven 26DataController 18, 19, 22, 24Datasource 17, 41Debug 39Default Installation

    ColdFusion 3Default Installation 3DefaultCacheTimeout

    Defaults 43

    DefaultCacheTimeout 39DefaultCacheTimeout 43DefaultExceptionHandler 39Defaults

    DefaultCacheTimeout 43

    Editing 29Object 19, 22, 24Defaults 19Defaults 22Defaults 24Defaults 29Defaults 43DefaultScaffolds 27DefaultScaffolds 27DefaultScaffolds 40DefaultTemplate 40

    DefinesCFC 32CFML 29EventHandlerTypes 29

    Defines 29Defines 32Deletes 26DEVELOPMENT 42Displays

    list 28Displays 26Displays 28DO 35, 45Documetnation

    set 5Documetnation 5DoTemplate 15Download/install

    Concurrency Library 3Download/install 3DSN 41DspBody.cfm 50DspPhrase.cfm 9, 13, 15DspPhrase.cfm file

    add 9DspPhrase.cfm file 9DspTable.cfm 28DspTableList.cfm 28DspTemplate.cfm 50

    57

  • 8/3/2019 Model Glue

    62/69

    Printed Documentation

    EEdit,commit,delete 27Editing

    Default 29Editing 29

    Eh 7, 9English 15Event 31Event API 35, 45, 51Event API's getArgument 31Event.SetValue 51Eventhandler 46Event-handler>'s 34EventHandlerFactory 29EventHandlerName

    URL 7

    EventHandlerName 7Event-handlers 33EventHandlerTypes

    defines 29EventHandlerTypes 29EventValue 7, 40Existing

    beanMappings 37viewMappings 37Web 3

    Existing 3Existing 37EXit Event 7, 9ExpandPath 42Explanation 53Extends

    ModelGlue.Core.Controller CFC42

    Extends 27Extends 42FFALSE

    set 40Filter

    Applying 22Filter 22Finklebuster 19First, arguments.event 9Firstname

    populate 19

    Firstname 19Firstname 22FirstVowel 6FirstVowel gt 6Following

    URL 19, 22, 24xml 13Following 13Following 19Following 22Following 22Following 24Font>

  • 8/3/2019 Model Glue

    63/69

    Index

    GetModelGluecalling 44

    GetModelGlue 17, 43GetModelGlue 44GetOrmService 45

    GetValue 7, 9, 48GetView 15, 48HH1>dspTemplate.cfm

  • 8/3/2019 Model Glue

    64/69

    Printed Documentation

    Model-Glue 17Model-Glue 18Model-Glue 27Model-Glue 29Model-Glue 31

    Model-Glue 31Model-Glue 32Model-Glue 32Model-Glue 34Model-Glue 34Model-Glue 35Model-Glue 35Model-Glue 37Model-Glue 38Model-Glue 39Model-Glue 39

    Model-Glue 41Model-Glue 42Model-Glue 43Model-Glue 44Model-Glue 45Model-Glue 50Model-Glue 51Model-Glue 53Model-Glue 1.x 32, 37, 53Model-Glue 1.x. 53Model-Glue 2.x application 53Model-Glue 2.x codebase 53Model-Glue API 38, 44Model-Glue Application 50, 51Model-Glue Application Template 27Model-Glue Configuration Setting

    Definitions 38Model-Glue debugging 9Model-Glue XML Reference 31ModelGlue.Bean.CommonBeans.Si

    mpleConfig 17ModelGlue.Core.Controller CFC 42Modelglue.GenericCommit 18, 19Modelglue.GenericDelete 18, 22Modelglue.GenericList 18, 22Modelglue.GenericRead 18, 24Modelglue.onQueueComplete 33Modelglue.onRequestEnd 33Modelglue.onRequestStart 33

    ModelGlue.unity.eventrequest.EventContext CFC 45

    ModelGlue.unity.framework.ModelGlue 43

    ModelGlue.Util.GenericCollection 3

    ModelGlue.Util.TimedCache.ItemNotFound 43ModelGlue.xml 7, 9, 15, 26, 27, 40,

    41, 47, 50, 53ModelGlue.xml file 15, 18, 53ModelGlue/unity/config/Configuration

    .xml 29ModelGlue/unity/xsl 29Modelglueapplicationtemplate 5Modelglueapplicationtemplate.contro

    ller.Controller 9

    ModelGlueConfiguration 27, 38, 39,43ModelGlueConfigurationBean 28Moved

    ModelGlue 3Moved 3Mssql 42MVC 5Myapplication.controller.MyController

    32MyCommittedContact 19MyContact 24MyController 9MyEvent 33Mysql 42NNAME

    value 35NAME 15, 33, 34NAME 35NAME 37NAME 45NAME 51Names

    Record's 19subdirectory 42URL 7, 40

    Names 7Names 19Names 40

    60

  • 8/3/2019 Model Glue

    65/69

    Index

    Names 40Names 42NeedTranslation

    listen 9NeedTranslation 9

    NeedTranslation 13NewCreating 29

    New 29New Application

    Creating 5, 53New Application 5New Application 53Now 9OObject

    Defaults 19, 22, 24value 37Object 19Object 22Object 24Object 37Object.commit 37Object.delete 37Object.edit 37Object.list 37Object.view 37Object-Oriented ColdFusion

    Components 5OnRequestEnd 9OnRequestStart 9Open

    /ModelGlue/unity/config/Configuration.xml 29

    Open /translator/Application.cfm 5Open

    /translator/config/ColdSpring.xml 5Open

    /translator/config/ModelGlue.xml 5,7

    OrderBy 22ORM

    Returns 45ORM 45PPanic 1

    PathToConfigXML 42PhraseError 13Pig Latin 6PigLatinTranslator 6PigLatinTranslator.cfc 6

    Please 13PointsCFC 9

    Points 9Populate

    Firstname 19Populate 19PreserveState 35Processor-intensive 41PRODUCTION 42Project 42

    Provides 26QQuery 22QueryName 22Quickstart 5, 6, 7, 9, 13, 15, 27RReactor Configuration Setting

    Definitions 38Reactor Framework 3, 18, 38Reactor.ReactorFactory 45Reactor.xml 38, 40, 41, 53Reactor.xml file 26, 42Reactor/project 42ReactorConfiguration 38ReactorFactory

    request 42ReactorFactory 42Reactor's 26, 38Reading

    Contact 24Specific Record 24

    Reading 24Record

    names 19Record 19Record 24RecordName 19, 24Red 13REDIRECT 35Reference Materials 31, 53

    61

  • 8/3/2019 Model Glue

    66/69

    Printed Documentation

    ReFindNoCase 6Reload 40, 41RELOADKEY

    values 40, 41RELOADKEY 40

    RELOADKEY 41ReloadPassword 41RELOADPASSWORD's

    matching 40, 41RELOADPASSWORD's 40RELOADPASSWORD's 41Represents

    CFC 17struct 17

    Represents 17Request

    ReactorFactory 42Request 42Rescaffold

    setting 41Rescaffold 41Rescaffold 53Result 27, 35, 36Returns

    CFC 44ORM 45

    Returns 44Returns 45ReturnType 6, 9, 13, 17, 42Reverese 53Reverse Compatibility 53Run

    view.template 15Run 15SSaves 26Scaffold

    Customizing 29How To Add 27To Add 26

    Scaffold 26Scaffold 27Scaffold 28Scaffold 29Scaffold 37Scaffold-generated 27

    ScaffoldPath 28SecurityViolation 27See Line 15See Reactor's 42SELECT 18

    Self-explanatory 53SendEmail 17Servername

    store 17Servername 17Set

    documetnation 5FALSE 40FORM 41RESCAFFOLD 41TRUE 39, 40, 41

    URL 41Set 5Set 39Set 40Set 41Set 41Set. 48SetConfig 17Setter 48SetValue 9Sitewide 15, 27Site-Wide Template

    Adding 15Site-Wide Template 15SomeArgument 47SomePage 40SomeValue 47Special Behavior 37Specific Event Handlers

    Adding 27Specific Event Handlers 27Specific Properties

    Committing 19Specific Properties 19Specific Record

    Reading 24Specific Record 24StatePrecedence 41Store

    servername 17

    62

  • 8/3/2019 Model Glue

    67/69

    Index

    Store 17Struct

    represents 17Struct 17Struct 46

    Struct 47Struct 51Subdirectory

    name 42Subdirectory 42Subj 17TTable.commit 27Table.delete 27Table.edit 27Table.list 27

    Table.view 27TEMPLATE 34, 35That's 5That's OK 13Timeout 39, 43To Add

    Scaffold 26To Add 26To Add Custom Configuration 17To Use Generic Database Messages

    18To Use Scaffolds 26Trace 49TransationForm 9Translated Phrase 9TranslatedPhrase 9, 13TranslateForm 13TranslatePhrase

    write 9TranslatePhrase 9TranslatePhrase 13TranslatePhrase Results 9, 13TranslationForm 7, 9, 13, 15TranslationForm# 9TranslationFormAction 7, 9, 13, 15Translator.model.PigLatinTranslator

    9, 13Translator.translate 9, 13Translator/config/ModelGlue.xml 9Translator/controller/Controller.cfc 9

    Translator/model 6Translator/views 7, 9Translator/views/dspTemplate.cfm

    15TRUE

    set 39, 40, 41TRUE 34TRUE 39TRUE 41TYPE 9, 27, 37, 40, 42UUpdating

    ContactId 42's 19lastname 19

    Updating 19Upgrading_From_Model-Glue_1 53

    URLeventHandlerName 7following 19, 22, 24name 7, 40set 41value 41

    URL 7URL 9URL 19URL 22URL 22URL 24URL 33URL 35URL 40URL 40URL 41URL 41URL 46URL 48URL 51URL 52Use

    CFC 32ColdSpring 17viewstate values 19, 22, 24

    Use 3, 9, 13, 15Use 17Use 18Use 19

    63

  • 8/3/2019 Model Glue

    68/69

    Printed Documentation

    Use 22Use 22Use 24Use 26Use 26

    Use 27Use 27Use 28Use 29Use 32Use 33Use 34Use 35Use 40Use 41Use 41

    Use 42Use 45Use 48Use expandPath 34UserMustBeAdministrator 27Username 17Using Broadcasts 27VValidate

    Form 13Validate 13Validate 19Validation 13, 19ValidationError 13, 19ValidationForContact 19ValidationName 19Value

    articleId 35NAME 35OBJECT 37RELOADKEY 40, 41URL 41xe.translate 7

    Value 7Value 9Value 35Value 37Value 38Value 40Value 41

    Value>mail.mydomain.comsmtpPasswordsmtpUsername

  • 8/3/2019 Model Glue

    69/69

    Index

    Web 3Web 5We'll 7Whenever 9WHERE 19, 22, 24

    WriteTranslatePhrase 9Write 9XXE 7Xe.translate

    value 7Xe.translate 7Xe.translate 13Xe.translationForm 9, 13XML

    following 13

    XML 7, 9XML 13XML 15XML 17XML 27

    XML 27XML 31XML 32XML 34XML 35XML 37XML 38XML 44XML 53XML fragments 32, 37XSL 29

    XSL Files 29