Coldbox – Persisting Data Across Requests

My mind couldn’t quite comprehend how the request collection maintains its data, and how it gets data from one page to the next. Luis to the rescue!

In my last Coldbox entry, I wanted to simply pass that fname variable over to the dspThisIsWill view. I tried with my routing but it didn’t quite work like I expected (OK, it handgrenaded!).

Luis explained how to get that data from the interceptor, into the dspThisIsWill view.

myInterceptor.cfc
<cfscript>
var rc = event.getCollection();
var result = rc.emp_fname;
event.setValue(‘fname’, result);
if(arguments.interceptData.fname EQ “Will”){
setNextRoute(“Employee/dspThisIsWill”, “fname”);
}
</cfscript>

rc retrieves our requestCollection.
result simply sets the first name only
We set the first name value in the request collection.
And finally, we send the fname value onto the next view (setNextRoute().

On the dspThisIsWill view, I can then grab that value out of the request collection and display it.

<cfscript>
rc = event.getCollection();
</cfscript>

<cfoutput>

<p>Wow! This is really <strong>#uCase(rc.fname)#</strong>??</p>

</cfoutput>

Give it another whirl!

Luis said you can also do this:

setNextRoute(“Employee/dspThisIsWill”, “fname,lname,mname”);

And, he has plans for a more-direct persistence in future versions.

If anyone has a better technique, I’d be interested in hearing about it.

No comments yet

Leave a reply