application.cfc and page handling/propagation - coldfusion

Is it possible to render a different page when the requested page does not exist using the OnRequestStart event handler?
function onRequestStart( string targetPage ) {
// handle another page
}
if(FileExists(cgi.script_name)){
include cgi.script_name;
}else{
// render another page
}
if I use the include directly instead of passing it through onRequestStart, I get an error about missing SESSION
If I don't abort the execution, I get the File not found error. Is there a way to skip trying to find the file and use the onRequestStart event to render a different page?

If you are trying to prevent a 404 of a coldFusion page (e.g. /index2.cfm) where the cfm template doesn't exists you can use onMissingTemplate() in your application.cfc
If the template that causes the 404 isn't something handled by CF (i.e .htm,.html) then you will have to catch it in the webserver using a custom 404 page or possibly a url rewite

Try this insted
OnError()
This fires if an exception gets thrown and is not caught by the controlling code.
Check this article
Ben Nadel on application.cfc

Related

Lucee- invalid component definition for custom tag

I'm working on a Lucee application that makes heavy use of custom tags.
My structure is as follows:
Calling app file - C:\lucee\tomcat\webapps\web-portal\web-champs\index.cfm
Location of file I'm calling - C:\lucee\tomcat\webapps\empportal\Champs\CFC\invoice.cfc
I've defined a custom tag in the Lucee admin with a name of empportal and resource of C:\lucee\tomcat\webapps\empportal\ (also tried without a trailing \). I restarted the server after adding the custom tag.
Error message
invalid component definition, can't find component [empportal.Champs.CFC.invoice]
Stacktrace
The Error Occurred in
C:\lucee\tomcat\webapps\web-portal\web-champs\dsp_outstandingInvoices.cfm: line 1
1: <cfinvoke component="empportal.Champs.CFC.invoice" method="getOutstandingItems" org_ID="#session.orgID#" returnvariable="getOutstandingItems" />
I also tried creating the component using new empportal.Champs.CFC.invoice() and same issue.
In Lucee you need to place files in the ROOT\ folder so tomcat can load them. In my case moving the folders to C:\lucee\tomcat\webapps\ROOT\ instead of C:\lucee\tomcat\webapps\ and restarting fixed the issue.

Handlebars.SafeString() issue in Meteor?

I have did a sample example of dynamic loading templates using the Handlebars.SafeString(). Everything works fine expect Refresh the browser URL. When ever refresh the browser url i get an error i.e "Uncaught TypeError: Property 'undefined' of object # is not a function".And this error get only this line i.e return new Handlebars.SafeString(Template[Session.get('currentTemplate')]({dataKey: 'somevalue'}));. With out this line Works fine everything even Refresh also.I am using this Handlebars.SafeString() is to load templates dynamically. I didn't have any idea about this So please help me how to?.
And What is the use of dataKey in above Handlebars.SafeString()?
It looks like the Session dict is not populated when the call is made, and therefore Session.get('currentTemplate') is undefined. A simple safeguard should fix the problem, assuming you're in a reactive context:
if(! Session.get('currentTemplate')) return '';
return new Handlebars.SafeString(Template[Session.get('currentTemplate')]({dataKey: 'somevalue'}));

Angularjs refresh ng:view

While using Angularjs v0.9 and php to implement my membership system
In this following function, I will call an api to edit the data of the member, on success, the php function will return
{"success":"true"}
and the controller will return to a page that can view the member of the data.
if(response.success==="true") {
window.location="#/register_members";
$('.alert-error').hide();
$('.alert-success').html("Member is updated.");
$('.alert-success').fadeIn();
}
However, at #/register_members, the data still remains as the unchanged data. Is there anyway I can refresh the page partially in angularjs? I am using ng:view and $route.
I have tried using
window.location.reload(true);
but the success message will not be rendered as the whole page is renewed.
Does anyone have any idea?
Found an interesting answer here to refresh a div in the page using Jquery
my page is "#/register_members"
the div i want to update is "#registerlist" which is inside a div called "#browse-box".
so now my controller will be
window.location="#/register_members";
$("#browse-box").load("/#/register_members #registerlist")
$('.alert-error').hide();
$('.alert-success').html("Member is updated.");
$('.alert-success').fadeIn();
works like a charm. :)

Django 404 dilemma

I have a bug in my 404 setup. I know that because, when I try to reach some page which doesn't exist, I get my server error template. But that templates is useless because it doesn't give me any debug info. In order to get django's debug page, I need to set DEBUG=True in settings file. But if I do that, bug doesn't appear because django doesn't try to access my buggy 404 setup. So what do you guys think? This is in my root urls file:
handler404 = 'portal.blog.views.handlenotfound' And this is in portal.blog.views.handlenotfound:
def handlenotfound(request):
global common_data
datas = {
'tags' : Tag.objects.all(),
'date_list' : Post.objects.filter(yayinlandi=True).dates("pub_date","year")
}
data.update(common_data)
return render_to_response("404.html",datas)
Edit:
I guess I also need to return a HttpResponseNotFound right?
If I had to debug this kind of errors, I would either
temporarily turn the handler into a simple view served by a custom url, so that django's internal mechanisms don't get into the way, or
(temporarily) wrap the handler code in a try..except block to log any error you may have missed
Anyway, are you sure your handler doesn't get called if DEBUG=true?
data.update(common_data) should be datas.update(common_data).
(Incidentally, data is already plural: the singular is datum.)

