Showing posts with label ajax. Show all posts
Showing posts with label ajax. Show all posts

Thursday, September 09, 2010

ORM is not configured for the current application

Working on a little app in ColdFusion 9.  Was consistently getting a phantom ColdFusion error (especially containers loaded by the built-in ColdFusion.navigate function):
ORM is not configured for the current application

Very mysterious, and took a while to troubleshoot.  In my Application.cfc, in the onRequestStart method, there was a <cfset ormreload()> .  I had put it there thinking that while I was doing some development it would be nice to have the ORM reloading all of time as I make changes.  However, it looks like it was interfering with the ORM's sequencing, and on Ajax page loads it was causing ColdFusion to erroneously report back that the ORM was not loaded.  I simply moved the ormReload to onApplicationStart, and the problem seems fixed.

Wednesday, March 03, 2010

KB927917

Over the last few months, I have been upgrading some of our websites' login systems. Today I updated the login system of old internal site that some users still use to update stuff. The login system that worked great on our newer web apps, wouldn't load the login screen on the old system. Here is the order of operations:

  • Main Page starts with style sheets, javascript & ajax library, starting body tag, etc.
  • Login Management Custom Tag occurs in middle of page, between begin and end body tags.
  • Login Management Custom Tag launches login cfwindow, navigates window to login form.
  • End of page winds things down, includes closing body tag.
Everything here works great in Firefox (of course), and on our newer Ajax-driven apps it works in IE. However, on this old, not-very-ajaxy website, IE 8 shows the cfwindow appears, and then breaks on the navigate saying: "HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917); Line: 0; Char: 0; Code: 0". Pretty mysterious.

So, lots of searching, and I found this helpful post:

http://blogs.msdn.com/ie/archive/2008/04/23/what-happened-to-operation-aborted.aspx

and additionally this helpful post:

http://social.msdn.microsoft.com/Forums/en/iewebdevelopment/thread/db34068c-5307-4ab7-be03-15b86c2604bb

So, I tried moving my custom tag to the end of the page, outside of the body tag, and that worked great. From what I can tell, the cfwindow, or maybe the ColdFusion.navigate was trying to add elements to the body of the page, before the body had closed.

Whether or not the reason provided above is exactly correct, it makes some sense. After all, our new, ajaxy websites launch the cfwindow from within a container (usually cfdiv), meaning that the main-page's body tag has closed before the cfwindow ever tries to load.

In any case, whether my diagnosis is right or wrong, the medicine worked. This one was a tricky one, so I thought that I would share it with the world.

Monday, November 02, 2009

cfwindow css bug workaround

Last week I posted about a bug I found in the ColdFusion 9 Ajax. In particular it referred to some display errors that were introduced by usage of cfwindow, cflayout-border, or (possibly) other Ajax containers. After a bit of head scratching and testing today, I have found a workaround. The workaround is kind of hackish, and doesn't work will with the CF rich text editor, but it is a start.

The Problem
Research and testing has shown that the problem was caused by the ext-all.css file. When you use or import cfwindow or cflayout-border on your page, ColdFusion automatically adds a few css and ajax files into your page's output HTML. One of these css files, ext-all.css, appears to be causing the problem.

If you open ext-all.css, you will find the following towards the very beginning of the file (emphasis and whitespace added for easier viewing):
html, body, div, dl, dt, dd, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, p, blockquote, th, td {margin:0; padding:0;}
This line appears to be causing the table padding problems.

Two lines farther down the file, you will find this:
address, caption, cite, code, dfn, em, strong, th, var {font-style:normal; font-weight:normal;}
This line appears to be causing text surrounded by <em> and <strong> tags to display as plain text.

The Workaround
The workaround is simple. In CSS, which ever style declaration comes last, wins. So, simply add the following to the bottom of your page:
<style>
strong { font-weight:bold; }
em { font-style:italic; }
em.strong {font-weight:bold;}
strong.em {font-style:italic;}
</style>
Line 1 is a style open tag.
Line 2 modifies the strong tag back to bold.
Line 3 modifies the em tag back to italics.
Line 6 closes the style tag.

So what are lines 4 and 5 for? Simple. Lines 2 and 3 of the workaround cause text to render bold or italics, but not both. So, Line 4 allows you to modify an em tag to be both italics and bold. Line 5 does the same in reverse.

