I personally would not be so thrilled if all that GXT templates offer red was basic string interpolation. Luckily, we can also benefit from some level of conditional processing in the XTemplate
class making it possible to vary the rendering or formatting of the intended data depending on the state of things in the data itself.
A simple example of this would be to only show data for customers over a certain age; we can also modify this to use a different formatting style for customers of the requisite age.
Instantiate an XTemplate
object with a string representing the desired HTML formatting, and in it use the if
keyword enclosed in a <tpl>
tag to express the condition which will likely need to be escaped with slashes and HTML entities.
private String getTemplate(boolean all){ StringBuilder sb = new StringBuilder(); if(!all){ sb.append("<tpl if=\"age > 30\">"); }else{ sb.append("<tpl>"); } sb.append("<p>Age: {age}<...