Wednesday, July 30, 2008

foreach to iterate over a map in 1.5

When you iterate over a map you need to usually get the key and the value, use this to get them both without having to use the key to get the value!

This also happens to not raise any unchecked warnings which you would have to @SuppressWarnings("unchecked")

Custom tags: passing in maps or other datatypes that arent strings

I needed to pass a hashmap into a custom tag. This hashmap was to be created on the jsp page using jstl, and then passed into the tag as an attribute.
For some reason i was not able to find the solution with just one google query.


1. first, to create a hashmap on the jsp using jstl and add some stuff to it:

2. next, add another attribute to your tag in the tld file:

3. finally, pass the hashmap into your tag .. <tag someName="${something}" /> and make sure that the setter in the tag takes in a Map

Tuesday, July 22, 2008

Intellij escapes strings on paste

I started using intellij, and coming from eclipse, some things are just wrong, or missing.
One thing that was driving me crazy was that when pasting strings that contain escaped literals, intellij would escape the escapes in the paste.
This string:
"something \" \t cool"
would become:
"something \\" \\t cool"
this was bad, especially for pasting around html tags with attributes.

some googling shows a long and old thread of people bitching about the same on the intellij forums:

Dont bother reading that thread though, there is no solution in it.

The solution is this:

This plugin unescapes your characters when you copy, so when you paste, intellij ends up escaping the characters and nothing breaks.