In my GWT application I have a javascript function wich require an array of array as argument. I get the data using RPC, so I get a List< List > from my database. I need this because I have to fill a kind of tree view. For example, I get this from my RPC call: {"A", "A1", "A2"}, {"B", "B1"}, and I have to pass this to my javascript function: [["A", "A1", "A2"], ["B", "B1"]]. In my interface I want to show:
A+
A1
A2
B+
B1
How can I pass it to my javascript function using JSNI?
If you can live without DevMode (because you use SuperDevMode for instance), Java arrays are the same as
JsArray*
in production mode, soString[][]
is the same asJsArray<JsArrayString>
.In DevMode, there's
JsArrayUtils
which can help (makes a copy in DevMode, returns as-is in production mode, with no overhead), but not for nested arrays (and actually not even for arrays of strings), so not in your case.If you need/want either lists rather than arrays, or DevMode support, then you'll have to copy the data into a
JsArray<JsArrayString>
.If you can use arrays but need DevMode support, you can use
GWT.isScript()
to make a specific code branch: make a copy into aJsArray<JsArrayString>
in DevMode, pass the array as-is in prod mode (that also means 2 JSNI methods, forJsArray<JsArrayString>
andString[][]
)