The template
class in the GXT toolkit provides a very simple mechanism for generating formatted HTML fragments from data objects which can be instances of ModelData
or Params
.
Once we apply the data to the Template
object, the result is the formatted HTML interpolated with values from the provided data.
Instantiate a Template
object with a string representing the desired HTML formatting and the placeholders. We will replace the Template
placeholders with values using a Params
object.
//Local convenience method private String getTemplate(){ StringBuilder sb = new StringBuilder(); sb.append("<p>Age: {age}</p>"); sb.append("<p>Sex: {gender}</p>"); sb.append("<p>Name: {name}</p>"); sb.append("<p>Email: {email}</p>"); sb.append("<p>Purchases: {purchases:number(\"00.00\")}</p>"); return sb.toString(); }; @Override public void onApply() { // Create a Template with the HTML from getTemplate...