Hi Lance, getting back to the tree grid again. I want to say thanks for all your help thus far. I believe I'm getting much closer. Would you mind reviewing what I have thus far and comment? As you indicated the query string in the getChildren method will need to be repaired and I'll need to setup the join in the category table. I still have to fix the value encoder as well.
Category entity. public class Category implements Serializable { @Id private String categoryId; private String label; private String parentCategoryId; getters/setters Category Node public class CategoryNode { private Category category; private boolean leaf; private boolean children; getters/setters CategoryTreeModelAdapter public class CategoryTreeModelAdapter implements TreeModelAdapter<CategoryNode> { private Session session; public CategoryTreeModelAdapter(Session session) { this.session = session; } public boolean isLeaf(CategoryNode node) { return node.isLeaf(); // since this was determined in a single query, //we have avoided the n + 1 selects problem } public boolean hasChildren(CategoryNode node) { return node.hasChildren(); // since this was determined in a single query, //we have avoided the n + 1 selects problem } public List<CategoryNode> getChildren(CategoryNode node) { List<Category> categories = session.createCriteria(Category.class).add(Restrictions.eq("parentCategoryId", node.getCategory().getCategoryId())).list(); Map<String, CategoryNode> nodes = new HashMap(); for (Category category : categories) { CategoryNode newNode = new CategoryNode(); newNode.setCategory(category); nodes.put(category.getCategoryId(), newNode); } // for each of node's children, count the number of children (ie node's grandchildren) // my hibernate is a bit rusty so this might need to be tweaked List<Object[]> results = session.createSQLQuery( "select c1.categoryId, count(c2.*) from Category c1 " + "join Category c2 on c2.parentId = c1.categoryId " + "where c1.parentId = ? " + "group by c1.categoryId", node.getCategory().getCategoryId()).list(); for (Object[] result : results) { String childId = (String) result[0]; int grandChildCount = (Integer) result[1]; CategoryNode childNode = nodes.get(childId); childNode.setLeaf(grandChildCount == 0); childNode.setChildren(grandChildCount != 0); } return new ArrayList(nodes.values()); } public String getLabel(CategoryNode node) { return node.getCategory().getLabel(); } } Tree Page. public class Tree { private TreeModel<Category> treeModel; @Inject private Session session; public TreeModel<Category> getStuffModel() { if (treeModel == null) { ValueEncoder<Category> treeEncoder = new ValueEncoder<Category>() { @Override public String toClient(Category category) { return category.getCategoryId(); } @Override public Category toValue(String uuid) { return Category.ROOT.searchSubTree(uuid); } }; treeModel = new DefaultTreeModel<Category>(treeEncoder, new CategoryTreeModelAdapter(session), Stuff.ROOT.children); } return treeModel; } } Thanks Lance. -- View this message in context: http://tapestry.1045711.n5.nabble.com/Tapestry-TreeGrid-tp5462126p5482910.html Sent from the Tapestry - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org