Hi George,

In you code, there should only be 2 references to HibernateCategoryDao.
1. In AppModule
   binder.bind(CategoryDao.class, HibernateCategoryDao.class);
2. In the HibernateCategoryDao class itself

Every other class (page, value encoder, treeModelAdapter) should reference
CategoryDao
eg @Inject CategoryDao categoryDao

Interfaces are a contract and have no implementation details. It's much
better to code against interfaces and only be bound to the actual
implemtation at runtime for many reasons including:
1. In your unit tests, you could inject a MockCategoryDao and not require a
database
2. In the future, you may need to change the implementation to a
WebServiceCategoryDao (or something else) and all you need to change is
AppModule
3. Tapestry uses the IOC pattern (inversion of control) and actually
injects a wrapper around HibernateCategoryDao so the @Inject'ed bean is not
actually an instance of HibernateCategoryDao (it does delegate to it
though).
4. If you code to an interface, you can do all sorts fancy things with
proxies including the interceptor pattern

Some further reading
http://en.wikipedia.org/wiki/Inversion_of_control
http://en.wikipedia.org/wiki/Proxy_pattern
http://en.wikipedia.org/wiki/Interceptor_pattern

I've made a couple of mods to the code too:

       List<Category> cats =
session.createCriteria(Category.class).add(criterion).list();
       Map<Integer, CategoryNode> childNodes = new LinkedHashMap<Integer,
CategoryNode>();
       for (Category cat : cats) {
           CategoryNode childNode = new CategoryNode();
           childNode.setCategory(cat);
           childNodes.put(cat.getId(), childNode);
       }
       if (!childNodes.isEmpty()) { // if empty, the next query will fail

          Query query = session.createSQLQuery(
               "select c1.id, count(c2.id) "
               + "from CATEGORY c1 "
               + "left join CATEGORY c2 on c2.parent_id = c1.id "
               + "where c1.id in (:catIds) "
               + "group by c1.id");

          query.setParameterList("catIds", childNodes.keySet().toArray());
          List queryResult = query.list();

          for (Iterator<Object[]> it = query.iterate(); it.hasNext(); ) {
                  Object[] result = it.next();
                  Long childId = (Long) result[0];
                  Integer grandChildCount = (Integer) result[1];
                  CategoryNode childNode = childNodes.get(childId);
                  childNode.setHasChildren(grandChildCount != 0);
                  childNode.setLeaf(grandChildCount == 0);
          }
       }
       return new ArrayList<CategoryNode>(childNodes.values());

Cheers,
Lance

On 18 February 2012 02:55, George Christman <gchrist...@cardaddy.com> wrote:

> btw, I should mention the model exception only happens while trying to
> expand
> the tree node. It produces an ajax exception.
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Tapestry-TreeGrid-tp5462126p5494602.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
>
>

Reply via email to