views:

269

answers:

1

I'm upgrading a GWT project from GWT 1.7.1 to currently newest version 2.0.3. It seems that new GWT broke String.split(String regex) method - I get the following error on the Javascript side:

this$static is undefined

This happens in this line of my .nocache.js file:

if (maxMatch == 0 && this$static.length > 0) {

...which happens to be a part of String split method equivalent in Javascript.

Is there a cure for this, apart from doing string splitting myself?

+2  A: 

A possible workaround is to write a JSNI method that wraps around the standard JavaScript split function, something like this (note: code not tested :))

public static final native String[] split(String string, String separator) /*-{
    return string.split(separator);
}-*/;

The closest thing on the GWT Issues list is Issue 3071, but I'd just stick with JSNI on this one (just like I stick with JSNI for regular expressions).

Igor Klimer
Thanks! This works, with minor correction that return argument must be String[] instead of JsArrayString.
Domchi
Heh, thanks for reporting back - I've corrected the code above. I guess JSNI is not that "stupid" (JsArray* classes are usually used with JavaScript Overlay Objects, so I thought that this would be the case here too).
Igor Klimer