View Full Version : XTemplate and null bean properties

8 May 2014, 10:32 AM
What's the right way to handle null bean properties in a GXT XTemplate?

Assume for example, I have a bean 'trucker' with some string properties, say 'remitToCity' and an XTemplate that looks like this:

"City: {remitToCity}"

I would have thought that if the 'remitToCity' bean property is null, I would just get "City: " as an output result. Instead, I get an exception in dev mode. Partial stack trace below:

Caused by: java.lang.NullPointerException: null
at com.google.gwt.safehtml.shared.SafeHtmlUtils.htmlEscape(SafeHtmlUtils.java:156)
at com.exworks.client.TruckerGrid_RemitToTemplate_remitToAddress_SafeHtml__TruckerDto_truckerDto___SafeHtmlTemplatesImpl.remitToAddress4(TruckerGrid_RemitToTemplateremitToAddress_SafeHtml__TruckerDto_truckerDto___SafeHtmlTemplatesImpl.java:39)
at com.exworks.client.TruckerGrid_RemitToTemplateImpl.remitToAddress(TruckerGrid_RemitToTemplateImpl.java:102)
at com.exworks.client.TruckerGrid$addressCell.render(TruckerGrid.java:61)
at com.exworks.client.TruckerGrid$addressCell.render(TruckerGrid.java:1)
at com.sencha.gxt.widget.core.client.grid.GridView.getRenderedValue(GridView.java:1765)

I thought maybe I could just check for null in the template, i.e.

"City: <tpl if="remitToCity == null">Not Available</tpl><tpl if="remitToCity != null">{remitToCity}</tpl>"
But that always prints "City: " , even when the property contains a non-null value.

I must be missing some obvious concept, but what?

19 Dec 2014, 3:50 AM
Hey, I have the same problem...

I use GXT 3.1...

Did you already solve it? Or is someone else able to help?
What is the correct syntax to handle possible null-values in a template?

25 Mar 2015, 9:02 AM
I have the same problem. Any feedback would be great ;)

23 Jun 2015, 9:17 AM
I encountered the same issue. Did you solve it?

10 Jul 2015, 2:04 PM
This should work, I'm investigating.

15 Jul 2015, 10:22 AM
Unfortunately it is not working. In that case, can you report a bug?

22 Jul 2015, 3:13 PM
Could you provide a test case that I could test locally? I wasn't able to replicate the issue. If I can replicate the issue, I we can fix it.

25 Jul 2015, 2:49 AM
You are missing the values attribute, Please try

"City: <tpl if="values.remitToCity == null">Not Available</tpl><tpl if="values.remitToCity != null">{remitToCity}</tpl>"

This used to work for me ;)