A Simpler Workaround
Incidentally, you probably noticed that there is a simpler (though more extreme) workaround. You could just remove td, th, strong, and em from the offending lines of ext-all.css . If you are going to do this, however, you probably want to backup your copy of ext-all.css first; how this will affect the ajax controls and/or pages that use them is unknown.

Why Bother? Who cares? Why not just use inline styles? Who uses strong or em tags anymore anyway?
Good question. The answer is: Adobe, or, more importantly, their products. ColdFusion has the slick CKEditor (formerly called FCKEditor) built into it. CKEditor uses strong and em tags to modify text. This means that any content that you generate using the CKEditor (e.g. in a homegrown CMS), will be rendered plain text by ext-all.css. This is a problem.

Also, when coding with DreamWeaver, if you hit Ctrl-b for bold, or Ctrl-i for italics, DreamWeaver is going to insert em and strong tags to enforce the bold & italics. If ext-all.css renders that text plain, you now have a lot of pages on your site unexpectedly showing up with a lot of plain text, and unpadded table cells. This is an even bigger problem.

Please Vote
Workaround notwithstanding, if you think that this bug is as big of a problem as I do, please vote for Adobe to fix it here:

http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=80530

Also, you may like to vote to have Adobe fix a related bug here:

http://cfbugs.adobe.com/cfbugreport/flexbugui/cfbugtracker/main.html#bugId=80421

Thanks for your votes. I am looking forward to seeing Adobe fix this problem.

Friday, October 30, 2009

CF 9 Ajax breaks site CSS and formatting

Thesis
JavaScript/CSS includes for cfwindow, cflayout-border (and possibly others), kill some formatting elements, such as <strong> & <em> tags, and negatively affects table display such as padding / margins. This is a problem.

The details
Consider the following simple cfm page:

<p>Not Bold</p>
<p><em><strong>Bold and italics</strong></em></p>
Not unexpectedly, the above displays one line of plain text, and one line of formatted text. The above works in both CF8 and CF9, and looks something like this:
Not Bold
Bold and italics
Now we try importing the javascript & css for cfwindow. Consider the following small but important change:

<cfajaximport tags="cfwindow" />
<p>Not Bold</p><br>
<p><em><strong>Bold and italics</strong></em></p>


In the above, the formatting for the page breaks. All you get is plain text on both lines, something like this:
Not Bold
Bold and italics

The "strongs" and "ems" are completely ignored. Some testing has shown that this also happens when you import "cflayout-border". Worse, it also seems to goof-up table formatting and padding. Oh, and the same problem occurs when using the <cfwindow> tag directly, instead of just importing the cfwindow ajax and creating thru JavaScript.

Although I don't really use strong or em tags anymore, this will break a lot of legacy pages. Also, since the CKEditor included with ColdFusion uses <strong> and <em> tags instead of inline styles, any pages that use content generated by CKEditor will stop showing formatted text. This is a problem if you have implemented a homebrew CMS (as we have on a few pages).

I'll post a fix/workaround if I find one.

Notes
I am hesitant to post about this; last time I publicized what I thought was a bug in ColdFusion it turned out that I was just an idiot, and was doing something wrong (duh). So, on the one hand I hope that I am just an idiot (again), and that there is a simple workaround for this. Unfortunately I fear that I may have found a legitimate bug this time, and it complicates our plans (already in progress) to move to CF 9.

If this is a legitimate bug, I am surprised that something like this could have made it into final release code. It is easy to reproduce, and is immediately apparent in both FireFox and IE. I have read thru the CF 9 release notes, and performed an hour of two of testing, and haven't found any obvious workarounds. If you have an idea, please let me know. Otherwise, I think that we are going to have to look at waiting to upgrade to CF 9 for a little while. Bummer.

Wednesday, September 24, 2008

*Update to previous post* CF-Ajax gets jealous

This post modifies the following previous post:

Create Spry Data Sets Using Inline Data

It turns out that the above doesn't work inside of a bound CFDiv. For instance, if your Spry dataset lives on a pages called data.cfm, and you include data.cfm on another page using a bound cfdiv, it breaks. For the below example, you can put the guts of my previous post on this subject (referenced above) into data.cfm if you want. See the example below:

<----------- data.cfm ----------->
...
Create a spry dataset
...
Show dataset in a dynamic region
...
<----------- End data.cfm ----------->


<----------- view_data.cfm ----------->
...
<cfdiv bind="url:data.cfm" />
...
<----------- End view_data.cfm ----------->


