House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

setting page variables in onRequestStart

  << Previous Post |  RSS |  Tree View |  Sort Oldest First |  Subscribe to this Group Next >> 

setting page variables in onRequestStart

----- Excess quoted text cut - see Original Post for more ----- Dominic Watson 05/23/2008 09:02 PM
> Err, how is it a 'pseudo-scope"? The request scope is a real scope Dominic Watson 05/23/2008 08:50 PM
My only problem with Request scope is that its available _everywhere_. I Adam Haskell 05/23/2008 07:14 PM
----- Excess quoted text cut - see Original Post for more ----- Dave Watts 05/23/2008 05:57 PM
----- Excess quoted text cut - see Original Post for more ----- Dave Watts 05/23/2008 05:50 PM
Of course, but that was just an example. Dawson, Michael 05/23/2008 02:53 PM
> In other words, do you use the variables scope at all on the "view" Dave Watts 05/23/2008 02:40 PM
Just so I'm clear on this... Dawson, Michael 05/23/2008 02:27 PM
During our site rewrite, we opted to use the request scope over the variables Adrian Moreno 05/23/2008 11:25 AM
Err, how is it a 'pseudo-scope"? The request scope is a real scope Raymond Camden 05/23/2008 11:08 AM
> variables.viewState? Dominic Watson 05/22/2008 09:59 PM
variables.viewState? Brian Kotek 05/22/2008 09:34 PM
> I'd argue that variables he is setting on - every- page request should Dominic Watson 05/22/2008 09:22 PM
I'd argue that variables he is setting on - every- page request should Raymond Camden 05/22/2008 06:23 PM
> Why not simply simply use the Request scope? Dominic Watson 05/22/2008 06:17 PM
thanks Raymond Richard White 05/22/2008 04:31 PM
Right, you can't do that. The variables scope in App.cfc isn't copied Raymond Camden 05/22/2008 04:19 PM
hi Richard White 05/22/2008 04:13 PM

