Skip to main content
Inspiring
March 1, 2017
Question

CFGRID html with bind - not rendering, getting spinner

  • March 1, 2017
  • 2 replies
  • 3267 views

Sorry to bother everyone again, but I am again needing assistance with converting my CFGRIDS from applets to html formats using CFC and binds.

I have been testing the grids one step at a time -  first by just adding the format="html" and enclosing the CFGRID within a CFFORM.  Looks okay.  Then I created the cfc and moved the query, and created the bind.  Now I get the grid appearing without any data, and the spinner in the base of the grid.

Here is my code: payment.cfc

<cfcomponent>
    <cffunction name="getData" access="remote" output="false">
        <cfargument name="page">
        <cfargument name="pageSize">
        <cfargument name="gridsortcolumn">
        <cfargument name="gridsortdirection">

        <cfquery name="payment_all" datasource="Treasury">
          SELECT Payment_Type, Payment_Desc
            FROM paytype
<!---             <cfif gridsortcolumn# NEQ "" or gridsortdirection NEQ ""> 
                order by #gridsortcolumn# #gridsortdirection#
            </cfif> --->
     </cfquery>
        <cfreturn QueryConvertForGrid(payment_all, page, pageSize)>
    </cffunction>
</cfcomponent>

My grid: paymentgrid.cfm

<cfform>

       <cfgrid format="html" name="paymentcodegrid"  height="254" width="315"

                pagesize=10 selectmode="row" striperows="yes" font="Arial" fontsize="10"

                bind="cfc:payment.getData({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})" >

                <cfgridcolumn name="Payment_Type" header="Payment Code" width="95" />

                <cfgridcolumn name="Payment_Desc" header="Payment Description" width="200" />

        </cfgrid>

    </cfform>

Both my cfgrid and my cfc are textbook copies from the ColdFusion manual's. My results are all but textbook. First of all, the page with the CFGRID renders the grid empty, with the spinner in the bottom of the grid next to the >| button for the last page. No error is returned in the application.log or the exception.log.

Also, I have taken to commenting out the

<cfif gridsortcolumn# NEQ "" or gridsortdirection NEQ ""> 

                order by #gridsortcolumn# #gridsortdirection#

  </cfif>

statement from my query.  When I leave it in as is, I get a SQL Server error - "Error Executing Database Query.[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near the keyword 'ASC'. The specific sequence of files included or processed is: E:\inetpub\WWWROOT\Treasury\payment.cfc, line: 12 "

I have tried putting a default into the cfargument statements push the values, didn't work.  I even commented out the statement and just put in a regular 'order by' statement, and still get the same results.

So I've tried this both in CF 9,0,2,282541  and on CF10, so I am really stumped.  I've searched the internet and spent days with folks that have spent years working on ColdFusion with no luck.

Windows 2008, SQL Server 2008R2.

Any ideas would be greatly appreciated.

Thanks.  Libby H.

    This topic has been closed for replies.

    2 replies

    Libby_HAuthor
    Inspiring
    March 6, 2017

    I feel as though I've pulled everyone down the wrong path here - because I think I've figured out my problem - but caused more questions for myself.  As I have mentioned before in some of my questions before, most of this code was written long, long ago beginning in 2000, using ColdFusion 4.5 and FuseBox 4 (I think).  As with many companies, I took over support back in 2007, and there has never been enough time or money to bring existing code up to snuff (or the latest version) and I am the sole developer and production support.

    There is a  application.cfm but is it empty and all of the variable setting is done in appGlobals.cfm module. (I think this is a FuseBox thing.)  I have done more searching, and found a Forum discussion regarding 'spinning' and it mentions putting the line <cfargument name="thePage" type="string" required="true"> into your application.cfc OnRequestStart cffunction as a fix because the error is being trigger because the cfc bind is not completing before the page is rendered.  So, I mocked up an application.cfc and put

    <cfsavecontent variable="content">

             <cfinclude template="appGlobals.cfm">

    </cfsavecontent>

    in the OnApplicationStart cffunction.  This fixed my problem - but as I stated, I think I have caused more questions for myself.

    My new application.cfm has code that Shared Hosting Environment mappings (based on variables.thisServerType) as well as cfmodule calls.  I don't know where exactly where to put this stuff in the application.cfc.  as well as y existing code has CFGRIDs embedded within CFFORMs throughout my application, and because changing CFGRID format=html needs the CFGRID encased with CFFORM, you can't embed one CFFORM within another. Right?  What a can of worms I have.

    BKBK
    Community Expert
    Community Expert
    March 7, 2017

    Libby H wrote

    ...
    So, I mocked up an application.cfc and put

    <cfsavecontent variable="content">

             <cfinclude template="appGlobals.cfm">

    </cfsavecontent>

    in the OnApplicationStart cffunction.  This fixed my problem - but as I stated, I think I have caused more questions for myself.

    ...

    The last statement summarizes the situation. You say the problem is fixed, but it is unclear what happened. It cannot be due to the cfsavecontent. The tag does nothing but define a variable called content. Besides, the scope of this variable is limited. Though it is defined in onApplicationStart, it is not an application-scoped variable. You mention onRequestStart, but it plays no part in your solution.

    Could it be that, by placing <cfinclude template="appGlobals.cfm"> within cfsavecontent, you effectively make appGlobals.cfm invisible? If so, then you could have achieved the same result by just removing the file appGlobals.cfm.

    Test the idea. Return the code to its previous state. Then temporarily rename the file to app_Globals.cfm. Does the problem go away? If so, then the cause of the problem is likely to be a setting in or regarding appGlobals.cfm.

    Another test. Place the code <cfoutput>#expandPath('.')#</cfoutput> at the top in paymentgrid.cfm. Is the resulting string E:\inetpub\WWWROOT\Treasury ?

    Inspiring
    March 1, 2017

    Is this correct or a typo when you wrote it on here?

    <cfif gridsortcolumn# NEQ "" or gridsortdirection NEQ "">

    You have a rogue # in there that shouldnt be there and could be causing issues.

    This also cannot be an OR as it means it will work if either one has a value. In the case of the SQL error, the gridsortdirection as the value and gridsortcolumn doesn't, which means the SQL malforms. It should really be an AND to make sure they both pass to allow the order by

    If you still get the error when commenting out he SQL part, then I would suggest putting a cftry / cfcatch in your component function to output any errors that are happening. You could also make sure your cfarguments all have defaults so that there is guaranteed to be values passed further in the function.

    Finally you have the function QueryConvertForGrid, are you sure the values being passed here are correct and there is no error with this function?

    Libby_HAuthor
    Inspiring
    March 1, 2017

    Thank you for catching my typo (the # and the OR).  I have removed the # and replaced the OR with an AND - so that fixed that problem.

    But I still have the bigger issue of the CFGRID not rendering and the spinner.  I took your advise and placed a cftry/cfcatch as such:

    cfcomponent>
        <cffunction name="getData" access="remote" output="false">
            <cfargument name="page">
            <cfargument name="pageSize">
            <cfargument name="gridsortcolumn">
            <cfargument name="gridsortdirection">
    <cftry>
            <cfquery name="payment_all" datasource="Treasury">
              SELECT Payment_Type, Payment_Desc
                FROM paytype
                 <cfif gridsortcolumn NEQ "" and gridsortdirection NEQ ""> 
                    order by #gridsortcolumn# #gridsortdirection#
                </cfif>
         </cfquery>
            <cfreturn QueryConvertForGrid(payment_all, page, pageSize)>
    <cfcatch type="any">
    Whoops! There was an internal error.
    <br>Please contact the Administrator! <p>
    Here's info on the error:
    <cfoutput>
    <br>
    <b>Type</b>: #CFCATCH.Type#<br>
    <b>Message</b>: #CFCATCH.Message#<br>
    <b>Detail</b>: #CFCATCH.Detail#<br>

    <b>Fuseaction</b>: "#attributes.fuseaction#"<br>
    <b>Fuseaction2</b>: "#attributes.fuseaction2#"<br>

    </cfoutput>

    </cfcatch>
    </cftry>
        </cffunction>
    </cfcomponent>

    I still receive the same results - the CFGRID appears empty, with the spinner in the bottom of the grid next to the >| button for the last page. No error is returned in the application.log or the exception.log.  No result from the cftry/cfcatch.

    Inspiring
    March 1, 2017

    Outputting the error like that wont produce the result as you will not see the error output anywhere.

    The quickest thing to do is something like this

    <cfcatch type="any">

         <cflog text="#CFCATCH.Type# - #CFCATCH.Message# - #CFCATCH.Detail# - #CFCATCH.TagContext[1].line#  - #CFCATCH.TagContext[1].Template#">

    </cfcatch>

    This will just log an error to the application.log.