Solved

cfdiv scopes

Posted on 2011-02-18
18
1,295 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:lantervj
  • 11
  • 7
18 Comments
 
LVL 39

Expert Comment

by:gdemaria
ID: 34928919

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..
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 34928998
>  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.

0
 

Author Comment

by:lantervj
ID: 34929264
0
 

Author Comment

by:lantervj
ID: 34929272
0
 

Author Comment

by:lantervj
ID: 34929281
0
 

Author Comment

by:lantervj
ID: 34929324
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.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 34929476


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#">
                                                                                 ^^^^^^

0
 

Author Comment

by:lantervj
ID: 34929964
Why would I cfparam it if it's in the variable scope?
0
 

Author Comment

by:lantervj
ID: 34929967
Nevermind.  I caught myself just as I hit the submit button.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:lantervj
ID: 34930021
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#">
0
 

Author Comment

by:lantervj
ID: 34930041
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?
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 34930068

<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
0
 

Author Comment

by:lantervj
ID: 34930296
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.
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 34930443
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.

0
 

Author Comment

by:lantervj
ID: 34930503
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?
0
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 34931364
> So, the only scope available inside a cfdiv is the url scope from the calling cfdiv

I would not say it that way, but in this instance I guess that is correct.

Think of any web page, let's say ContactDetail.cfm

If I access the page like this  ContactDetail.cfm?mode=read&ID=123

then you will get variables URL.mode and URL.ID via the URL scope.

If you do a form post with the action="ContactDetail.cfm"  then you will get variables via the form scope

If you acess it via <cfmodule template="contactDetail.cfm" mode="edit" ID="123">

then you will receive those variables via the attributes scope.

So in your case, you are access the page as in the first example via the URL

  <cfdiv bind="url:dspPagesDiv.cfm?change_board_type={change_board_type}"

see the query string format after the .cfm?    

That means you are calling the coldfusion template just you typed it into the address bar with URL variables.   So, the WAY you are calling it, means you must access the variables via the URL.

With a CFDIV you can also do a <CFINCLUDE> to <CFMODULE> inside of it which would mean different variables are available.

I hope that explanation helped.   But the short answer is, you need to pass it all onthe URL.


0
 

Author Comment

by:lantervj
ID: 34932105
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?
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 34933285

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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Hi, I will be creating today a basic tutorial on how we can create a Mail Custom Function and use it where ever we want. The main advantage about creating a custom function is that we can accommodate a range of arguments to pass to the Function and …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now