• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Query object in main page available to iframe?

LEGEND ,
Jul 30, 2012 Jul 30, 2012

Copy link to clipboard

Copied

Hello, everyone.

What is the best way to make a query object in a document available to an iframe (with a .cfm file as the source of the iframe) in that document?

Thanks,

^_^

Views

2.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jul 30, 2012 Jul 30, 2012

>> So, which is best, Application scope, or Session scope?

If the data is user specific, then probably the session scope. Performance-wise, either one should be fine.

>> And will a simple CFSET SESSION.VariableName = CFQUERYOBJECT work?  I didn't think a simple variable could contain a complex object?

What makes a variable simple or complex is its content. 

<cfset session.key = 1 /> Creates a simple variable

<cfset session.key = structNew() /> Creates a complex variable

Yes, session.key = queryObje

...

Votes

Translate

Translate
Advocate ,
Jul 30, 2012 Jul 30, 2012

Copy link to clipboard

Copied

An iframe is just another window. If it is loading a .cfm file then how woudl you get that query object into any other .cfm file? 

Don't let the source being loaded in an iframe confuse you. It's just another .cfm file. It doesn;t become an iframe til it reaches the client, and at that point it is long past ColdFusion's control. If you're thinking that the parent window will somehow pass a CF query to the iframe window, then you're thinking along the wrong track. The parent window is makign the request for the iframe document after it has left the server. It no longer has any concept of what a ColdFusion query is.

If you need to ensure that the parent window and the iframe run the same dynamic query then you could do something like this:

1. User requests the parent window

2. Dyanmic query is run

3. Query is cached in the App or session scope with a Unique key

4. Iframe is created using that unique key (example: <iframe src="/childPage.cfm?queryKey=34jkldsflhsfdsdf" />)

5. When iframe is loaded by the browser it receives that key, looks up the query in the cache and uses it instead of making a new query.

jason

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 30, 2012 Jul 30, 2012

Copy link to clipboard

Copied

I did NOT think that the parent window will somehow pass a CF query to the iframe window; that's why I came into this forum to ask.

I had thought about inserting the query object into the session scope, but didn't know how to do so.

As of right now, when the iframe loads it is just a blank form.  I am using JavaScript to reload the form with the ID of a record when a link is clicked.  Instead of reaching out to the database, I figured it would be more efficient to query the query of the parent document.

So, which is best, Application scope, or Session scope?  And will a simple CFSET SESSION.VariableName = CFQUERYOBJECT work?  I didn't think a simple variable could contain a complex object?

Thanks,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 30, 2012 Jul 30, 2012

Copy link to clipboard

Copied

>> So, which is best, Application scope, or Session scope?

If the data is user specific, then probably the session scope. Performance-wise, either one should be fine.

>> And will a simple CFSET SESSION.VariableName = CFQUERYOBJECT work?  I didn't think a simple variable could contain a complex object?

What makes a variable simple or complex is its content. 

<cfset session.key = 1 /> Creates a simple variable

<cfset session.key = structNew() /> Creates a complex variable

Yes, session.key = queryObject will work just find.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 30, 2012 Jul 30, 2012

Copy link to clipboard

Copied

Regarding "Yes, session.key = queryObject will work just find"

cfquery name="session.something" accomplishes the same thing with one less command.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 30, 2012 Jul 30, 2012

Copy link to clipboard

Copied

In the parent document, I coded "<cfset session.query1 = queryName>", and in the iframe document, I coded "SELECT * FROM #session.query1# WHERE id=#url.id#" and am getting the error message that complex object types cannot be converted to simple values.  Do I need to set the session variable to StructNew(), first?

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 30, 2012 Jul 30, 2012

Copy link to clipboard

Copied

LATEST

OP!  Got it.. I just had to remove the hash marks from "session.query1" and it worked!

Thanks, Jason!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation