Coldfusion: Need to disable or block "Error invoking CFC - server error" error pop-up message - data-binding

I have a .cfm and .cfc that I am using to edit data in a cfgrid on the .cfm, and it works, however 10% of the time I will get the following error message:
"Error invoking CFC /test/editCFgrid.cfc: Internal Server Error"
I tried using the debugging advice, however no luck.
Here is the CFM code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<cfform name="artistform">
<cfgrid format="html" name="artistgrid" pagesize=11
striperows="yes"
bind="cfc:editCFgrid.getArtists({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
delete="yes" insert="yes" selectmode="edit"
onchange="cfc:editCFgrid.saveArtist({cfgridaction},{cfgridrow},{cfgridchanged})">
<cfgridcolumn name="firstname" header="First Name" />
<cfgridcolumn name="lastname" header="Last Name" />
<cfgridcolumn name="address" header="Address" />
<cfgridcolumn name="city" header="City" />
<cfgridcolumn name="state" header="State" />
<cfgridcolumn name="postalcode" header="Postal Code" />
<cfgridcolumn name="email" header="Email" />
<cfgridcolumn name="phone" header="Phone" />
<cfgridcolumn name="fax" header="Fax" />
<cfgridcolumn name="thepassword" header="Password" />
</cfgrid>
</cfform>
</body>
</html>
Here is the CFC code:
<cfcomponent output="FALSE">
<cffunction name="getArtists" hint="I extract artists from the database" access="remote" output="FALSE" returntype="struct">
<cfargument name="page" required="TRUE" hint="the page the grid is on" />
<cfargument name="pagesize" required="TRUE" hint="records displayed per page" />
<cfargument name="gridsortcolumn" required="TRUE" hint="selected column to sort" />
<cfargument name="gridsortdirection" required="TRUE" hint="the sort direction" />
<cfset var qArtists = "" />
<cfif arguments.gridsortcolumn eq "">
<cfset arguments.gridsortcolumn = "lastname" />
<cfset arguments.gridsortdirection = "asc" />
</cfif>
<cfquery name="qArtists" datasource="test_database">
SELECT *
FROM Artists
ORDER BY #arguments.gridsortcolumn# #arguments.gridsortdirection#
</cfquery>
<cfreturn QueryConvertForGrid( qArtists, arguments.page, arguments.pagesize ) />
</cffunction>
<cffunction name="saveArtist" type="any" hint="I insert, update or delete an artist" access="remote" output="FALSE" returntype="void">
<cfargument name="gridaction" type="any" required="TRUE" hint="I for insert, U for update and D for delete" />
<cfargument name="gridrow" type="any" required="TRUE" hint="the rows being inserted or updated" />
<cfargument name="gridchanged" type="any" hint="the changes" />
<cfset var qInsertArtist = "" />
<cfset var qUpdateArtist = "" />
<cfset var qDeleteArtist = "" />
<cfif IsStruct( arguments.gridrow ) and IsStruct( arguments.gridchanged )>
<cfif arguments.gridaction eq "I">
<cfquery name="qInsertArtist" datasource="test_database">
INSERT INTO Artists
(firstname, lastname, address, city, state, postalcode, email, phone, fax, thepassword)
VALUES
(<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.firstname#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.lastname#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.address#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.city#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.state#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.postalcode#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.email#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.phone#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.fax#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.thepassword#" />)
</cfquery>
<cfelseif arguments.gridaction eq "U">
<cfset var colname = StructKeyList( arguments.gridchanged ) />
<cfset var value = StructFind( arguments.gridchanged, colname ) />
<cfquery name="qUpdateArtist" datasource="test_database">
UPDATE Artists
SET #colname# = <cfqueryparam value="#value#" />
WHERE artistid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.gridrow.artistid#" />
</cfquery>
<cfelseif arguments.gridaction eq "D">
<cfquery name="qDeleteArtist" datasource="test_database">
DELETE FROM Artists
WHERE artistid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.gridrow.artistid#" />
</cfquery>
</cfif>
</cfif>
</cffunction>
</cfcomponent>
Each function (edit, insert, delete, etc) works, but it randomly will generate the error. Ultimately, I am seeking a code that will ignore/block/"OK" the error message so the user won't see it.
Any help will be greatly appreciated! I have spent the entire day (9 hours) googling for an answer, but I haven't found any. I do not have access to the CF Admin Log, I'm just a regular developer. Thanks!

Google chrome, firebug in firefox, IE developer tools can all help you with this.
In google chrome (my preference), right click on your page > inspect element. Then go to the network tab. You'll have to refresh your web page. Then you will see your cfc in the list of files (probably RED). Right click > open in new tab, and you'll open the cfc directly with all the arguments being called. You should then be able to see your error.
There is no ignore/block/ok. You need to fix the error.

Perhaps a time out or a SQL error. To get the full error use: cferror, this tag show a full debug information (better than debug server info) I sent it to me by mail:
Put this on you Application file:
<cferror type="exception" template="error.cfm" />
<cferror type="request" template="error.cfm" />
Create a "error.cfm" file with:
"Error message"
<cfsavecontent variable="errorContent">
<cfoutput>
An error occurred: http://#cgi.server_name##cgi.script_name#?#cgi.query_string#<br />
Time: #dateFormat(now(), "short")# #timeFormat(now(), "short")#<br />
<h2>Error:</h2>
<cfdump var="#error#" label="Error">
<h2>Form:</h2>
<cfdump var="#form#" label="Form">
<h2>URL:</h2>
<cfdump var="#url#" label="URL">
<h2>SESSION:</h2>
<cfdump var="#SESSION#" label="SESSION">
</cfoutput>
</cfsavecontent>
<cfmail to="mail#mymail.com" from="mail#mymail.com" subject="Error on #cgi.server_name#: #error.message#" type="html">
#errorContent#
</cfmail>

There is a way to ignore/block/ok the "error" message with the following script:
<script>ColdFusion.setGlobalErrorHandler(function (error)
{mygrid = ColdFusion.Grid.refresh ('artistgrid', false);
}
);
</script>
Insert this script in the CFM files, and you're good to go! Being that the error that I was encountering was not impacting the function (editing the cells) of the cfgrid (the pop-up message was being more of a nuisance then anything else). Hopefully this solution will help others!
You do not need to use the 'Grid.refresh' command in the script, you can use anything command you want.
Thanks everyone who attempted to answer my issue!

Related

How to disable checkboxes 's option in dialog.xml in CQ5 AEM?

I have designed my CQ5 dialog as given in the following image. I have to disable my checkboxes options as highlighted in the image.
And dialog.xml is like
<stewartOwned jcr:primaryType="cq:Widget"
defaultValue="false" fieldLabel="Stewart Owned"
inputValue="false" name="./stewartOwned" type="checkbox"
xtype="selection" layout="hbox">
<options jcr:primaryType="cq:WidgetCollection">
<option1 jcr:primaryType="nt:unstructured" text=""
value="stewartOwned" />
<option2 jcr:primaryType="nt:unstructured" text=""
value="ShowInAdvanced" />
</options>
<optionsConfig jcr:primaryType="nt:unstructured"
width="150" />
</stewartOwned>
<independent jcr:primaryType="cq:Widget"
defaultValue="false" fieldLabel="Independent" inputValue="false"
name="./independent" type="checkbox" xtype="selection"
layout="hbox">
<options jcr:primaryType="cq:WidgetCollection">
<option1 jcr:primaryType="nt:unstructured" text=""
value="I" />
<option2 jcr:primaryType="nt:unstructured" text=""
value="ShowInAdvanced" />
</options>
<optionsConfig jcr:primaryType="nt:unstructured"
width="150" />
</independent>
I have tried following solution to disable through id but it is not viable as id is auto generate and you never know what id will be generated in the next session.
listeners jcr:primaryType="nt:unstructured"
loadcontent="function(dialog) {
CQ.Ext.getDom('ext-comp-1568').disabled = 'disabled';
CQ.Ext.getDom('ext-comp-1573').disabled = 'disabled';
}" />
Can someone please suggest how I disable highlighted checkboxes in dialog.xml ?
After a lot of research and reading CQ5 documentation, I managed to find out following solution.
var nameField =
dialog.getField('./name').getEl().child('input[value*=ShowInAdvanced]').id;
CQ.Ext.getDom(nameField).disabled = 'disabled';

cfselect bind in cfc does not work when I enable Application.cfc

I am trying to create a form with 3 select boxes that are bound to a cfc (triple related cfselect). If I remove the Application.cfc, the code runs just fine, the select box gives me the data I need. However, when I add Application.cfc which has cflogin function which requires users to login before they are able to use any page than my triple related select boxes do not work anymore. The select box just doesn't give out any data from the query in the function. It still connects to the function page, because when I change the name on the bind of the cfselect, it will let me know that that function does not exist in the component. I am not sure what I have to do to make the triple related cfselect work with cflogin in place.
I am using ColdFusion 10
I really appreciate any suggestions.
Thanks, Niva
I added the code:
This is code on form
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold; width=100">Product Type:</td>
<td width="200">
<cfselect name="Selproducttype" bind="cfc:groupfnc.getproducttypeid()"
display="description" value="producttypeid" BindOnLoad="true"/></td></tr>
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold; width=100">Vendor:</td>
<td width="200">
<cfselect name="Selvendor" bind="cfc:groupfnc.getven({Selproducttype})"
display="fullname" value="vendorid" BindOnLoad="true"/></td></tr>
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold; width=100">Product:</td>
<td width="200">
<cfselect name="Selprod" bind="cfc:groupfnc.getprod({Selvendor})"
display="fullname" value="productid" BindOnLoad="true" /></td></tr>
<tr valign="top">
<td style="color:DarkSeaGreen; font-weight:bold; width=100">Sub Product:</td>
<td width="200">
<cfselect name="Selsubprod" bind="cfc:groupfnc.Getsub({Selprod})"
display="fullname" value="productsubid" /></td></tr>
Code on component: groupfnc.cfc
<cffunction name="getproducttypeid" access="remote" output="false" returntype="query">
<cfquery name="listproducttype" datasource="xxxxxx">
Select distinct producttypeid, (Case when producttypeid = '101' then 'Hotel'
when producttypeid='201' then 'optionalTour'
when producttypeid = '301' then 'Transporation'
when producttypeid = '501' then 'MISC'
when producttypeid = '601' then 'OTH' end) as description
From products
</cfquery>
<cfreturn listproducttype />
</cffunction>
<cffunction name="getven" access="remote" output="false" returntype="Query">
<cfargument name="Selproducttype" type="any" required="true">
<cfif ARGUMENTS.Selproducttype EQ "">
<cfset ARGUMENTS.Selproducttype = '0'>
</cfif>
<cfquery name="listven" datasource="xxxxxx">
SELECT distinct vendors.fullname, vendors.vendorid
from vendors, products
where products.vendorid= vendors.vendorid
and products.producttypeid = #ARGUMENTS.Selproducttype#
ORDER BY fullname
</cfquery>
<cfreturn listven />
</cffunction>
<cffunction name="getprod" access="remote" output="false" returntype="Query">
<cfargument name="Selvendor" type="any" required="true">
<cfif ARGUMENTS.Selvendor EQ "">
<cfset ARGUMENTS.Selvendor = '0'>
</cfif>
<cfquery name="Lstprod" datasource="xxxxxx">
Select productid, fullname from products
where vendorid = #ARGUMENTS.Selvendor#
order by fullname
</cfquery>
<!---</cfif>--->
<cfreturn Lstprod />
</cffunction>
<cffunction name="Getsub" access="remote" output="false" returntype="Query">
<cfargument name="Selprod" type="any" required="true">
<cfif ARGUMENTS.Selprod EQ "">
<cfset ARGUMENTS.Selprod = '0'>
</cfif>
<cfquery name="Lstsubprod" datasource="xxxxxx">
Select productsubid, fullname from productsubs
where productid = #ARGUMENTS.Selprod#
order by fullname
</cfquery>
<!---</cfif>--->
<cfreturn Lstsubprod />
</cffunction>
Here is my application.cfc
<cfcomponent>
<cfset This.name = "Orders">
<cfset This.Sessionmanagement="True">
<cfset This.loginstorage="session">
<cffunction name="OnRequestStart">
<cfargument name = "request" required="true"/>
<cfif IsDefined("Form.logout")>
<cflogout>
</cfif>
<cflogin>
<cfif NOT IsDefined("cflogin")>
<cfinclude template="loginform.cfm">
<cfabort>
<cfelse>
<cfif cflogin.name IS "" OR cflogin.password IS "">
<cfoutput>
<h2>You must enter text in both the User Name and Password fields.
</h2>
</cfoutput>
<cfinclude template="loginform.cfm">
<cfabort>
<cfelse>
<cfquery name="loginQuery" dataSource="xxxxxx">
SELECT userid, roles
FROM logininfo
WHERE
userid = '#cflogin.name#'
AND upassword = '#cflogin.password#'
</cfquery>
<cfif loginQuery.roles NEQ "">
<cfloginuser name="#cflogin.name#" Password = "#cflogin.password#"
roles="#loginQuery.roles#">
<cfelse>
<cfoutput>
<H2>Your login information is not valid.<br>
Please Try again</H2>
</cfoutput>
<cfinclude template="loginform.cfm">
<cfabort>
</cfif>
</cfif>
</cfif>
</cflogin>
<cfif GetAuthUser() NEQ "">
<cfoutput>
<form action="securitytest.cfm" method="Post">
<input type="submit" Name="Logout" value="Logout">
</form>
</cfoutput>
</cfif>
</cffunction>
</cfcomponent>
I found the problem. Because in my Application.cfc has this part:
<form action="securitytest.cfm" method="Post">
<input type="submit" Name="Logout" value="Logout">
</form>
</cfoutput>
So looking at the ajax response the logout form is placed infornt so the select box didnt parse the value.I removed this partin the Application.cfc and the page run just fine.
Thank you so much for all your help!
^_^

