All posts tagged 'development'

iBatis and DB2 INSERT statements

iBatis for Java is a good way of abstracting away the SQL statements from the business logic; it relies on XML files which contain all SQL statements and it is pretty simple to access a database. Because accessing DB2 from Java is pretty new for me I had some troubles finding a sample to setup a “insert” statement which returns the last inserted ID.
With PHP I’d use my_insert_id(), but how does it work with Java and DB2? Unfortunately all samples I could find where either based on Oracle or on the Microsoft SQL Server…. no luck.

So here is the XML required for an INSERT statement with iBatis on DB2:

<insert id=”insertTABLE” parameterclass=”TABLE”>
INSERT INTO TABLE
(…)
VALUES
(#…#)
<selectkey resultclass=”int” keyproperty=”id”>
SELECT IDENTITY_VAL_LOCAL() as ID FROM SYSIBM.SYSDUMMY1
</selectkey>
</insert>

After that the insert statement can be used like follows:

TABLE_BEAN table_bean = new table_bean();
table_bean.setXXX(…);
mySqlMapClient.insert(“insertTABLE”, table_bean);
// now table_bean.getId() returns the correct id

From now on iBatis works like a charm and the object value is automatically updated… nice!

IE and script loading via Ajax

Today I stumbled across a very strange IE issue. Again. Basically the code that was working fine in all real browsers – the code loaded some HTML fragment containing script tags using AJAX and added it to the page. Nothing complicated, except that those script tags require some special handling in Internet Explorer, as they do not execute automatically when being added to the page:

if(IE) {
var scripttags = NewlyAddedDomViaAjax.getElementsByTagName(“SCRIPT”);
var head = document.getElementsByTagName(“head”)[0];
for(var i=0, j=scripttags.length; i < j; i++)
{
var scripttag = document.createElement(“SCRIPT”);
scripttag.src = scripttags[i].src;
head.appendChild(scripttag);

}
}

No big magic and works fine. Except for the case that the script tag comes as first element in the newly inserted HTML code. In this case the getElementsByTagName is *not* returning the script node at all – it just returns an empty result set. This means that the JavaScript code is not executed in IE….

Luckily this problem is quite easy to solve – just move some other HTML code in front of the HTML snippet that is returned via AJAX – place all the script tags at its end and everything will work fine!

btw, how about Google? Not of great help, the closest I could find was this unanswered forum post.

(Image from Flickr)

A-void(0) javascript:void(0)

Today seems to be the day of IE6 bugs… the rather old “comma-bug” caused some troubles in one app and another one did not work properly in IE6. The following code was involved:

<a href=”javascript:void(0)” onclick=”someFunc()”>my link</a>

The someFunc() dynamically loaded a new script file – which worked fine in all browsers except for Internet Explorer 6 – the file was never loaded. Reason for this is that javascript:void(0) terminates all loading, including newly added &ltscript> tags or XHR requests.

Solving this is quite simple – the default handler of the link must never be executed:

<a href=”javascript:void(0)” onclick=”someFunc(); return false;“>my link</a>

But because there are more issues around the javascript: pseudo protocol I highly recommend not using javascript:void(0) at all. Instead use the following code:

<a href=”#” onclick=”someFunc(); return false;“>my link</a>

In the worst case the default handler is executed, which means the site goes to an empty anchor… in practice this means the “#” is appended to the URL, that’s it. No scary JavaScript function involved, that only breaks IE6. And shorter to type too.

More information: here and here.

Display Dojo tooltips based on the title tag

Recently I had to add nice tooltips to a larger Web application that is based on the Dojo framework. I thought “nothing easier that that”, as with jQuery I can do stuff like

with some (optional) parameters and that’s it. Unfortunately I had to learn from the various sources and samples that this simple feature is not supported out of the box by Dojo. There is a way of creating tooltips on the fly but there does not seem to be a ready-to-use solution which uses the title tag of the elements and shows a tooltip based on that.

So here is the code I came up with to display Dojo tooltips based on the title tag:

The code selects all elements with the class “withTooltip” and creates a Tooltip dijit for each of the found elements. It is important to notice that an ID is being added in case there is none – dijit.Tooltip requires an id and does not seem to work with classes or just an element being specified.

SVN AuthzSVNAccessFile woes

Setting up AuthzSVNAccessFile support for Subversion (SVN) should not be that hard, right? Plenty of documentation exists… but there is one pitfall – if you define access for certain repository directories make sure the path does not contain a trailing slash!

If you don’t you will see this error message:

Sending folder/design/readme.txt
svn: Commit failed (details follow):
svn: Server sent unexpected return value (403 Forbidden) in response to CHECKOUT request for ‘/myrepos/!svn/ver/501/trunk/folder/design/readme.txt’
svn: Your commit message was left in a temporary file:
svn: ‘/tmp/trunk/svn-commit.2.tmp’

Here is a simple AuthzSVNAccessFile sample file showing the issue:

[groups]
developers = mike, peter
designers = marc

[/]
@developers = rw
* = r

# This will not work!
[myrepos:/trunk/folder/design/]
@designers = rw

# Just leave out the trailing slash!
[myrepos:/trunk/folder/design]
@designers = rw

But it’s always just a comma, right?

Expected identifier, string or number

A very interesting but kept me busy now for quite some time, the following code does not work in IE:

var list = ["a", "b", "c", ];

As the code has been way more complex it was a bit harder to find the extra comma at the end and interestingly I already read about this a while ago… shame on me!

Nevertheless the error message is scary and useless:

IE6, please leave now!

Un-Happy Foto Designer für den Mac

Happy Foto ist ein qualitativ sehr guter Anbieter von Online-Ausarbeitungen welcher (als Ausnahme am Markt!) auch eine Mac-Version seiner Software anbietet. An sich wirklich sehr löblich nicht nur auf Windows-User zu schauen. Leider lässt sich diese Software auf meinem System aber nicht starten – in /var/log/system.log wird nur folgendes ausgegeben:

2008-10-21 10:28:01.810 HappyFoto-Designer 1.0[12134:10b] -DCI_USE_SETCURRENTCONTEXT_NIL=0
2008-10-21 10:28:01.811 HappyFoto-Designer 1.0[12134:10b] -DCI_WORKAROUND_CICONTEXT_MAPTABLE=1
2008-10-21 10:28:01.811 HappyFoto-Designer 1.0[12134:10b] -DCI_WORKAROUND_CICONTEXT_MAPTABLE_VIA_CG=0
2008-10-21 10:28:01.812 HappyFoto-Designer 1.0[12134:10b] -DCI_FORCE_SOFTWARE_RENDERER=0
2008-10-21 10:28:01.812 HappyFoto-Designer 1.0[12134:10b] -DCI_FORCE_SOFTWARE_RENDERER_VIA_ENV=0
2008-10-21 10:28:01.872 HappyFoto-Designer 1.0[12134:10b] Unable to load nib file: MainMenu, exiting

Sehr lästig, das Programm-Icon verschwindet nach rund 2 Sekunden wieder. Das wars. Keine Fehlermeldung für unerfahrene Benutzer. Grund ist laut Hotline die “ungewöhnliche” Spracheinstellung meines Systems – Englisch. Nun ja, ich verstehe ja, dass Happy Foto nicht alle Sprachen dieser Erde unterstützt, aber das Programm sollte zumindest in der Standardsprache Deutsch starten, falls keine Lokalisierung verfügbar ist.

Der Helpdesk konnte nicht weiterhelfen – “Umstellen auf Deutsch” ist aber nicht wirklich eine Option für mich. Hier also die Lösung für alle die den Terminal starten und bedienen können:

cd HappyFoto-Designer 1.0.app/Contents/Resources
cp -R German.lproj/ English.lproj

Das legt eine Kopie der deutschen Sprachdateien an und fortan startet der Happy Foto Designer für den Mac auch auf einem englischem System. Endlich ist der Happy, der Foto Designer!

Newer posts