Busted Mug

A blog that documents solutions to the most frustrating problems that occur during development in technologies such as Java, XML, AJAX, SQL, CSS and others that make me want to throw my coffee mug against the cube wall.

Thursday, November 30, 2006

Select Boxes - clear all options - except the last one

Update:I was a blithering idiot when I posted this. Read this post. If you're messing with dynamic select boxes here's a good reference. I ran into a problem. Apparently you can't remove the last option (makes sense - how can you have no options?). To make the select appear blank you end up doing something like this:
if (this.selectedDates.length == 0) document.getElementById(this.listName).options[0] = new Option("","");
It just inserts a blank option.

Select boxes and "Could not convert JavaScript argument" (NS_ERROR_XPC_BAD_CONVERT_JS)

While trying to add a dynamically generated option to a select box I ran into this error:
Error: uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: file:///C:/Documents%20and%20Settings/mmbmb/Desktop/calendar%20de3v/calendarDateInput.js :: PickDisplayDay :: line 148" data: no]
I was perplexed for some time until I did a little research and ran into this page on Quirksmode. The solution lies here:
 for(i=0;i<list.length;i+=2)
 {
  box2.options[i/2] = new Option(list[i],list[i+1]);
 }
I was trying to call the .add method of a select using text as an argument. This is non-standard (but I think works in IE). You have to instantiate an option object or else JS will error while trying to convert. Quirksmode is great btw.

Select boxes and "Could not convert JavaScript argument" (NS_ERROR_XPC_BAD_CONVERT_JS)

While trying to add a dynamically generated option to a select box I ran into this error:
Error: uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: file:///C:/Documents%20and%20Settings/mmbmb/Desktop/calendar%20de3v/calendarDateInput.js :: PickDisplayDay :: line 148" data: no]
I was perplexed for some time until I did a little research and ran into this page on Quirksmode. The solution lies here:
 for(i=0;i
I was trying to call the .add method of a select using text as an argument. This is non-standard (but I think works in IE). You have to instantiate an option object or else JS will error while trying to convert. Quirksmode is great btw.

Wednesday, November 29, 2006

JS Hex Color Picker

Oh how many million times have I needed a Color Picker? I can't count anymore. I usually end up googling for one but this one is nice and actually give you the hex in the format you'll use in JS or CSS which is nice.

CSS Date Selection

Dynamic Drive DHTML Scripts- Jason's Date Input Calendar is a great css-enabled date selector. No need to open a new window and fool with all that entails. This is nice and clean.

Tuesday, November 28, 2006

Foreach in Java

As a php to java convert (mandated by my employer) I always forget the java version of for each. Sun, of course, has a good for each reference and tutorial but it is a little long winded. to break it down:
    for (TimerTask t : c)
        t.cancel();
means "For each tasktimer in c, assign it to t and do .cancel." These make your code much more elegant. I use them whenever possible.

Comma separated lists in java

I find myself doing this for a user a million times and have taken until now to take care of the formatting somewhere else. If you need a list that has commas in between items, but of course doesn't have a trailing comma, something like this is handy:
 /**
  * bch: formats a comma-separated list
  * @param items string separated by spaces
  * @return list in format a, b, c
  */
 public static String commalist(String items) {
  StringTokenizer st = new StringTokenizer(items);
  StringBuffer sb = new StringBuffer();
  while (st.hasMoreElements()) {
   sb.append(st.nextToken());
     if (st.hasMoreElements()) {
    sb.append(", ");
   }
  }
  return sb.toString();
 }

gotAPI/search

I just can't get enough of gotAPI. It's an awesome developer tool that will allow you to specify the technologies that you're working on so that you're only searching those APIs. Too cool. It has a real web 2.0 feel to it too.

Obvious yet useful

Every programmer needs to have some of those completely obvious and simple functions taken care of in their toy box. Here's one that I programmed 1000x before realizing I should really code it once and be done: public static String nvlb(String source, String falseCase) { if (source == null || source.equals("")) return falseCase; else return source; } Put this as a static member of your class and you'll never need to code out replacing a null or blank string to throw into some sql again. It will eliminate some keystrokes, but ranks high on the DUH factor :)

Wednesday, November 22, 2006

Firefox, IE vulnerable to fake login pages? | CNET News.com

Firefox, IE vulnerable to fake login pages? | CNET News.com Very tricky. A testament to not saving your passwords. What will they think of next?

Busted Jar

In Websphere 5.1.2 I keep running into this issue with one of my external jars. It happens to be gnu.regexp but that's not really consequential I don't think. Anyhow, this jar keeps getting unincluded and the only way I can fix it is to go into Server Configuration>Environment and add it back in. It suckos :P If anyone know what can cause this I am all ears - this one might be my bad, I'm not sure.

Attack code targets zero-day Mac OS X flaw | CNET News.com

In other news Pigs have grown wings and started to fly - Attack code targets zero-day Mac OS X flaw | CNET News.com When you claim to be so secure that anti-virus software doesn't exist it is going to be pretty tough to deal with an outbreak of this. It's a good thing no one is actually using Macs anywhere, lol.

Tuesday, November 21, 2006

Bill O'Reilly: Tech helps the terrorists win | News.blog | CNET News.com

Oh gosh: Bill O'Reilly: Tech helps the terrorists win | News.blog | CNET News.com. In the course of this babbling O'Reilly, the oft ranting commentator on Fox News said ""I really fear for the United States because, believe me, the jihadists? They're not playing the video games. They're killing real people over there." Take a gander at the CNet article to get the whole gist, but basically he's insane. Apparently he'd rather have America's teenagers doing something productive via killing real people? Or perhaps he didn't mean to say that and it was just Freudian. In any case someone please buy him a clue.

Oracle's stupid column indexes

Oracle has really dumb column indexes. Instead of starting with 0 like the rest of the computer science world, they chose to go with 1 as the first. Thus, even the most seasoned programmer will often fall for this rookie mistake because programmers know that in CS 0 is first. Consequently, you'll get a ORA-17003: Invalid column index error and usually it's pretty easy to spot. None the less this is extremely annoying. I wish Oracle would fix it.

Monday, November 20, 2006

java.lang.IllegalAccessError

The java.lang.IllegalAccessError is one of those stupid litte "Duh" kind of errors. This little nasty came along, apparently, because I needed a method to be public instead of private. This it tough to get. You have to have an interface class that has a public member that calls a private method. The compiler should pick them out but in my case didn't do the job until after I was muttering "WTF" and bashing my keyboard.

The ? : operator in Java

The ? : operator in Java These are great but seldom used. I recommend it. I.E. output = obj.getShowA() ? a: "Not showing a"; It simplifies the multiline structure. Fun.

Saturday, November 18, 2006

First Post

This is the first post. I'll probably delete it later. Oh yeah, boobies!