How to add new line character in following code?

When i inserting the data in database then there is facility to the user that in multiline textbox he can write sentence in multiple line.
So when i am populating the same data the database it populate the data like this : fffffffffffffffffffffffffffffff<br /> f<br /> f<br /> f<br /> f<br /> f<br /> f<br /> f<br /> f<br /> <br /> ff<br /> f<br /> f<br /> <br /> <br /> <br /> fff
but i want to remove &lt, &gt ,br. For this i have used following code but my purpose is not solved. So how to do that:
txtEditorOpportunity.Text = dbReader["DESCRIPTION"].ToString().Replace("<br/>", "\n");
There is a space in the <br /> tag in your question, so while using Replace method. Try it like
.Replace("<br />", "\n");
Note the space character between br and / which makes it <br /> and NOT <br/>
You are doing it correctly. Just observe the tags that you are getting, they contain a space between "". So make sure that you put a space in your replace command accordingly.
Something like this.
.Replace("<br />", "\n");
Some browsers treat <br /> as just <br>, so to be sure that nothing goes wrong, you can replace the above code with the following code.
.Replace("<br />", "\n").Replace("<br>", "\n");

Weird behaviour with Chrome browser and data bound button

I've noticed some strange browser specific weirdness with Google
Chrome with some data bound buttons, in that when you navigate away
from the page then use the browsers back button the data bind displays
different data. If you then hit refresh it resets to the correct data.
It doesn't happen in Firefox or Explorer 7.
I had actually entered the data bound bool button example to CF
Cookbook http://cookbooks.adobe.com/post_Using_cfinput_buttons_and_data_binding_to_toggle_d-16390.html so the files I'm using are there, direct link is http://cookbooks.adobe.com/index.cfm?event=getFile&fileId=6902
but now I have spotted this cross browser quirk I feel I should take
it down unless of course you can help me figure out what is going
on!
Any clues appreciated.
bool_buttons.cfm
<cfset url.messageID=28>
<CFSET application.dsn = "data">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<cfform>
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle1#click},'referral', 'Referral', 'Message')" name="toggle1" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle2#click},'viewed', 'Read', 'Unread')" name="toggle2" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle3#click},'actioned', 'Actioned', 'Pending')" name="toggle3" value="" bindonload="YES">
</cfform>
</body>
</html>
messageProcess.cfc
<cfcomponent>
<cffunction access="remote" name="togglebool" output="true" returntype="any" displayname="Toggle boolean value in message record" hint="Toggles boolean value in message record">
<cfargument required="true" name="dsn" type="string"/>
<cfargument required="true" name="messageID" type="numeric"/>
<cfargument required="true" name="buttonLabel" type="string"/>
<cfargument required="true" name="switchName" type="string"/>
<cfargument required="true" name="switchOnLabel" type="string"/>
<cfargument required="true" name="switchOffLabel" type="string"/>
<cfset var returnMessage = "" />
<cfset var temp = "" />
<cfquery datasource='#arguments.dsn#' name="getSwitchData">
SELECT #arguments.switchName#
FROM messages
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfset temp="getswitchdata."&#switchName#>
<cfif #Evaluate(temp)# is 1>
<cfset returnMessage="#arguments.switchOnLabel#">
<cfelse>
<cfset returnMessage="#arguments.switchOffLabel#">
</cfif>
<cfif buttonLabel eq "">
<cfreturn returnMessage>
<cfelseif buttonLabel eq "#arguments.switchOffLabel#">
<cfquery datasource='#arguments.dsn#'>
UPDATE messages
SET #arguments.switchName#=1
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfreturn "#arguments.switchOnLabel#">
<cfelseif buttonLabel eq "#arguments.switchOnLabel#">
<cfquery datasource='#arguments.dsn#'>
UPDATE messages
SET #arguments.switchName#=0
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfreturn "#arguments.switchOffLabel#">
</cfif>
</cffunction>
</cfcomponent>
This is a Google Chrome bug, I had a similar case and opened a ticket here

