Changes between Initial Version and Version 1 of Training/Section02

Show
Ignore:
Timestamp:
12/29/09 19:55:31 (16 years ago)
Author:
cfgrok (IP: 64.30.223.5)
Comment:

Adding new training section

Legend:

Unmodified
Added
Removed
Modified
  • Training/Section02

    v1 v1  
     1[[TOC(heading=Training Section Contents, Training*)]] 
     2 
     3= Section 2 – Show Me Some Skinning = 
     4 
     5All great applications have a great look and feel. Part of the challenge of implementing a great look and feel is consistency. Model-Glue 3 makes it really easy to create and manage application layouts as well as apply those layouts to your events. In this module, we will take a static layout and create a structured layout for use in our application. 
     6 
     7== Exercise: Skinning == 
     8 
     9At this stage, point your browser at [http://localhost/PlantOMatic http://localhost/PlantOMatic]. 
     10 
     11Click on the This Template link and our template will display in your browser. This template can be portioned off into 6 sections: 
     12 
     13 * Navigation – Contains the logo and the navigation 
     14 * Primary Content – Contains the general content for the user 
     15 * Secondary Content – Contains any secondary content in a 2 column format 
     16 * Footer – Contains footer content 
     17 * Message Box – Contains messaging to notify the user of status or error conditions 
     18 * Master Page – Contains the general page layout structure and includes the above 4 elements. 
     19 
     20[[Image(training02-1.png, nolink)]][[BR]] 
     21'' The above diagram shows the content sections and the file in which each will reside '' 
     22 
     23=== Making the Modules === 
     24 
     25 * Open the file /template.html and review the contents. Each section has been marked out for you with HTML comments. For example, the following section of code indicates the boundaries for the specific content. 
     26 * Create a new file using the name indicated (views/layout/Layout.Navigation.cfm) and copy the content in between the comments into the newly created file. Do this for each section. 
     27 
     28'' Example of the boundaries for specific content '' 
     29 
     30{{{ 
     31 
     32<div id="menu"> 
     33  <!-- Create File: views/layout/Layout.Navigation.cfm --> 
     34  <ul> 
     35    <li><a href="/PlantOMatic" class="current">home</a></li> 
     36  </ul> 
     37  <!-- End Create File: views/layout/Layout.Navigation.cfm --> 
     38</div> 
     39 
     40}}} 
     41 
     42=== One Master to Rule Them All === 
     43 
     44Open /PlantOMatic/views/layout/Master.Layout.cfm and review the code. Master.Layout.cfm contains !ColdFusion and HTML source code and represents the high level structure of our application – it is primarily in charge of assembling our content modules. We get our content from the !ViewCollection and output it on the screen. The calls to the !ViewCollection are together at the top of the file: 
     45 
     46{{{ 
     47 
     48<cfsilent> 
     49  <cfset navigationcontent = viewcollection.getView( "navigation" ) /> 
     50  <cfset primarycontent = viewcollection.getView( "primary" ) /> 
     51  <cfset messagecontent = viewcollection.getView( "message" ) />  
     52  <cfset secondaryexists = viewcollection.exists( "secondary" ) /> 
     53  <cfset secondarycontent = viewcollection.getView( "secondary" ) /> 
     54  <cfset footercontent = viewcollection.getView( "footer" ) /> 
     55</cfsilent> 
     56 
     57}}} 
     58 
     59Each module is outputted in the correct place using standard !ColdFusion output notation like so:  
     60 
     61{{{ 
     62 
     63#primarycontent# 
     64 
     65}}} 
     66 
     67=== Putting it all Together === 
     68 
     69Our last task in skinning is to create a reusable mechanism to use our layout. Model-Glue 3 introduces the concept of an Event Type. Much like Types in Object Oriented Programming, an Event Type contains specific behavior and is addressable by a specific name. Event Types in Model-Glue can contain behavior that is executed BEFORE, AFTER or BEFORE and AFTER an Event is executed.  
     70 
     71Our template runs after Events are processed. Open /PlantOMatic/config/ModelGlue.xml and insert the following code in between the <event-types></event-types> tags. 
     72 
     73{{{ 
     74 
     75<event-type name="templatedPage"> 
     76  <after> 
     77    <views>  
     78      <include name="navigation" template="layout/Layout.Navigation.cfm"> 
     79        <value name="xe_ShipmentList" value="Shipment.List" /> 
     80      </include> 
     81      <include name="message" template="layout/Layout.MessageBox.cfm" /> 
     82      <include name="footer" template="layout/Layout.Footer.cfm" /> 
     83      <include name="main" template="layout/Master.Layout.cfm" /> 
     84    </views> 
     85  </after>               
     86</event-type> 
     87 
     88}}} 
     89 
     90Then add '''type="templatedPage"''' to each Event Handler, like so: 
     91 
     92{{{ 
     93 
     94<event-handler name="default" type="templatedPage"> 
     95  <views> 
     96    <include name="primary" template="primary.cfm" /> 
     97  </views> 
     98</event-handler> 
     99 
     100<event-handler name="page.error" type="templatedPage"> 
     101  <views> 
     102    <include name="primary" template="layout/Master.Exception.cfm" /> 
     103  </views> 
     104</event-handler> 
     105 
     106<event-handler name="page.missing" type="templatedPage"> 
     107  <views> 
     108    <include name="primary" template="layout/Master.MissingEvent.cfm" /> 
     109  </views> 
     110</event-handler> 
     111 
     112}}} 
     113 
     114=== A Flexible One Column Template === 
     115 
     116Now, when we run our application at [http://localhost/PlantOMatic/ http://localhost/PlantOMatic/] we see our template in action: 
     117 
     118[[Image(training02-2.png, nolink)]][[BR]] 
     119'' One Column Layout '' 
     120 
     121==== What about Two Columns? ==== 
     122 
     123To see the benefits of this flexible template, let's add a piece of secondary content. Open /PlantOMatic/config/ModelGlue.xml and update the default Event Handler to have an include for secondary: 
     124 
     125{{{ 
     126 
     127<event-handler name="default" type="templatedPage"> 
     128  <views> 
     129    <include name="primary" template="primary.cfm" /> 
     130    <include name="secondary" template="secondary.cfm" /> 
     131   </views> 
     132</event-handler> 
     133 
     134}}} 
     135 
     136Now when our Event Handler runs, Model-Glue will include the secondary content inside of the ViewCollection. Since we test for the existence of secondary in /PlantOMatic/views/layout/Master.Layout.cfm and adjust the HTML markup accordingly, the simple presence or the absence of secondary in the ViewCollection will turn our layout from a single column to a two column layout seamlessly. 
     137 
     138=== A Flexible Two Column Template === 
     139 
     140[[Image(training02-3.png, nolink)]][[BR]] 
     141'' Two Column Layout '' 
     142 
     143==== Housekeeping ==== 
     144 
     145We have a few items to take care of before we move on. 
     146 
     147 * Open /PlantOMatic/views/layout/Layout.Navigation.cfm and replace the content: 
     148 
     149{{{ 
     150 
     151<cfsilent> 
     152  <cfset event.copyToScope( variables, "xe_ShipmentList") /> 
     153  <cfset xe_ShipmentList = event.linkTo( xe_ShipmentList ) /> 
     154</cfsilent> 
     155 
     156<cfoutput> 
     157<ul> 
     158  <li><a href="#xe_ShipmentList#" class="current">home</a></li> 
     159</ul> 
     160</cfoutput> 
     161 
     162}}} 
     163 
     164 * Open /PlantOMatic/views/layout/Layout.MessageBox.cfm and replace the content: 
     165 
     166{{{ 
     167 
     168<cfsilent> 
     169  <cfset MSGQuery = event.getValue( "MessageContainer" ).getAllMessages() />  
     170</cfsilent> 
     171 
     172<!-- Begin User Message Box --> 
     173<cfif MSGQuery.RecordCount gt 0> 
     174  <div id="highlightnews"> 
     175    <ul> 
     176      <cfoutput query="MSGQuery"> 
     177        <li class="#MSGQuery.Type#Message">#MSGQuery.Message#</li> 
     178      </cfoutput>        
     179    </ul> 
     180  </div> 
     181</cfif> 
     182 
     183<!-- End User Message Box --> 
     184 
     185}}} 
     186 
     187=== Section 2 Summary === 
     188 
     189In this section, we learned how to skin a static template, work with the Model-Glue framework to create a flexible layout and configure our Event Handlers for templating. For more information, we suggest the following documentation: 
     190 
     191[http://docs.model-glue.com/wiki/ReferenceMaterials/ViewApi View API] 
     192 
     193[http://docs.model-glue.com/wiki/HowTos/HowToUseTypedEvents How to Use Typed Events] 
     194 
     195[http://docs.model-glue.com/wiki/ReferenceMaterials/ModelGlueXmlReference Model-Glue XML Reference] 
     196 
     197---- 
     198 
     199Back: [wiki:Training/Section01 Training Section 1: Installation] 
     200 
     201Next: [wiki:Training/Section03 Training Section 3: Dealing with Data]