HI,
I am very new to the Vaadin…i wanna use the Lazyquerycontainer because my database has a large data to load…
I saw the example of yours and on net i have implemented it but not able to run…
My classes are as follows…
public class SubEntityQueryFactory implements QueryFactory{
private EntityManager entityManager;
private QueryDefinition definition;
public SubEntityQueryFactory(EntityManager entityManager) {
super();
this.entityManager = entityManager;
}
public void setQueryDefinition(QueryDefinition definition) {
this.definition=definition;
}
public Query constructQuery(Object sortPropertyIds, boolean
sortStates) {
return new SubEntityQuery(entityManager,definition,sortPropertyIds,sortStates);
}
}
public class SubEntityQuery implements Query{
private EntityManager entityManager;
private QueryDefinition definition;
private String criteria=“”;
public SubEntityQuery(EntityManager entityManager, QueryDefinition definition,
Object sortPropertyIds, boolean
sortStates) {
super();
this.entityManager = entityManager;
this.definition = definition;
for(int i=0;i<sortPropertyIds.length;i++) {
if(i==0) {
criteria=" ORDER BY";
} else {
criteria+=“,”;
}
criteria+=" m.“+sortPropertyIds;
if(sortStates) {
criteria+=” ASC";
}
else {
criteria+=" DESC";
}
}
}
public Item constructItem() {
return new BeanItem(new SubEntity());
}
public int size() {
javax.persistence.Query query = entityManager.createNativeQuery(“SELECT count(GISubEntityID) from goinvestor…SubEntity as m”);
return ((Integer)query.getSingleResult()).intValue();
}
public List loadItems(int startIndex, int count) {
javax.persistence.Query query = entityManager.
createNativeQuery(“SELECT GISubEntityID,GIEntityID from SubEntity as m”+criteria,SubEntity.class);
query.setFirstResult(startIndex);
query.setMaxResults(count);
List subEntities = query.getResultList();
List items=new ArrayList();
for(SubEntity subEntity : subEntities) {
items.add(new BeanItem(subEntity));
}
return items;
}
public void saveItems(List addedItems, List modifiedItems,
List removedItems) {
throw new UnsupportedOperationException();
}
public boolean deleteAllItems() {
throw new UnsupportedOperationException();
}
}
@Entity
public class SubEntity implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
@Id
public int giSubEntityID;
public int giEntityID;
public int getgISubEntityID() {
return giSubEntityID;
}
public void setgISubEntityID(int giSubEntityID) {
this.giSubEntityID = giSubEntityID;
}
public int getgiEntityID() {
return giEntityID;
}
public void setgIEntityID(int giEntityID) {
this.giEntityID = giEntityID;
}
}
after this i am creating the lazy query container
LazyQueryContainer lqc = new LazyQueryContainer(new SubEntityQueryFactory(em),true,100);
lqc.addContainerProperty(LazyQueryView.PROPERTY_ID_ITEM_STATUS, QueryItemStatus.class,
QueryItemStatus.None, true, false);
lqc.addContainerProperty(“GISubEntityID”,Integer.class, null, true, true);
lqc.addContainerProperty(“GIEntityID”,Integer.class, null, true, true);
lqc.addContainerProperty(LazyQueryView.DEBUG_PROPERTY_ID_QUERY_INDEX, Integer.class, 0, true, false);
lqc.addContainerProperty(LazyQueryView.DEBUG_PROPERTY_ID_BATCH_INDEX, Integer.class, 0, true, false);
lqc.addContainerProperty(LazyQueryView.DEBUG_PROPERTY_ID_BATCH_QUERY_TIME, Integer.class, 0, true,
false);
and giving it to the table…
final String T_SUB_ENTITY_TABLE_COL_HEADER ={“SubEntity id”,“Entity id”};
final String T_SUB_ENTITY_TABLE_VISIBLE_COLS ={“GISubEntityID”,“GIEntityID”,};
Table filterTable = new Table();
filterTable.setSizeFull();
filterTable.setImmediate(true);
filterTable.setSelectable(true);
filterTable.setColumnCollapsingAllowed(true);
filterTable.setColumnReorderingAllowed(true);
filterTable.setContainerDataSource(buildSubEntityLazyQueryContainer());
filterTable.setVisibleColumns(T_SUB_ENTITY_TABLE_VISIBLE_COLS);
filterTable.setColumnHeaders(T_SUB_ENTITY_TABLE_COL_HEADER);
After running this program i am getting the following error
java.lang.NullPointerException
at org.vaadin.addons.lazyquerycontainer.LazyQueryContainer.getContainerProperty(LazyQueryContainer.java:186)
at com.vaadin.ui.AbstractSelect.getContainerProperty(AbstractSelect.java:753)
at com.vaadin.ui.Table.getVisibleCellsNoCache(Table.java:1876)
at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1541)
at com.vaadin.ui.Table.attach(Table.java:3679)
Please give the proper solution i have done everything to correct it…