Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

custome tag running twice...?

Status
Not open for further replies.

imstillatwork

IS-IT--Management
Joined
Sep 26, 2001
Messages
1,605
Location
US
I have a page (index.cfm)

on this page is a custom tag in the custom tag folder that includes a header and footer:

<cf_wrap>'index.cfm'</cf_wrap> (make sense?)

ok, now in my application.cfm i have included 2 files: locals.cfm, and globals.cfm

in locals.cfm I am including a tracking tag. tracking.cfm

so i guess it should be like this:

application.cfm
*includes globals.cfm and locals.cfm
locals.cfm includes tracking.cfm

index.cfm uses a custom tag with start and end for header and footer as first and last lines of page.

the tracking tag is being run twice somehow, but is not showin that it runs twice in the debug output.

for every page i visit, 2 rows are inserted into the tracking page. I set one field of tracking as a randrange, and it produces two different numbers, like the insert qyery is running twice.

I have NO IDEA whats going on...











 
ok, I set an application var in the application.cfm to count how many times application.cfm runs each page load, and its counting by twos? what gives?

Does application.cfm run for <cf_wrap> AND for </cf_wrap>??????

never had this issue before. if it is normal, hwhats the workaround?

THANKS!!!!

 
Take the includes out of the application.cfm and just put that code directly in your document. ColdFusion calls the application.cfm before every .cfm page, so it gets &quot;confused&quot; when you include another one within that page. You can still keep those pages out there for other pages with a local application.cfm (one contained in the app's directory, which overrides the global application.cfm in the web root) to use, but you need to place that code directly in the global application.cfm page.
 
that makes using local and global application settings includes totaly pointless. the reason this is local, is because it should not be running in every area of the web site. If i put it directly in the application.cfm, I still have other includes in applicaion.cfm and throughouteach page loaded. it only runs twice no matter how many included files there are, so i dont think application.cfm runs every time a cfm file is loaded, I can't get it to run more than 2 times.

When I combine all included files directly into application.cfm, it still is happening.

anything?

 
Application.cfm runs everytime a cfm file is pulled from a directory with an application file in the tree. If you have a file with an cfinclude in the same directory it will run application.cfm twice. Try it create a test.cfm with 2 or three includes in it and your monitoring database will in crease by three.
 
it only counted twice. I was incrementing an application variable ever time application.cfm ran.

there are between 6 and 10 .cfms to load a page.

everything I ever heard before was that application.cfm was once per http request. not per .cfm request.

 
Do you use <cflocation> anywhere in the application.cfm or any of the included files? i use the application.cfm file to do user login. if they are not logged in i send them to another page. That page then calles the application.cfm again. to keep the application.cfm from sending them to that page over and over and over again i had to make sure that the <cflocation> tag was only used once <cfif not isdefined(&quot;nonuser&quot;)>do the validation and possibly redirect</cfif>

The below was taken from:
Processing Application.cfm
When any ColdFusion application page is requested, ColdFusion searches up the page's directory tree for an Application.cfm file. When it is found, the Application.cfm code is logically included at the beginning of that page.

If it is not found, ColdFusion searches up the directory tree until it finds an Application.cfm file. If more than one Application.cfm file is in the current directory tree, ColdFusion uses the first one it finds.

Only one Application.cfm file is ever processed for each ColdFusion application page. The Application.cfm file is automatically included in each application page, as if by a cfincludetag. If the Application.cfm page it is present in the directory tree, there is no way not to include it. For this reason, it is the ideal location to set application-level variables.

If an application page has a cfinclude tag pointing to an additional application page, ColdFusion does not initiate another search for an Application.cfm page when it includes the additional page.


A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
- Quote by Douglas Adams
 
I've never has Application.cfm fire twice... and I have includes all over my pages.

As Macromedia says (in bombboys quote above), Application.cfm is designed so it will only fire once, regardless of custom tags or cfincludes that are in the page. So something else must be going on in your page imstillatwork.

Have you tried taking the page back down to it's bare essentials (like commenting out the includes for globals, locals, and tracking)? Then work your way back up to the correct state to narrow down just when the problem is introduced.

I assume that you know that
Code:
<cf_wrap>
is called twice in your example... and you have to use the
Code:
<CFSWITCH expression=&quot;#LCase(ThisTag.ExecutionMode)#&quot;>
  <CFCASE value=&quot;start&quot;>
     :
  </CFCASE>
  <CFCASE value=&quot;end&quot;>
     :
  </CFCASE>
</CFSWITCH>
syntax. But
Code:
<cf_wrap>
executing twice wouldn't explain why Application.cfm was running twice anyway... soo...


-Carl
 
yeah. that is all what i thought was correct. I am rebuilding my dev environment anyways. been darn near 2 years since a fresh installation of windows! We'll see how it goes from there. thanks!


 
this is the tag I am using...

<cfif thistag.executionmode is &quot;start&quot;>
<cfinclude template=&quot;/#Request.mappedPath#/inc_header.cfm&quot;>
</cfif>
<cfif thistag.executionmode is &quot;end&quot;>
<cfinclude template=&quot;/#Request.mappedPath#/inc_footer.cfm&quot;>
</cfif>

If I leave everythin the same, but comment out this tag, the application.cfm runs once. the database gets updated once, and the application.appcount var is only incremented once.

HOW SHOULD THIS BE FIXED? ?

Thanks!!


Kevin

 
BTW. This first started happening in CF5. I wiped out my entire PC, installed MX, and it still happens.

like i said above, it stops when I stop using the code I posted just above, which makes no sense to me. ? ? ? ?

 
I'm at a loss as to why it's happening... by all accounts, it shouldn't behave that way.

But, fixing it could be fairly simple.
Keep a
Code:
#Request.pageInited#
variable. And simply wrap your Application.cfm code in:
Code:
<CFIF NOT IsDefined(&quot;Request.pageInited&quot;) OR (IsBoolean(Request.pageInited) AND Request.pageInited NEQ true)>
     :
   do all your Application.cfm code here
     :
   <CFSET Request.pageInited = true>
</CFIF>

Should you need to do this? No. But it will solve your immediate problem. And the nice thing is that, if future versions of ColdFusion ever suddenly decide to behave correctly for you, nothing will break.


-Carl
 
Carl -

Would you have time to look over my code / and or environment and help me on this? I am stumped!

email kevsarg18 at yahoo dot com if you can!

thanks!


 
Remote analysis of an environment never works very well, IMHO. I could look over your code... but I doubt I'd really come back with much more than I already told you.

I ran a test here on my CF MX and CF 5.0 servers.
In a new directory, I created the following files:
Application.cfm-
Code:
<CFAPPLICATION name=&quot;myapplication&quot; clientmanagement=&quot;Yes&quot; sessionmanagement=&quot;Yes&quot;>
<p>Running application.cfm</p>

<CFINCLUDE template=&quot;include_file1.cfm&quot;>

mainpage.cfm-
Code:
<!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
    &quot;[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>[/URL]
<html xmlns=&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;>[/URL]
<head>
	<title>Main Page</title>
</head>

<body>

<CF_SOMETAG>
<h2>Hello world</h2>
</CF_SOMETAG>

</body>
</html>

include_file1.cfm-
Code:
<p>Including file 1</p>
<CFINCLUDE template=&quot;include_file2.cfm&quot;>

include_file2.cfm-
Code:
<p>Including file 2</p>

sometag.cfm-
Code:
<CFSWITCH expression=&quot;#LCase(ThisTag.ExecutionMode)#&quot;>
  <CFCASE value=&quot;start&quot;>
      <p>Starting tag</p>
  </CFCASE>
  <CFCASE value=&quot;end&quot;>
     <p>Ending tag</p>
  </CFCASE>
</CFSWITCH>

And the output (on both MX and 5.0) when I ran mainpage.cfm was how I would expect it to be...

Running application.cfm

Including file 1

Including file 2

Starting tag

Hello world

Ending tag


Try creating those pages in a new directory on your server and see if you don't get the same result. If you do, something else must be up in your code. If you get a result that indicates that Application.cfm is running twice, something is misbehaving in ColdFusion server itself. And a bounce or reinstall might be in order.



-Carl
 
TOTALY nucking futz.....


think I found it.

I have an img tag with src=&quot;&quot;

a changed it to src=&quot;asdas&quot; and application.cfm only runs once.

I cange it back to src=&quot;&quot; and application.cfm runs twice.

very consistant, thats got to be it, nothing else I tried made any changes, and this seems to be the problem, but why would it do that?










 
Bwahhhh... an IMG TAG?!?

That's an odd one.

I wonder...
Code:
<IMG>
tags are, in effect, separate requests to the web server. If you don't specify a src, perhaps it goes ahead and makes that new request, but for the current page (kind of like... if you leave the action attribute of a FORM blank, it assumes you want to post back to the current page). That would cause Application to be called for both requests, maybe.

Just out of curiousity... why in the world did you have an img tag with no src specified??



-Carl
 
...testing / dev... just a hieght/width placeholder. I will be using a dummy image or at least a broken src from now on though.

so yeah, application.cfm was only running once per request, but the page was being requested, then almost instantly requested again. so everything looks fine, but if you count page loads, it was wrong.

all is fine now.

I was able to recreate this every time on every web site i have.

thanks for the help!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top