This is DataProvider and ListPage.
All is fine where i work with only one entity.
My DAO returns data from table assotiated with this entity and another table.
How i can provide access to this data from my DataTable?
public class MyDomainDataProvider extends
SortableDataProvider<MyDomain> implements IFilterStateLocator {
DataSource dataSource = QueryFactory.getDataSource();
private final MyDomainDAOImpl dao = new MyDomainDAOImpl(dataSource);
private MyDomain filter = new MyDomain();
private String sql = new String();
public MyDomainDataProvider() throws QueryException {
// set default sort
setSort("id", true);
filter.setId(null);
}
public Iterator<? extends MyDomain> iterator(int first, int count) {
SortParam sp = getSort();
//String x = FilterCriterionFactory.getFilteredSQL(filter);
String tmp = filter.getName();
if (tmp != null) {
sql = "where name like '%" + tmp + "%'";
} else {
sql = "where name like '%'";
}
Integer tmp2 = filter.getId();
if (tmp2 != null) {
sql += " and id like '%" + tmp2 + "%'";
}
return (Iterator<? extends MyDomain>)
dao.getDataAsEntity(MyDomain.class, first, count, sp.getProperty(),
sp.isAscending(), "select * from mydomain " + sql).iterator();
}
public IModel<MyDomain> model(MyDomain my) {
return new Model<MyDomain>(my);
}
public int size() {
String tmp = filter.getName();
if (tmp != null) {
//sql = "where name like '%" + tmp + "%'";
} else {
//sql = "where name like '%'";
}
Integer tmp2 = filter.getId();
if (tmp2 != null) {
sql += " and id like '%" + tmp2 + "%'";
}
return dao.getResultSetFullSize(MyDomainDAOImpl.SELECT_ALL_SQL + sql);
}
public Object getFilterState() {
return filter;
}
public void setFilterState(Object state) {
filter = (MyDomain) state;
}
}
public MyListPage(PageParameters params) throws QueryException {
MyDataProvider provider = new MyDataProvider();
IColumn[] columns = new IColumn[]{
new PropertyColumn(new
Model<String>(getString("List.FieldName.Id")), "id", "id"),
new TextFilteredPropertyColumn(new
Model<String>(getString("List.FieldName.Name")), "name", "name"),
new TextFilteredPropertyColumn(new
Model<String>(getString("List.FieldName.Ip")), "ip", "ip"),
new TextFilteredPropertyColumn(new
Model<String>(getString("List.FieldName.Port")), "port", "port"),
new TextFilteredPropertyColumn(new
Model<String>(getString("List.FieldName.Description")), "description",
"description"),
new PropertyColumn(new
Model<String>(getString("List.FieldName.NodeId")), "nodeid"),
new FilteredAbstractColumn<Object>(new
Model<String>(getString("List.Actions"))) {
public Component getFilter(String componentId,
FilterForm form) {
return new GoAndClearFilter(componentId, form, new
ResourceModel("List.Filter"), new ResourceModel("List.Clear"));
}
public void populateItem(Item cellItem, String
componentId, IModel rowModel) {
cellItem.add(new UserActionsPanel(componentId, rowModel));
}
}
};
AjaxDataTable dataTable = new AjaxDataTable("table", columns,
provider, 2);
final FilterForm form = new FilterForm("filter-form", provider);
dataTable.addTopToolbar(new FilterToolbar(dataTable, form, provider));
form.add(dataTable);
add(form);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]