05/23/2008 09:02 PM
Author: Dominic Watson Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305992 ----- Excess quoted text cut - see Original Post for more ----- I agree with you for most app building. However, I was recently tasked with building a pretty much flat site but where ColdFusion templating would be really useful. For this simple app, I just setup onRequestEnd.cfm to be the HTML template that outputted #request.header# for various page specific header tags (javascript, etc) and #request.body# for the main content.  Each individual page would then just savecontent to request.body and possibly request.header to be outputted later in onRequestEnd.cfm. The request scope was the logical place for these variables. (I'm sure that onRequestEnd tactic must have been / is a common tactic - not claiming originality!) Dominic -- Blog it up: http://fusion.dominicwatson.co.uk
05/23/2008 08:50 PM
Author: Dominic Watson Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305991 > Err, how is it a 'pseudo-scope"? The request scope is a real scope > (don't give it any confidence issues!) just as much as Variables. And > I'll repeat my earlier assertion - that maybe seeing Request.Foo will > help it stand out compared to Variables.goo. ;) You mis-read me (and I express badly). For example, MG3 has introduced the 'helpers' 'pseudo-scope'. With this, you put all your UDFs in a folder called helpers and the app automagically places them all in a variable called helpers. So then, in your cfms, or even your cfcs (yuck), you could do: <cfset result = helpers.stringUdfs.myStringFunction('foo')> So here, 'helpers' is sort of a 'pseudo-scope'. Sure, it's just a structure in the variables scope that has collections of udfs as its keys, but I think the 'pseudo-scope' is a good term for it. This is what I was trying to recreate for Richard - but I failed to calculate the inability to set anything in the variables scope in application.cfc (the 'global' variables scope outside of the cfc that is). The request scope is absolutely fine. However, in this case, we were putting the collection of udfs in the application scope and then wanting to create a 'pseudo-scope' for them to avoid verbosity. If that isn't possible, then the best place for them is just to stay in the application scope (logically where they belong): <cfset result = application.helpers.myStringFunction('foo')> But yeh, I completely agree that variables should sit in the scopes where they belong - but I also like the idea of creating 'pseudo-scopes' if it readable to do so ;) Dominic -- Blog it up: http://fusion.dominicwatson.co.uk
05/23/2008 07:14 PM
Author: Adam Haskell Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305989 My only problem with Request scope is that its available _everywhere_. I understand you can be a good developer and not use it in your model or elsewhere but I still dislike the request scope for that reason. Being a person that is constantly working on framework and components to be used in my company I cherish encapsulation and request scope spits in the face of that. Sure Application and Session do too but they server a good purpose for carrying state so I like them :)  I do like your point about global variables for the life of the request and being easy to differentiate between those and page variables. I am with Dave though maybe Application or Session would be a better place for that info? Just my 2 cents. Also check out what Sean did with Application.cfc in fusebox very clever to get around most of the limitations/issues with onRequest. Adam Haskell On Thu, May 22, 2008 at 4:17 PM, Raymond Camden <rcamden@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more -----
05/23/2008 05:57 PM
Author: Dave Watts Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305984 ----- Excess quoted text cut - see Original Post for more ----- I read that article, and while I'm glad this turned out well for you, there seems to be a serious misunderstanding in the article about how Java garbage collection works in CF. The garbage collection doesn't run after every request, by default - and you wouldn't want it to, either. Garbage collection is an expensive operation. And just destroying the unwanted references in onRequestEnd.cfm or the onRequestEnd method in Application.cfc isn't going to change that - it just means that those variables will be immediately eligible for garbage collection whenever it runs, as long as those variables have no other references in the stack. This isn't a memory leak. Java will eventually reclaim and reallocate that memory. That said, I'm not sure what's different about using Request variables in this way, since they're just references like any other reference, and the values stored in the heap should be destroyed by the garbage collector the same way. Finally, if you're creating truly global site variables, why not just use the Application scope? That's what it's for, after all. You don't have to worry about the silly locking issues like you did with CF 5 and earlier. Of course, if things are working as they are, it's probably not worth changing now. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information!
05/23/2008 05:50 PM
Author: Dave Watts Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305983 ----- Excess quoted text cut - see Original Post for more ----- Yeah, that was really for the benefit of others, not for you personally. That said, I've seen a lot of people use only Request variables in their pages for this sort of thing. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Software provides the highest caliber vendor-authorized instruction at our training centers in Washington DC, Atlanta, Chicago, Baltimore, Northern Virginia, or on-site at your location. Visit http://training.figleaf.com/ for more information!
05/23/2008 02:53 PM
Author: Dawson, Michael Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305960 Of course, but that was just an example. m!ke > In other words, do you use the variables scope at all on the "view" > pages? > > Would you have used: > > <cfquery name="request.myQuery" ...> ? If it's really a view page, in an MVC pattern, you wouldn't have any CFQUERY tags in it. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/
05/23/2008 02:40 PM
Author: Dave Watts Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305959 > In other words, do you use the variables scope at all on the "view" > pages? > > Would you have used: > > <cfquery name="request.myQuery" ...> ? If it's really a view page, in an MVC pattern, you wouldn't have any CFQUERY tags in it. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Training: Adobe/Google/Paperthin Certified Partners http://training.figleaf.com/ WebManiacs 2008: the ultimate conference for CF/Flex/AIR developers! http://www.webmaniacsconference.com/
05/23/2008 02:27 PM
Author: Dawson, Michael Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305958 Just so I'm clear on this... You are using the request scope for EVERY variable you set or ONLY the global variables? In other words, do you use the variables scope at all on the "view" pages? Would you have used: <cfquery name="request.myQuery" ...> ? m!ke During our site rewrite, we opted to use the request scope over the variables scope for all "view" (CFM) pages. We use onRequestStart() to make sure certain global site variables are available in the request scope.
05/23/2008 11:25 AM
Author: Adrian Moreno Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305954 During our site rewrite, we opted to use the request scope over the variables scope for all "view" (CFM) pages. We use onRequestStart() to make sure certain global site variables are available in the request scope. After reading this article: http://www.schierberl.com/cfblog/index.cfm/2006/10/16/memoryLeak_variablesScope it turns out using the request scope everywhere was a great boon to the project. One of our legacy applications uses Application.cfm, relies on the variables scope and has major memory issues. If you look down in his Summary, #4 says "Calling structClear(variables) in onRequestEnd.cfm will destroy unwanted references tied to variables scope". We added this code to one server in the middle of the day and watched the memory on that server drop like a rock as soon as it deployed. We promoted it to the rest of the servers and they've all been behaving much better ever since. -- Adrian ----- Excess quoted text cut - see Original Post for more -----
05/23/2008 11:08 AM
Author: Raymond Camden Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305953 Err, how is it a 'pseudo-scope"? The request scope is a real scope (don't give it any confidence issues!) just as much as Variables. And I'll repeat my earlier assertion - that maybe seeing Request.Foo will help it stand out compared to Variables.goo. On Thu, May 22, 2008 at 8:21 PM, Dominic Watson <watson.dominic@googlemail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- -- =========================================================================== Raymond Camden, VP of Software Dev, Broadchoice Email : ray@camdenfamily.com Blog : www.coldfusionjedi.com AOL IM : cfjedimaster Keep up to date with the community: http://www.coldfusionbloggers.org
05/22/2008 09:59 PM
Author: Dominic Watson Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305938 > variables.viewState? Ok Mr Pedant, pick up on the useless bit of the post damn you :p -- Blog it up: http://fusion.dominicwatson.co.uk
05/22/2008 09:34 PM
Author: Brian Kotek Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305936 variables.viewState? On Thu, May 22, 2008 at 9:21 PM, Dominic Watson < watson.dominic@googlemail.com> wrote: ----- Excess quoted text cut - see Original Post for more -----
05/22/2008 09:22 PM
Author: Dominic Watson Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305935 > I'd argue that variables he is setting on - every- page request should > be segregated for normal page variables. If I see request.siteURL for > example, it flags it as a variable that is always available, as > opposed to just 'X' for example. Sure, I'd be with you usually; but this is an entire 'pseudo scope'. Would you argue for MG to use request.viewstate over just viewstate? That wouldn't be so bad actually thinking about it; always bugged me a little referencing viewstate without a scope lol Dominic -- Blog it up: http://fusion.dominicwatson.co.uk
05/22/2008 06:23 PM
Author: Raymond Camden Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305930 I'd argue that variables he is setting on - every- page request should be segregated for normal page variables. If I see request.siteURL for example, it flags it as a variable that is always available, as opposed to just 'X' for example. On Thu, May 22, 2008 at 5:15 PM, Dominic Watson <watson.dominic@googlemail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- -- =========================================================================== Raymond Camden, VP of Software Dev, Broadchoice Email : ray@camdenfamily.com Blog : www.coldfusionjedi.com AOL IM : cfjedimaster Keep up to date with the community: http://www.coldfusionbloggers.org
05/22/2008 06:17 PM
Author: Dominic Watson Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305928 > Why not simply simply use the Request scope? Verbosity. The idea he is working on is doing something similar to the way MG3 creates the 'helper scope' for udfs. I think helpers.myUdf() is preferable to request.helpers.myUdf() though its all good. Clearly with MG, the helper/event/viewstate variables are setup outside of any cfcs and I hadn't figured that in the sample code I came up with (I still use application.cfm). Dominic -- Blog it up: http://fusion.dominicwatson.co.uk
05/22/2008 04:31 PM
Author: Richard White Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305924 thanks Raymond i haven't yet looked into the request scope but will do now! thanks again ----- Excess quoted text cut - see Original Post for more -----
05/22/2008 04:19 PM
Author: Raymond Camden Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305923 Right, you can't do that. The variables scope in App.cfc isn't copied to the template. Unless you use onRequest. But that has some drawbacks as well. Why not simply simply use the Request scope? On Thu, May 22, 2008 at 3:10 PM, Richard White <richard@j7is.co.uk> wrote: ----- Excess quoted text cut - see Original Post for more -----
05/22/2008 04:13 PM
Author: Richard White Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:56505#305922 hi is it possible to set page variables in the onRequestStart method of the application.cfc? if i enter the following code in the application.cfc: <cfset variables.myVariable = "myVariable"> and the following code in my page: <cfoutput>#myVariable#</cfoutput> i get an error message when running a page saying myVariable is not defined
<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

May 24, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference