Solved

cfdiv scopes

Posted on 2011-02-18
18
1,301 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

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
 

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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM:  How to open a cfwindow or run a function on double click of a cfgrid row. One of my clients wanted to be able to double click on a row item to get more detailed information about a transaction and to be able to modify the line items i…
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

737 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