tag:blogger.com,1999:blog-1670252685898016604.post3334512270912436154..comments2023-10-04T11:04:46.931-05:00Comments on Rae's Blog: Serving a Downloadable File with ColdFusion in Model GlueRaehttp://www.blogger.com/profile/05844223371538832222noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-1670252685898016604.post-9146150113177267872007-07-11T10:23:00.000-05:002007-07-11T10:23:00.000-05:00I’m no CFGRID expert, and I’m not familiar with th...I’m no CFGRID expert, and I’m not familiar with the exact format of your grid, so I’m going to refer you to the docs for figuring out how to get the data you want out of the CFGRID – there are lots of options for columns, rows, cells, etc. <BR/><BR/><A HREF="http://livedocs.adobe.com/coldfusion/7/htmldocs/00000266.htm " REL="nofollow">CF 7 LiveDocs - CFGRID</A><BR/><BR/>I would probably not use the built-in CFGRIDUPDATE, as I’m not sure how this would work within the Model Glue framework – CFGRIDUPDATE pretty much breaks every MVC rule out there! So that means that you’re going to want to treat the grid data like any other form data, and pass the file for the download with the FORM scope.<BR/><BR/>Here’s how you process a form within Model Glue:<BR/><BR/>Within the <views> block of your MG xml, in the include that is the main body of your page (where your form is), add a value for an “exit event”, where the value of your exit event is the event handler that will process your form:<BR/><BR/><include name="body" template="myView.cfm"><BR/><BR/> <value name="xe.submitGrid" value="submitGridAction" /><BR/><BR/> </include><BR/><BR/>Within the body of that include, place your CFFORM with your CFGRID, and for the “submit” action, use something like:<BR/><BR/><cfset submit = viewstate.getValue("myself") & viewstate.getValue("xe.submitGrid") /><BR/><BR/>This submit variable now holds the passed exit event value from the event object, and tells the form which event handler to submit to. Then in the action attribute of your CFFORM, insert the #submit# variable.<BR/><BR/>When the form is submitted your event handler broadcasts a message, which calls a function on your controller, and the controller is where you dynamically get the name of the file (from the FORM scope which, in Model Glue, is in the Event object) for your download. (I glossed over this assuming some knowledge of MG…)<BR/><BR/>To get the filename passed in the form from the Event object:<BR/><BR/><cfset myFile = arguments.event.getValue("filename")><BR/><BR/>(Where the filename parameter is the form field that contains the file name.)<BR/><BR/>Then you can create a new Download object (Download.cfc) from that file name, pass in the path and file type, and proceed with the rest of the tutorial as usual.<BR/><BR/>In other words, all we are doing is sending the file name dynamically from the view using the FORM scope, rather than hard coding the file name into the view.<BR/>HTH!Raehttps://www.blogger.com/profile/05844223371538832222noreply@blogger.comtag:blogger.com,1999:blog-1670252685898016604.post-74916630871061512512007-07-10T22:05:00.000-05:002007-07-10T22:05:00.000-05:00Ok how can we use this and make the file name to d...Ok how can we use this and make the file name to download dynamic. I have a cfgrid that has file names in it, so how can I get the name from a column in the cfgrid and use it for the file name and then get the expand path etc.<BR/><BR/><BR/>Thanks<BR/><BR/>JimAnonymousnoreply@blogger.com