NullPointerExceptions in ColdFusion 9 and ColdBox on localhost

I'm running CF 9.0.1 Developer and Coldbox 3.0.0 on my local machine (64-bit Windows Vista running 32-bit CF9 on Apache). I'm working on an application that I've checked out from SVN and deployed locally. Everything seems to be working correctly, but my application log is filling up with entries like this:
Apr 18, 2011 12:41 PM Error jrpp-7
exception.log has an extremely long stack trace for each exception, maybe 150 lines or so. It starts with this:
"Error","jrpp-4","04/18/11","11:07:30",,""
java.lang.NullPointerException
at coldfusion.util.Utils.getServletPath(Utils.java:86)
at coldfusion.util.Utils.getServletPath(Utils.java:76)
at coldfusion.util.Utils.getBaseTemplatePath(Utils.java:405)
at coldfusion.runtime.TemplateProxyFactory.getTemplateFileHelper
(TemplateProxyFactory.java:1522)
at coldfusion.runtime.MetadataUtils.getComponentMetadata
(MetadataUtils.java:112)
at coldfusion.runtime.CfJspPage.GetComponentMetaData(CfJspPage.java:2667)
at coldfusion.runtime.TemplateProxy.getRuntimeComponentMetadata
(TemplateProxy.java:1756)
at coldfusion.runtime.TemplateProxy.getRuntimeMetadata
(TemplateProxy.java:1617)
at coldfusion.runtime.MetadataUtils.getMetaData(MetadataUtils.java:54)
at coldfusion.runtime.CfJspPage.GetMetaData(CfJspPage.java:2640)
at cfEventHandler2ecfc862260423$funcPOSTLOAD.runFunction
(C:\ColdFusion9\wwwroot\ybocv5\coldbox\system\orm\hibernate
\EventHandler.cfc:30)
This is a version of an app that has been running in production, and what makes me think this is just on my local version is the appearance of this in the stack trace:
at cfdump2ecfm471394032$funcRENDEROUTPUT.runFunction
(E:\cf9_updates_rc\cfusion\wwwroot\WEB-INF\cftags\dump.cfm:704)
...
at cfCollectionPanel2ecfm961210602.runPage
(C:\ColdFusion9\wwwroot\ybocv5\coldbox\system\includes
\panels\CollectionPanel.cfm:40)
We don't use cfdump in production; this looks like ColdBox is trying to display a complex object in a debugger panel and failing.
The only thing I found online so far was this thread in Google's transfer-dev group ... someone who saw a bunch of similar errors and thought maybe it was a CF9 bug. The only reply with any sort of solution was this one, suggesting a fix that seems to be Transfer-specific.
Does anyone know what might be causing these errors? It's not as important to me to fix them as it would be on a production app, but if I'm spamming my logs with these errors, it's hard to find legitimate errors when they do occur.
Update: I've been working with the CollectionPanel.cfm template to identify the root cause, and the exception is consistently thrown here:
<cfelseif isObject(varVal)>
<!--- this cfdump is the guilty party ... --->
<cfdump var="#varVal#" expand="false" top="2">
<cfelse>
I've tried wrapping the cfdump in a try-catch, but the exception is thrown anyway, always from that same line of code. This makes sense, I guess, given that these errors don't have any visible effect on the pages on which they occur.
It appears to not be caused from a <cfdump> instead from a GetMetaData() call.
Specifically when you get the meta data of a cfc, which extends another cfc which has been modified after the current has been compiled (and where GetMetaData has been run) where it needs to update the extends struct in the GetMetaData() return. Cf only generates the meta data struct once, most likely for performance reasons.
I think it might be a bug in cf...
Inside the TemplateProxyFactory.getTemplateFileHelper() it's calling runtime.resolveTemplatePath(compName + ".cfc") where compName is name.replace('.', '/')
All good and well until you use a mapping. If you straight out replace dots with slashes, you'll need to add a leading slash, just like they do in TemplateProxy.getMetaData()
Without the leading slash, resolveTemplatePath() returns null, which triggers the VFSFileFactory.getFileObject() call which tries to get a File object from the parent cfc name.
Before it even gets to the VFSFileFactory, it calls Util.getBaseTemplatePath() with the pageContext. Inside it gets the ServletContext from the pageContext and tries to call getServletPath() so that it can get its real path. Utils.getServletPath() tries to get the attribute "javax.servlet.include.servlet_path" which on my machine (and probably yours) doesn't exist and returns null.
You can check by calling this: isNull(getPageContext().getRequest().getRequest().getAttribute("javax.servlet.include.servlet_path")); - yes, there is supposed to be two .getRequest() calls in there.
So it seems Cf is trying to refresh it's extends struct in a cfc getMetaData() call when the extended file is modified and does it a different way then when it first generated the struct.
In you cf admin, what are you settings under Server Settings > Caching?
Trusted cache? Cache template in request? Component cache? Save class files? Cache web server paths?