Tips and ticks from Thimo Jansen, a Web Developer specialized in XPages and Java

Thursday, January 17, 2013

Be careful feeding the ResponseWriter, use big bites

Earlier this week I got bitten by one of the consequences of writing JavaScript code in a Java environment. There are some things you need to be aware of and I for one was not.

In this case: the XPages run-time can't always determine what the type is of the JavaScript value you're feeding to a Java method. It can be problematic with single position values, either a string or a number. Is it a char, a String or an int?

For writer.write("g"); the engine does not know whether to call void write(char) or void write(String) on the Java side.

This is a general JavaScript to Java issue, as there is no JavaScript character type so we cannot be type-explicit on the SSJS calling side.

To pass in a single character to the writer class that you either:
a) find a non-ambiguous version of a write method and force that to be called,
b) declare the var as an explicit Java type and pass that in