Link to home
Start Free TrialLog in
Avatar of lantervj
lantervjFlag for United States of America

asked on

cfdiv scopes

What scopes are avaiable inside a cfdiv?  I can dump attributes and url and see that my data is there but I get an error that XXXX is undefined in attributes.  I understand I can't change some scope values from inside a cfdiv, but I thought I could read that data.
Avatar of gdemaria
gdemaria
Flag of United States of America image


Any scope is "available" in a cfdiv, the question is how are you passing values to the CFDIV.

If you are using ColdFusion.navigate() and passing in a URL, then you need to receive those variables via URL scoped variables.  

If you use <cfinclude> between your cfdiv tags, then any scoped variable CAN pass through, although you SHOULD only allows the scoped intended to be global...  

Best practise would be pass in only what you need.

Perhaps show some code..
>  I understand I can't change some scope values from inside a cfdiv, but I thought I could read that data

Not sure that is true.  You can't change values in cgi variables and you need a function to change query variables,  but you should be able to change any variable scoped values.   Need to see your code.

Avatar of lantervj

ASKER

One problem is the variable board_type that initially come from the initiating page in the url.  It determines which board type is seleted in the cfselect named change_board_type.  There is a second cfdiv that is bound to that element and I was trying to effect a submit of some sort that would reload the entire page with a new value for url.board_type.  The larger issue is in the cfdiv dsppagediv.cfm.  I can do a dump or the url and attributes scopes and see the variable xboard but I get an error (not defined) when using attributes.xboard_type in the div.


xboard_type  is using the variables scope, not attributes scope here.... I don't see variables.xboard_type defined anywhere in that file, and no cfparam for it either.  So it seems to be undefined...

<cfinvoke component="cfc.basic" method="getPages" returnvariable="qPages">
  <cfinvokeargument name="board_type" value="#variables.xboard_type#">
                                                                                 ^^^^^^

Why would I cfparam it if it's in the variable scope?
Nevermind.  I caught myself just as I hit the submit button.
I changed the div code;
<cfinvoke component="cfc.basic" method="getPages" returnvariable="qPages">
      <cfinvokeargument name="board_type" value="#change_board_type#">
      <cfinvokeargument name="selectJobID" value="#url.selectJobID#">

The variable change_board_type is the name of a cfselect in the included dspsearchparams.cfm.

I get the error;

 Variable CHANGE_BOARD_TYPE is undefined.
 
The error occurred in D:\inetpub\wwwroot\TaxTalent.net\Development\control\jobads\dspPagesDiv.cfm: line 43

41 : <!--- <cfdump var="#url#"><cfabort> --->
42 : <cfinvoke component="cfc.basic" method="getPages" returnvariable="qPages">
43 :       <cfinvokeargument name="board_type" value="#change_board_type#">
44 :       <cfinvokeargument name="selectJobID" value="#url.selectJobID#">
45 :       <cfinvokeargument name="selectCompanyName" value="#url.selectCompany_Name#">
Part of the problem seems to be that the included file dspsearchparams.cfm is in it's own cfform (line 71 of dsphome.cfm).  But, shouldn't CF "find" the variable change_board_type?

<cfinvokeargument name="board_type" value="#change_board_type#">

change_board_type is still in the "variables" scope in the code above (no scope = variables scope)

To put it in the URL scope, you need to add URL. before it.

<cfinvokeargument name="board_type" value="#URL.change_board_type#">


Which scope do you use?   - that depends on how the variable is getting to you.  If it is coming to the file via a web URL such as  myPage.cfm?vw=page&mode=edit&ID=123   then myPage.cfm needs to receive it as URL
At the very top of dspHome.cfm is;
<cfparam name="attributes.board_type" default="#url.board_type#">

The div has;
<cfinvoke component="cfc.basic" method="getPages" returnvariable="qPages">
      <cfinvokeargument name="board_type" value="#attributes.board_type#">

And I get the error;

 Element BOARD_TYPE is undefined in ATTRIBUTES.
 
The error occurred in D:\inetpub\wwwroot\TaxTalent.net\Development\control\jobads\dspPagesDiv.cfm: line 43

41 : <!--- <cfdump var="#url#"><cfabort> --->
42 : <cfinvoke component="cfc.basic" method="getPages" returnvariable="qPages">
43 :       <cfinvokeargument name="board_type" value="#attributes.board_type#">
44 :       <cfinvokeargument name="selectJobID" value="#url.selectJobID#">
45 :       <cfinvokeargument name="selectCompanyName" value="#url.selectCompany_Name#">


I'm missing the point somewhere.
when you call the page using this format...

  <cfdiv bind="url:dspPagesDiv.cfm?change_board_type={change_board_type}" bindonload="False" id="boardDiv" />

You are loading it as a completely stand-along page, as through you were calling it from the browser.

So it makes no difference what you have in the dspHome.cfm page

You must pass any variables to the dspPagesDiv.cfm right there after the ? in the bind parameter.  If you don't pass it, it will not receive it.   This is ajax, it is making a completely seperate call to that page.

So, the only scope available inside a cfdiv is the url scope from the calling cfdiv statement and any "scope" changes made inside the div?
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
One last thing;  when I code  
<cfdiv bind="url:dspPagesDiv.cfm?change_board_type=#change_board_type#& title={title}"  

,notice that I eliminated the braces,  the CFDIV is triggered and the bind fails supposedly by the second url parm.  Does the CFDIV always trigger on a @change event by default no matter how the parms are defined?

by changing it to this format...

change_board_type=#change_board_type#

You are giving it a static value.   The value of change_board_type will be set when the page loads and will not change when the user changes the field called change_board_type (assuming there is a field with that name).   That is good to do when you have something like a USER_ID which tells you the person who is logged in, that won't change.   If you want the contents of your CFDIV to change when board_type is changed, it needs to be with the brackets { }

The default behavior is @change, but there are other options available such as @click