PDA

View Full Version : BeanModel XTemplate combination not working



sgolla
5 Aug 2009, 10:02 AM
I am using BeanModelTag instead of BaseModelData on my model object. When i follow the demo for XTemplate and implemented my panel, it is not showing up the data at run time. I debugged and saw the data is ofcourse getting into js object, and my property names seem to be correct, but i just can't get to see data in my output. Any help / clues on this is greatly appreciated. Below is my source code:



import com.extjs.gxt.ui.client.core.XTemplate;
import com.extjs.gxt.ui.client.data.BeanModel;
import com.extjs.gxt.ui.client.data.BeanModelFactory;
import com.extjs.gxt.ui.client.data.BeanModelLookup;
import com.extjs.gxt.ui.client.util.Util;
import com.google.gwt.core.client.JavaScriptObject;

import client.model.SearchFilter;
import client.model.Request;
import client.model.FieldValue;

/**
* @author sgolla
*
*/
public class SearchSummaryPanel extends ContentPanel {
public SearchSummaryPanel(Request searchRequest)
{
this.setWidth(600);
this.setBodyStyle("padding:5px;");
BeanModelFactory factory1 = BeanModelLookup.get().getFactory(SearchFilter.class);
BeanModel oSearchFilter = factory1.createModel(searchRequest.getFilter());
JavaScriptObject jsCommon = Util.getJsObject(oSearchFilter, 10);
XTemplate tpl = XTemplate.create(getCommonCriteriaTemplate());
this.addText(tpl.applyTemplate(jsCommon));
layout();
}

private native String getCommonCriteriaTemplate() /*-{
var html = [
"<div class='filtersLabel'>Filters</div>",
"<div><table width='100%' border='0' cellspacing='0' cellpadding='0' class='sort-table'>",
" <tr>",
" <th class='firstColBdr'>Field Name</th>",
" </tr>",
" <tpl for='filters'><tr><tpl>",
" <td class='firstColBdr'>{field}</td>",
" </tr></tpl></tpl>",
"</table>",
"</div>"
];
return html.join("");
}-*/;
}


Thank you
Sreekanth

sgolla
5 Aug 2009, 10:52 AM
I am able to resolve the problem. I corrected my template that looks like below:
May be if this can help someone out there. Notice double quotes, single quotes swapped. Also an extra nesting of tpl is removed and that helped.



private native String getCommonCriteriaTemplate() /*-{
var html = [
'<div class="filtersLabel">Filters</div>',
'<div><table width="100%" border="0" cellspacing="0" cellpadding="0" class="sort-table">',
' <tr>',
' <th class="firstColBdr">Field Name</th>',
' </tr>',
' <tpl for="filters"><tr>',
' <td class="firstColBdr">{field}</td>',
' </tr></tpl>',
'</table>',
'</div>'
];
return html.join('');
}-*/;