How can I bind a button control to a cfc to toggle a boolean database value

I would like to able to bind a series of 3 buttons to toggle 3 boolean values on a database message entry. The boolean database entries are read|unread, actioned|pending, referral|message and the message entry has the unique key "messageID". I want the buttons to display the record starting values (which I presume is bindonload="true").
I've limped towards
<cfform>
<cfinput type="hidden" name="switchName" value="read">
<cfinput type="button" bind="cfc:cfcs.messages.toggle({toggle#click},{switchName#none})" name="toggleRead" value="Read" bindonload="true">
</cfform>
and in the cfc
<cffunction access="remote" name="toggle" output="false" returntype="any" >
<cfargument required="true" name="toggle" type="any"/>
<cfargument required="true" name="switchName" type="any"/>
<cfif toggle eq "Read">
<cfreturn "Unread">
<cfelseif toggle eq "Unread">
<cfreturn "Read">
</cfif>
</cffunction>
This gets me some of the way there, in so far as it toggles the button label, but I'm foxed on how to pick up the initial db values to display the initial status.
Also is there a way to pass other variables in the bind statement without using hidden fields and control#none format, e.g. I will need to pass in the messageID so I can update the correct record. I wouldn't have put in the switchName input if I knew how to simply pass the switchName variable in a beter way.
Many thanks for any light you can shed?
How about...
<cfinput type="button" bind="cfc:cfcs.messages.toggle({toggle#click}, #switchName#)" value="#initialValue#" bindonload="false">
or alternatively:
<cfajaxproxy bind="javascript:yourJSFunc({toggle#click})">
and in your yourJSFunc, use whatever JS var's you need.
That helped Henry.
I got it working, though it feels a bit kludgy...
<cfform>
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle1#click},'referral', 'Referral', 'Message')" name="toggle1" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle2#click},'viewed', 'Read', 'Unread')" name="toggle2" value="" bindonload="YES">
<cfinput type="button" STYLE="width: 80px; height: 22px;" bind="cfc:messageProcess.togglebool('#application.dsn#', '#url.messageID#',{toggle3#click},'actioned', 'Actioned', 'Pending')" name="toggle3" value="" bindonload="YES">
</cfform>
and the cfc
<cfcomponent>
<cffunction access="remote" name="togglebool" output="true" returntype="any" displayname="Toggle boolean value in message record" hint="Toggles boolean value in message record">
<cfargument required="true" name="dsn" type="string"/>
<cfargument required="true" name="messageID" type="numeric"/>
<cfargument required="true" name="buttonLabel" type="string"/>
<cfargument required="true" name="switchName" type="string"/>
<cfargument required="true" name="switchOnLabel" type="string"/>
<cfargument required="true" name="switchOffLabel" type="string"/>
<cfset var returnMessage = "" />
<cfset var temp = "" />
<cfquery datasource='#arguments.dsn#' name="getSwitchData">
SELECT #arguments.switchName#
FROM messages
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfset temp="getswitchdata."&#switchName#>
<cfif #Evaluate(temp)# is 1>
<cfset returnMessage="#arguments.switchOnLabel#">
<cfelse>
<cfset returnMessage="#arguments.switchOffLabel#">
</cfif>
<cfif buttonLabel eq "">
<cfreturn returnMessage>
<cfelseif buttonLabel eq "#arguments.switchOffLabel#">
<cfquery datasource='#arguments.dsn#'>
UPDATE messages
SET #arguments.switchName#=1
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfreturn "#arguments.switchOnLabel#">
<cfelseif buttonLabel eq "#arguments.switchOnLabel#">
<cfquery datasource='#arguments.dsn#'>
UPDATE messages
SET #arguments.switchName#=0
WHERE messageID=<cfqueryparam value="#arguments.messageID#" cfsqltype="CF_SQL_INTEGER"/>
</cfquery>
<cfreturn "#arguments.switchOffLabel#">
</cfif>
</cffunction>
If there's a slicker way please let me know.

Resources