Tuesday, December 30, 2008

extjs + AIR installed in Vista SQLError 3122

I have built a small Extjs+AIR+SQLite project and installed it in the Vista system. I got the following error message when do create/Edit/delete.

SQLError: 'Error #3122', details:'', operation:'execute'

This Extjs AIR application makes use of the local database (SQLite) and I was unable to update/create/delete a record; I was repeatedly getting error 3122 during the save operation. After looking up the error description I finally figured out it was because the database file was read-only. And the installed file was in the Vista application directory. (Vista make this - it is not me, right? I think I already complain too much for IE - Vista is really good ??? / compare with IE - your know I did not have enough sleep past 2 days)

AIR applications have privileges to write to any location on the user's hard drive; however, developers are encouraged to use the app-storage:/ path for local storage related to their application. Files written to app-storage:/ from an application are located in a standard location depending on the user's operating system:
  • On Mac OS: the storage directory of an application is //Local Store/ where is the user's “preferences folder,” typically: /Users//Library/Preferences

  • On Windows: the storage directory of an application is \\Local Store\ where is the user's CSIDL_APPDATA “Special Folder,” typically: C:\Documents and Settings\\Application Data

  • On Linux: //Local Store/where is /home//.appdata

You can access the application storage directory via the air.File.applicationStorageDirectory property. You can access its contents using the resolvePath() method of the File class.

Do not installed AIR project under Vista/program file folder if you need touch SQLite DB file.

Hopefully anyone does not hit this stupid error like me.

Tuesday, December 23, 2008

Javascript file Concatenation and Compression

Currently there are several way to do this, you can see this one:

YUI Compressor
[http://www.julienlecomte.net/blog/2008/10/80/]

The YUI Compressor uses a slightly modified version of the parser used in the Rhino JavaScript engine.However, it is Java based tool and you need compile/run etc. Actually it is the best mini tool I found so far.

If you use Apatan/Eclipse, maybe you need think this one.

JSConcatenation
[http://www.rockstarapps.com/pmwiki/pmwiki.php?n=JsLex.JSConcatenation]

Using this tool, will make your easy to mini your file into any output as your like. Rockstarapps.com has an aptana 'feature' that you download via aptanas internal software update engine. It allows for many other things but I was only interested in the JS tools it offers.

It is very straight forward, select files in the resources pane or better yet select your script tags right in an HTML document and "right click--> rockstarapps -->concatenate javascript". It produces an xyz.all.js file (with comments), a xyz.all.min.js file (without comments, linebreaks and spaces) an xyz.all.ycomp.js file (minified and yui compressed), AND it even includes a xyz.all.ycomp.js.gz (Gzipped).

Monday, December 15, 2008

fileupload with Extjs + Grails issues

Recently when I played fileupload with extjs + grails, I have several issues and take a while to identified.

1: In extjs, you need set: fileUpload: true in your formPanel. This will send multipart POST to the server side.

var imagepath = new Ext.form.FileUploadField({
id: 'form-file',
emptyText: 'Select an image',
fieldLabel: 'Photo',
name: 'imagepath',
anchor: '90%',
buttonCfg: {
text: '',
iconCls: 'upload-icon'
}
});
var formPanel = new Ext.form.FormPanel({
id: 'formPanel',
fileUpload: true,
baseCls: 'x-plain',
labelWidth: 120,
url:posurl,
defaultType: 'textfield',
items: [name, imagepath, description]
});

2: You'd better download the latest bug-fixed build (1.0.5) if you see error:

[1884908] errors.GrailsExceptionResolver
java.lang.NullPointerException
at java.net.URLDecoder.decode(URLDecoder.java:119)

There's something fundamentally wrong about how Grails handles multipart POST requests right now (since rev. 7387), but it only happens on this setup:
  • a HTTP POST multipart request is sent to the server;
  • the next request is a GET (or maybe POST also) with query parameters (eg, a query string is present in the URL);
  • Jetty (or the container) binds this next requext to the same thread that the multipart POST was bound to.
Latest build @:
http://bamboo.ci.codehaus.org/download/GRAILS-GRAILS15/artifacts/build-1462/Distributions

This build fixed above issue - 3460 [http://jira.codehaus.org/browse/GRAILS-3640]. Grails-1.1-beta1 does not fix this issue.

3: Render

For fileupload, ExtJs's formpanel is expecting JSON reply, typical HTTP 200 response is not valid and you will get error on the client side Javascript. Therefore, you need to specify the JSON response as normal "text/html" instead of "application/json" type.