6 Replies Latest reply: Jul 30, 2012 9:53 AM by WolfShade RSS

    Query object in main page available to iframe?

    WolfShade Community Member

      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,

       

      ^_^

        • 1. Re: Query object in main page available to iframe?
          12Robots Community Member

          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

          • 2. Re: Query object in main page available to iframe?
            WolfShade Community Member

            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,

             

            ^_^

            • 3. Re: Query object in main page available to iframe?
              12Robots Community Member

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

               


              • 4. Re: Query object in main page available to iframe?
                Dan Bracuk Community Member

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

                 

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

                • 5. Re: Query object in main page available to iframe?
                  WolfShade Community Member

                  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?

                   

                  ^_^

                  • 6. Re: Query object in main page available to iframe?
                    WolfShade Community Member

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

                     

                    Thanks, Jason!