Version 2 (modified by cfgrok, 16 years ago)

Tweaks to training formatting

Error: Failed to load processor TOC
No macro or processor named 'TOC' found

Section 8: Extending Model-Glue

The Model-Glue framework is highly extensible. If you don't like the way Model-Glue handles a certain function, you can override Model-Glue. This is a simple process because Model-Glue uses ColdSpring under the covers. In this walk-through, we will make Model-Glue use a custom scaffold template without actually modifying Model-Glue framework files.

  1. Create a new directory in /PlantOMatic/model called scaffoldTemplates
  2. Open /ModelGlue/gesture/modules/scaffold/beans, copy the following files and paste them into the newly created scaffoldTemplates directory:
  • /ModelGlue/gesture/modules/scaffold/beans/Edit.cfc
  • /ModelGlue/gesture/modules/scaffold/beans/List.cfc
  1. Open each file and change the name attribute in the view tag:
<view name="body" template...

To:

<view name="primary" template...

  1. Open /PlantOMatic/config/ModelGlue.xml and add the following tag after the closing </event-types> tag:
<scaffold object="Plant" event-type="templatedPage" />

  1. Next, open /PlantOMatic/config/ColdSpring.xml and change:
<property name="rescaffold"><value>false</value></property>

To:

<property name="rescaffold"><value>true</value></property>

  1. In the same ColdSpring.xml file paste in the following XML:
<bean id="modelglue.scaffoldType.Edit" class="coldspring.beans.factory.config.MapFactoryBean">
  <property name="SourceMap">
    <map>
      <entry key="class"><value>PlantOMatic.model.scaffoldTemplates.Edit</value></entry>
      <event key="hasXMLGeneration"><value>true</value></event>
      <event key="hasViewGeneration"><value>true</value></event>
      <entry key="prefix"><value>Form.</value></entry>
      <entry key="suffix"><value>.cfm</value></entry>
    </map>
  </property>
</bean>	

<bean id="modelglue.scaffoldType.List" class="coldspring.beans.factory.config.MapFactoryBean">
  <property name="SourceMap">
    <map>
      <entry key="class"><value>PlantOMatic.model.scaffoldTemplates.List</value></entry>
      <event key="hasXMLGeneration"><value>true</value></event>
      <event key="hasViewGeneration"><value>true</value></event>
      <entry key="prefix"><value>List.</value></entry>
      <entry key="suffix"><value>.cfm</value></entry>
    </map>
  </property>
</bean>

Putting It All Together

Test your code by visiting http://localhost/PlantOMatic/?event=Plant.List

You should have a list of plants using the custom look and feel of our PlantOMatic application:

Training 08 Image 1
Plant List

In this walk-through we overrode default behavior of the Model-Glue framework simply by using ColdSpring. The reason why this worked is because Model-Glue uses ColdSpring internally to configure itself. Since beans in ColdSpring are referenced by name, and because application specific ColdSpring bean definitions load after the Model-Glue internal definitions, you can override pretty much any behavior of Model-Glue. If you want to find the names of overridable beans look in /ModelGlue/gesture/configuration/ModelGlueConfiguration.xml.


Back: Training Section 7: Crossing the Generational Gap

Attachments