I have spent almost two entire days trying to get the above to work. Interestingly, my research into the above with FireBug shows that I can get it to actually create and populate the dataset. However, try as I might, I can't get the dynamic region in view_data.cfm to show any data. I have researched on the web, and found others with the same finding; for example:

Spry + CFDIV = No Love

I love the CF Ajax goodness, but this is very frustrating and a major limitation. It makes it so that I can't use Spry (and possibly other Ajax frameworks) on big apps that include CF-Ajax (especially bound cfdivs). I work for a government agency, and we write some very large, powerful, complicated apps using ColdFusion. If the CF-Ajax makes it so that I can't extend the CF goodness with other Ajax frameworks, then this is a problem

I am hopeful that Adobe will address these sorts of CF-Ajax quirks in CF 9. If they don't, I will probably think twice in the future about using the CF Ajax features in the future.

Tuesday, September 23, 2008

Create Spry Data Sets Using Inline Data

I finally figured out how to create a Spry dataset using inline data. This is a major step towards usability, and wasn't posted on any of the Spry examples that I searched thru on Adobe's site.

To create a Spry dataset using inline data, you can just create a javascript array, and give the array to the dataset object using the Data Set's setDataFromArray(array) function. I have tested it in both FireFox and IE. You can find more information about the setDataFromArray(array) fuction here: http://labs.adobe.com/technologies/spry/articles/data_api/apis/dataset.html#setdatafromarray

The example below uses ColdFusion syntax to get data from the database and to populate the array. However, this would work with whichever language you like, or even with static data. See the following example:

Example:

<cfquery name="get_users" datasource="ds">
SELECT last_name, first_name, phone, address
FROM user

</cfquery>

<script type="text/javascript" src="Spry_1_6_1_022408/includes/SpryData.js"></script>

<script>

user_array = [<cfloop query="get_users">{last_name: "#get_users.last_name#", first_name: "#get_users.first_name#", phone: "#get_users.phone#", address:"#get_users.address#"}<cfif currentrow="" neq recordcount="">, </cfif></cfloop>]

user_dataset = new Spry.Data.DataSet();

user_dataset.setDataFromArray(user_array);
</script>

<div id="users_region" spry:region="user_dataset">

<table border="1">
<tr>
<th spry:sort="last_name">Name</th>
<th spry:sort="phone">phone</th>
<th spry:sort="address">Address</th>
</tr>
<tr spry:repeat="personnel_dataset">
<td>{last_name}, {first_name}</td>
<td>{phone}</td>
<td>{address}</td>
</tr>
</table>

</div>

You may have noticed that the above example doesn't var scope its JavaScript variables. This was on purpose, and it will still work. Experience has shown that var scoping variables can make them incompatible with some of the ColdFusion 8 CF-ajax stuff.

Thursday, May 01, 2008

ColdFusion Ajax Functions

Tired of looking up the syntax for the ColdFusion 8.0 Ajax functions? Me too. So, I created the following. You can thank me later.

https://acrobat.com/#d=0xInJpmQt0NgwOGzthNHuQ

Tuesday, January 15, 2008

Getting dates to appear correctly in an HTML cfgrid

A little while ago, I posted this to my blog, however I didn't give much context, I just dumped a pair of links to fairly dense articles. What do these links tell you? They tell you how to have SQL Server format things for you (in this case dates), similar to using the dateFormat function in ColdFusion. This can come in very handy when working with cfgrids.

Although the Adobe livedocs say that you can mask / format values that go into a grid, I haven't had much success with getting it to work; especially in the case of HTML grids.

A great work-around is just to use the SQL Server CONVERT function. How? If you plug a date/time/timestamp column name into CONVERT, and tell it what you want to convert it to, it will change the data-type of the date/time column (just in the resulting recordset, not in the actual table) to the data-type of your choice, and format the date for you to one of many predefined formats. Lots of examples of this and other techniques here:

http://www.oreilly.com/news/sqlnut_1200.html

For a list of predefined formats, and some more (not very useful) examples, look here:

http://msdn2.microsoft.com/en-us/library/ms187928.aspx

So, if you need to use a date/time column in a cfgrid, just preformat it in the actual query like so:

SELECT CONVERT(VARCHAR(11), date_column, 102) AS formatted_date
FROM table
...etc.

I hope that makes more sense.