amusingly enough i realized while attempting to implement it that the
formatting was different each time and decided to skip it this time.  Some
day i won't have to do four different views WITH DIFFERENT formatting
codes.  Sigh!

On Thu, Feb 26, 2009 at 3:09 PM, Doug Boude <[email protected]> wrote:

> Hi Miki.
>
> In thinking about doing what you're describing, here's how I believe I
> would do it:
>
> within the controller that retrieves the raw data set, I would instantiate
> a "formatter" object (some cfc with a method that accepts an incoming
> structure of field/value pairs and turns it into a formatted string). I
> would create a private helper function in my controller that grabs an entire
> given row from my raw query, then I would loop over my raw query, retrieving
> each row as I go and feeding it to the formatter object's method. Okay,
> enough words; here's the pseudocode to describe what I'm talking about:
>
> <cfset var stData = structnew() />
> <cfset var stFormatted = structnew() />
>
> <!--- get raw query... --->
> <cfset stData.raw = objDataObject.getDataQuery() />
>
> <!--- loop over raw query, transforming each row into a formatted string
> within a struct key in the stFormatted structure... --->
> <cfloop query="stData.raw">
>     <cfset stFormatted[recordID] =
> objFormatter.formatRow(argumentCollection=getQueryRow(current)) />
> </cfloop>
>
> <cfset stData.formatted = stFormatted />
>
> <cfset arguments.event.setValue("stData",stData) />
>
>
> Now, as proof of concept I created some code that runs locally using
> QuerySim to create some data. This code works, so maybe it'll help lend
> fodder to your creative fire:
>
> <cf_querysim>
>     UserInfo
>     userID,firstName,lastName,userGroups
>     100|Stan|Cox|33
>     200|Joe|Blow|35
>     300|Doug|Boude|21
>     400|Jim|Pickering|15
> </cf_querysim>
>
> <cfset stData = structnew() />
> <cfset stFormatted = structnew() />
> <cfset stData.raw = getDataQuery() />
> <cfloop query="stData.raw">
>     <cfset stFormatted[userID] =
> formatRow(argumentcollection=getRow(currentrow)) />
> </cfloop>
> <cfset stData.formatted = stFormatted />
> <!--- <cfset arguments.event.setValue("stData",stData) /> --->
>
> <cfscript>
> function getDataQuery(){
>     return UserInfo;
> }
> function getRow(rowid){
>     var retval = structnew();
>     var colList = listToArray(UserInfo.columnlist);
>     for (i=1;i lte arraylen(colList); i = i + 1){
>         retval[colList[i]] = UserInfo[colList[i]][rowid];
>     }
>     return retval;
> }
> </cfscript>
> <cffunction name="formatRow" access="public" returntype="any">
>     <cfset var retval = "" />
>     <cfset retval =
> "<b>#arguments.firstname#&nbsp;&nbsp;#arguments.lastname#&nbsp;&nbsp;#arguments.usergroups#</b>"
> />
>     <cfreturn retval />
> </cffunction>
>
> <cfdump var="#stData#">
>
>
> Hope this helps!
>
> Doug Boude  :0)
>
>
>
> On Thu, Feb 26, 2009 at 11:59 AM, Miki Tracey <[email protected]>wrote:
>
>> i've had my head buried in this code since my last post but now i'm
>> encountering something that i may be able to solve with a function in the
>> CFC
>>
>> basically i have four different layouts for one set of data.  Each layout
>> has one or more cfscript tags that convert the raw text into formatted
>> paragraphs of one type or other.  And this is FINE except for one thing.
>> Within four days i've gotten the cfscripts to end up so much differently
>> from each other that i'm not sure i can get them aligned.  It occurred to me
>> that if i just fed the data to an object that does the work for me i could
>> only have to keep one script for formatting and update only it.  (yay
>> reuse)  (yes, i am able to put that in a cfm and call it into the page if it
>> comes down to that, but i'd rather do it 'right-ish')
>>
>> But I am having trouble using UDFs in model glue (which is just fine by
>> me) however i'm at a complete loss how to use model glue to format the
>> text.  I considered doing it in the master controller, just instantiating
>> another object and doing it there, but that will only format one db record,
>> the rest will be unformatted, so it seems like the smart place to do it is
>> in the cfoutput in each page.
>>
>> Once upon a time i used Java and JSP and this made sense, but i've mostly
>> been a linear programmer for ten years, and so OO is giving me headaches.
>>
>> So i have two questions
>> - can i use objects in my code that are instantiated in the controller but
>> functions are not run on them?  if so, how do i do that
>> OR
>> - do i need to instantiate within the cfm page as per how one did it
>> before one put a framework around one's cold fusion?
>>
>> I am going to poke at it and hope i get it working tonite, but since i
>> have the delay anyway, i might as well ask for your advice since you guys
>> all rock and all.  And examples would really rock, however i didn't find
>> anything searching the example directory view cfms for function calls.
>> (though that could just be my relative lack of search fu)
>>
>> --
>> Miki Tracey
>> Administrator
>> Ice and Fire USA
>> [email protected]
>>
>>
>>
>
> >
>


-- 
Miki Tracey
Administrator
Ice and Fire USA
[email protected]

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "model-glue" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/model-glue?hl=en

For more about Model-Glue, check http://www.model-glue.com .
-~----------~----~----~----~------~----~------~--~---

Reply via email to