[stringtemplate-interest] difficulty using format and null options together

Mark Wharton contact at moonbase.com.au
Sun Mar 16 23:39:57 PDT 2008


Hello,

I'm having difficulty using format and null options together in generating an SQL statement with quoted values and NULL keyword. Here's a sample:

	String ts = "$values; format=\"quote\", null=\"NULL\", separator=\", \"$";
	StringTemplate t = new StringTemplate(ts);
	t.registerRenderer(String.class, new ValueRenderer());
	List values = new ArrayList();
	values.add("x");
	values.add("y");
	values.add(null);
	values.add("z");
	values.add(null);
	t.setAttribute("values", values);
	System.out.println("t: "+t.toString());

Actual Result...

	t: "x", "y", "NULL", "z", "NULL"

Desired Result...

	t: "x", "y", NULL, "z", NULL

It looks like the null option is applied before the format option and consequently the NULL becomes quoted because it is a string when the renderer processes it. I don't see how it is possible to have non quoted NULL in the output for null values in the list when the format option is also used in the same expression.

Thanks,

Mark

Mark Wharton
+ 8190 9834 2559
contact at moonbase.com.au



More information about the stringtemplate-interest mailing list