| Version 3 (modified by DanWilson, 14 years ago) |
|---|
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.
- Create a new directory in /PlantOMatic/model called scaffoldTemplates
- 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
- Open each file and change the name attribute in the view tag:
<view name="body" template...
To:
<view name="primary" template...
- Open /PlantOMatic/config/ModelGlue.xml and add the following tag after the closing </event-types> tag:
<scaffold object="Plant" event-type="templatedPage" />
- Next, open /PlantOMatic/config/ColdSpring.xml and change:
<property name="rescaffold"><value>false</value></property>
To:
<property name="rescaffold"><value>true</value></property>
- 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:

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.
Bonus Points
For bonus points, you can take the additional step of creating a new Scaffolding template in Model Glue. This is really simple to do and we'll leave it for your homework. If you get stuck, simply post to the Model Glue Mailing List and we'll sort you out.
For this exercise, you will need to:
- Make a copy of the List.cfc located at PlantOMatic.model.scaffoldTemplates.List. Name the copy Grid.cfc.
- Open the new Grid.cfc and go to the loadViewTemplate() method. Add the word GRID after the Breadcrumbs just so you can verify the new Grid is working.
<div id="breadcrumb"><a href="##listEvent##">%spaceCap( Metadata.alias )%</a> GRID</div>
- Then wire up the new Grid.cfc in your /PlantOMatic/config/ColdSpring.xml. This will include configuring the Grid with a bean called: PlantOMatic.scaffoldTemplate.Grid as well as using some ColdSpring? functionality to load the new bean into the modelGlue.scaffoldManager
<!-- Load the new Grid Scaffold Template into the Model Glue framework --> <bean id="ScaffoldTemplate.Grid" factory-bean="modelglue.scaffoldManager" factory-method="addScaffoldTemplate" lazy-init="false"> <constructor-arg name="scaffoldBeanRegistry"> <list> <ref bean="PlantOMatic.scaffoldTemplate.Grid" /> </list> </constructor-arg> </bean> <!-- Configure the new Grid.cfc --> <bean id="PlantOMatic.scaffoldTemplate.Grid" class="coldspring.beans.factory.config.MapFactoryBean"> <property name="SourceMap"> <map> <entry key="class"><value>PlantOMatic.model.Grid</value></entry> <event key="hasXMLGeneration"><value>true</value></event> <event key="hasViewGeneration"><value>true</value></event> <entry key="prefix"><value>Grid.</value></entry> <entry key="suffix"><value>.cfm</value></entry> </map> </property> </bean>
- Lastly, add a second scaffold tag for Plant to your /PlantOMatic/config/ModelGlue.xml with the type of Grid so we can get the new Grid to generate:
<scaffold object="Plant" type="Grid" event-type="templatedPage" />
Test your code by visiting http://localhost/PlantOMatic/?event=Plant.Grid. Notice the GRID string in the breadcrumbs. You can make many uses of this, from implementing a JQuery Datatables Grid, Generating Pie Charts, Bar Charts, and any number of interesting patterns applied to your table objects. If you do something interesting with this feature, or just have a general comment, please let us know on the Model Glue Mailing List.
Attachments
-
training08-1.png
(94.4 kB) - added by cfgrok
16 years ago.
Training 08 Image 1
![(please configure the [header_logo] section in trac.ini)](/ModelGlue.com/trac.cgi/chrome/site/your_project_logo.png)