Wednesday, August 13, 2008

EL Map won't work with numerical index

Assume you're using JSTL in a JSP. You create a Map in the JSP's backing class (e.g. SimpleFormController in Spring):

Map map = new HashMap();
map.put(0,115);
map.put(1,226);

This map is provided to your JSP as a variable with the name exampleMap. You then attempt to access the map's values in the JSP:

${exampleMap[0]}
${exampleMap[1]}

It doesn't work. For an explanation, see this dialogue which does a phenomenal job of describing the reason.

Thursday, July 24, 2008

JavaScript == operator

Keep in mind that 0 == "" returns true in JavaScript. For a more detailed explanation (and a lover's lament) see Chipmunkan's blog post.

Tuesday, July 8, 2008

Dynamically altering a form's onsubmit event handler

Suppose you have a form and you wish to alter the form's onsubmit event handler on-the-fly...

For example, your form might consists of two radio buttons and a submit button. Depending on which radio button has been selected prior to the user's submitting the form, you want the onsubmit event handler to change.

This works in Firefox, but not IE:
form.setAttribute("onSubmit", "alert('hi'); return false;");

This works in both:
frm.onsubmit=test;
function test() {
alert('hi');
return false;
}

Wednesday, April 2, 2008

Inserting timestamp in Postgres

Here's an example of inserting a timestamp in Postgres:
insert into timeexample values ('2007-1-1'::timestamp)