<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Simeon Says &#187; Model-Glue</title>
	<atom:link href="http://blog.simb.net/tag/Model-Glue/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.simb.net</link>
	<description>Because I said so...</description>
	<lastBuildDate>Tue, 31 Aug 2010 17:23:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>MG Unity Scaffolded Forms &#8211; Adding a Checkbox</title>
		<link>http://blog.simb.net/2006/12/08/mg-unity-scaffolded-forms--adding-a-checkbox/</link>
		<comments>http://blog.simb.net/2006/12/08/mg-unity-scaffolded-forms--adding-a-checkbox/#comments</comments>
		<pubDate>Fri, 08 Dec 2006 00:00:00 +0000</pubDate>
		<dc:creator>Simeon</dc:creator>
				<category><![CDATA[CF]]></category>
		<category><![CDATA[Model-Glue]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Ok, I have been Model-Glue Unity heavy on the posts lately, but at least I am posting right? This tip has to do with modifying the way your data is presented. Essentially the problem arose like this. Client had and admin that I built using the scaffolding in Model-Glue Unity. I have modified most of [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, I have been Model-Glue Unity heavy on the posts lately, but at least I am posting right?</p>
<p>This tip has to do with modifying the way your data is presented.  Essentially the problem arose like this.  Client had and admin that I built using the scaffolding in Model-Glue Unity.  I have modified most of the displays and it has worked great for us.  But now we want to add to the admin another field. They want to mark wether a member has sent a check as method of payment.  All and all this is not very tough.  I go to my database and I add a field to it called checkSent its a tinyint(1).  So now I can just store null, 0 and 1 in the field.  Since most people have no values and i dont want to go change that, we will say that only the value 1 means they have sent a check.</p>
<p>If we tell MGU to rescaffold for us (?event=member.list&#38;scaffold=true ) then we can go look at the generated code and steal it.  Since we have already been modifying the display we already have a frmMember.cfm in the views folder of our application.  So now we have added the html to display the value from the database.  Only one problem&#8230; Its a text field. Now our users have to remember to put a 0 or a 1 in that field to make things work nicely.  I dont know about you but I dont trust users to be able to remember that.  What I really want here is a checkbox.  So I change the cfinput that we added to our form so it has a type=&#8221;checkbox&#8221; the value=&#8221;1&#8243; and the checked property is based on the value being a 1.</p>
<p>All better right?  Well now we can check the box and save our member.  If we go back and visit the form we will see that our box is checked and we are happy.  But what if we didnt mean to set it.  Maybe it was an accident?  Uncheck the box, submit, and then return to the edit form.  Its still checked. :(</p>
<p>See because we allow our field to be null in the database the form validation doesn&#8217;t require we pass a value.  And the field  being undefined (remember a checkbox thats not checked passes no value on submit) doesn&#8217;t get set into our database.</p>
<p>So how do we fix this?  Well one way is to go the same route we did with our list event.  That is to over-ride how Model-Glue processes the data.  But that sounds like a lot of work and I am not into it.  So my solution was a little trick with the html.  Think about what happens when you submit a form that has multiple inputs with the same name.  Most common example of this is with checkboxes.  The results are passed as a comma separated list.  But what if one of the possible values of the list is &#8220;&#8221;?  Well then its not really worth passing is it?  So what I did to solve my issue was add a hidden input on the form with the same name as my checkbox.  Now if the check box is marked when the form get submitted we the value of 1.  But if the checkbox is not checked when the form is submitted the hidden input takes over and the value is &#8220;&#8221;.  And that is a value it gets stored into our database as null.  And because we decided above that only the value of 1 means that a check was sent, we are in business.</p>
<p>Of course this is in some ways a hack.  But the truth of it is that if fits our needs and the effort required matches the payoff we get in the site.  So take that little tip with you on your next Scaffolding form adventure.</p>
<p>PS. If you want to test this little hack of mine, through this code in a test.cfm and give it a whirl.<br />
<code><br />
<cfif isDefined("form.mything")><br />
<cfdump var="#form.mything#" /><br />
</cfif></p>
<form action="" method="post">
<input type="hidden" name="mything" value="" />
<input type="checkbox" name="mything" value="" />
<input type="submit" value="submit" />
</form>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simb.net/2006/12/08/mg-unity-scaffolded-forms--adding-a-checkbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using GatewayMethod to extend Model-Glue Unity Scaffolds</title>
		<link>http://blog.simb.net/2006/12/07/using-gatewaymethod-to-extend-modelglue-unity-scaffolds/</link>
		<comments>http://blog.simb.net/2006/12/07/using-gatewaymethod-to-extend-modelglue-unity-scaffolds/#comments</comments>
		<pubDate>Thu, 07 Dec 2006 07:49:00 +0000</pubDate>
		<dc:creator>Simeon</dc:creator>
				<category><![CDATA[CF]]></category>
		<category><![CDATA[Model-Glue]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Ok, its a Model-Glue day for me. In my last post I talked about starting to work from the code that is generated for us by the Scaffolds in Model-Glue Unity. In that post I talked about adding a function to your controller to change the query that is used for a scaffolded event. This [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, its a Model-Glue day for me.  In <a href="http://www.simb.net/client/index.cfm?mode=entry&amp;entry=5F22D46A-C5F2-7961-E044C5FD3C39862C">my last post</a> I talked about starting to work from the code that is generated for us by the Scaffolds in Model-Glue Unity.</p>
<p>In that post I talked about adding a function to your controller to change the query that is used for a scaffolded event.  This is just one way to go about this however.  I think for most model-glue &#8216;ers this will be the most familiar way of adding functionality.  However now that we are working with Reactor inside MGU it may not be the best way.  Reactor is an ORM framework for cf.  It is a kind of highbred between the Active Record and DAO design patterns.  What that means to us however is that it creates a Gateway object for each of the tables in our database.  This gateway object is then responsible for retrieving sets of data (queries) from our database for us.  So in my last example the query I wrote would really have belonged in my MemberGateway object.  Again this is not really a tutorial on how Reactor works either (what good am I too you anyway :] ) so I direct you to look more into Reactor if you are interested.</p>
<p>But what I do want to show you is how your Model-Glue.xml file will change using this method.  As it stands our event-handler broadcasts the the &#8220;member.getAlMembers&#8221; message and then displays our list of members. It looks something like this.</p>
<p><code><br />
<broadcasts><br />
<message name="member.getAllMembers" /><br />
</broadcasts><br />
</code></p>
<p>What we want to do is bring back our &#8220;ModelGlue.genericList&#8221; message that our scaffold generated.  With that back we can add on the &#8220;gatewayMethod&#8221; argument and specify the function we created on our gateway.  Now our broadcast configuration will look like this:</p>
<p><code><br />
<broadcasts><br />
<message name="ModelGlue.genericList"><br />
<argument name="criteria" value="" /><br />
<argument name="object" value="member" /><br />
<argument name="queryname" value="memberQuery" /><br />
<argument name="gatewayMethod" value="getAllMembers" /><br />
</message><br />
</broadcasts><br />
</code></p>
<p>And the only thing that is really different between what we had in the last post is that last line about gatewayMethod.  Now Model-Glue will use our method on our gateway to get the data from the members table.  And we can use that same function from elsewhere in our application if we require.</p>
<p>Seems like a long way to go, and we ended up so close to where we started.  But hey sometimes it takes a bit of work to learn something.  Now go forth and build on the code that has been generated for us.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simb.net/2006/12/07/using-gatewaymethod-to-extend-modelglue-unity-scaffolds/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Adding on to Model-Glue Unity Scaffolds</title>
		<link>http://blog.simb.net/2006/12/07/adding-on-to-modelglue-unity-scaffolds/</link>
		<comments>http://blog.simb.net/2006/12/07/adding-on-to-modelglue-unity-scaffolds/#comments</comments>
		<pubDate>Thu, 07 Dec 2006 07:12:00 +0000</pubDate>
		<dc:creator>Simeon</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[CF]]></category>
		<category><![CDATA[Model-Glue]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[In my last post I talked a little about getting started with scaffolds in Model-Glue Unity. Anyone you talk to will agree that scaffolds are a great way to see something come together fast, and can be a good tool for developers. Not many will say that they are all you need to build sites, [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.simb.net/client/index.cfm/2006/12/7/Using-ModelGlue-Unity-Scaffolds">my last</a> post I talked a little about getting started with scaffolds in Model-Glue Unity.  Anyone you talk to will agree that scaffolds are a great way to see something come together fast, and can be a good tool for developers.  Not many will say that they are all you need to build sites, and some will even say they just get in the way.</p>
<p>Well I happen to believe they are a great place to start.  So much so that when I had to build a free site for someone recently I used MGU in the admin, even though the front end of the site was done with fusebox.  This arrangement worked out great for a while, but now they need a little bit more information to be displayed.  MGU makes it very easy to take what it builds and customize that.  For starters I wanted to modify what gets displayed on the member.list page of my admin.  Well MGU generates the templates for me inside the /site/views/generated folder.  For the purposes of displaying the list of members the file is named dspMemberList.cfm.  If you just take that generated file and drag it, up out of the generated folder, into the views folder MGU will use this file instead of the generated one.  So by default the scaffolds in MGU display every field in your table across the page, and we dont need all that information.  The first task is to only display the data that we need.  Remember this is just a summary page.  After saving your new file with you modifications you can run your page again to see how you have updated the layout.  You can also do this with the frmMember.cfm and dspMember.cfm  files if you would like to modify the layout of them.</p>
<p>That is all well and good for getting started on making modifications.  But lets look at something a little bit harder. And I will note here that I am using MGU from the svn respository ( its possible this stuff may not work with whatever release is out in beta). On my member list page I want to display some aggregate data.  Maybe its a sum of the number of times a user has logged in.  But really the point is just that our generic query that the scaffolds wrote for us isnt going to cut it anymore.  What I really need is to write my own query and use that to populate my display.  This task is almost as simple as creating the scaffold in the first place.  First thing we want to do is get the generated event handler xml code from the scaffolds.xml file.  This will be located at /site/config/scaffolds/Scaffolds.xml  assuming site is the name of your MGU app and you haven&#8217;t changed the location of the scaffolds info in your MGU configuration.  Glancing at that file you will find a section that looks much like this.</p>
<pre class="code" lang="xml" >
<code>
<event -handler name="member.list" access="public">
<broadcasts>
<message name="ModelGlue.genericList">
<argument name="criteria" value="" />
<argument name="object" value="member" />
<argument name="queryName" value="memberQuery" />
</message>
</broadcasts>
<views>
<view name="body" template="dspmemberList.cfm" append="true">
<value name="xe.view" value="member.view" overwrite="true" />
<value name="xe.delete" value="member.delete" overwrite="true" />
<value name="xe.edit" value="member.edit" overwrite="true" />
</view>
</views>
<results>
	<result name="" do="view.template" redirect="false" append="" preserveState="true" />
</results>
</event></code>
</pre>
<p>We want to copy that code and paste it into your ModelGlue.xml file, inside the <event -handlers> section.  Just having this code here is not enough though.  We also need to tell MGU not to scaffold the view piece for us.  So we need to modify our scaffold tag for member to specify that information.</p>
<p><code><br />
<scaffold object="member" type="view,edit,commit,delete"><br />
			<results><br />
				<result do="view.template" /><br />
			</results><br />
		</scaffold><br />
</code></p>
<p>Now our scaffold knows not to generate the member.list event.  If we run our application again and append the &#38;scaffold=true attribute.  We should see our application run, just like we left it.  Only difference is behind the scenes its using our new xml config in the Model-Glue.xml file.  </p>
<p>So lets push ahead.  This is not really a tutorial on using MG, I am really just working on extending the scaffolding features.  So when I say &#8220;I next created a new message-listener and called a method on my controller which got my new query&#8221; I am not really going to get very deep into how that works.  I believe this to be a standard Model-Glue item and if you have done any you will know how.  And if not then check the documentation because <a href="http://www.firemoss.com">Joe</a> does a great job with that.  In fact you can take a look at Quickstart 4 in the Model-Glue Unity Documentation to see the steps involved.</p>
<p>So I created a new message-listener called &#8220;member.getAllMembers&#8221; on my controller and asked it to call the &#8220;getAllMember&#8221; function on my controller.  That function does some stuff to get a query that is joined with a couple tables and does some calculation.  Then it puts that query into the event using setValue.  Now i need to modify the event-handler for member.list to call this new bit of code and use it for display.  This is as simple as changing:</p>
<p><code><br />
<broadcasts><br />
<message name="ModelGlue.genericList"><br />
<argument name="criteria" value="" /><br />
<argument name="object" value="member" /><br />
<argument name="queryName" value="memberQuery" /><br />
</message><br />
</broadcasts></code></p>
<p>To this new code</p>
<p><code><br />
<braodcasts><br />
<message name="member.getAllMembers" /></p>
<p></braodcasts></code></p>
<p>Now when we run our ?event=member.list page in our MGU site, our new query is used to get the data.  And using the same file we modified above we can display the new data from the query on our list.</p>
<p>Pretty neat.  What we looked at here was modifying the code generated by the Scaffolds in our Model-Glue unity application.  We created new templates to use for display as well as changed how the code runs.  We now have a site that is customized for us, but we still had to write very little actual code to get it done.  So go get some coffee and play some Gears of War.  You earned it.</event></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simb.net/2006/12/07/adding-on-to-modelglue-unity-scaffolds/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Model-Glue Unity Scaffolds</title>
		<link>http://blog.simb.net/2006/12/07/using-modelglue-unity-scaffolds/</link>
		<comments>http://blog.simb.net/2006/12/07/using-modelglue-unity-scaffolds/#comments</comments>
		<pubDate>Thu, 07 Dec 2006 04:00:00 +0000</pubDate>
		<dc:creator>Simeon</dc:creator>
				<category><![CDATA[CF]]></category>
		<category><![CDATA[Model-Glue]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I have been a fuseboxer for about as long as I have done cf. But the scaffolding features of MG-U looked really appealing. But learning new frameworks can be a daunting task, especially when work comes with deadlines. I already use ColdSpring and Reactor in my fusebox projects, so the only thing I really needed [...]]]></description>
			<content:encoded><![CDATA[<p>I have been a fuseboxer for about as long as I have done cf.  But the scaffolding features of MG-U looked really appealing.  But learning new frameworks can be a daunting task, especially when work comes with deadlines.</p>
<p>I already use ColdSpring and Reactor in my fusebox projects, so the only thing I really needed to grasp was the Model-Glue pieces.  This is all very well laid out and it took no time at all to have some basic pages running queries and displaying data.  So on to the scaffolds.  Adding the CRUD functionality based on a table in my database was stupid simple.  In the event-handler section of the model-glue config file you just add a scaffold tag and specify what table you want it to work on.  Something like this:</p>
<p><code><br />
<scaffold object="member" /><br />
</code></p>
<p>But I had already setup some layout code for the site so I wanted to use that with the scaffolds.  So I amended the code like so:</p>
<p><code><br />
<scaffold object="member"><br />
   <results><br />
      <result do="view.template" /><br />
   </results><br />
</scaffold><br />
</code></p>
<p>And with that I could visit my site and use the following url to see the list of data from the members table in the database:</p>
<p>http://my-site.com/admin/index.cfm?event=member.list</p>
<p>This also added member.view, member.edit, member.delete and member.commit as events that can be run in my application.</p>
<p>In just a couple lines of code I added a whole bundle of functionality to my site.  Enough so actually that I could get the thing out the door and let the client have some time to decide what they would like added.</p>
<p>What came next is was adding functionality to the scaffolded code. But thats a post for next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simb.net/2006/12/07/using-modelglue-unity-scaffolds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
