projectwonder/wonder — pull request #100 by lbane (2011-12-29 15:34:49+00:00)
Title: Use the right amount of closing tags in AjaxTree when showRoot is false

The AjaxTree generates a superfluous "

" pair at the end of the AjaxTree, when showRoot is false.

When the showRoot option for an AjaxTree is set to "false", the first level after the root node is displayed as the root list of the tree. The root node itself has still the internal level 0, while the first level after root has level 1. When closing the last level, a "closeCount" number is calculated, as the difference between the last displayed level and the root level.

Example:

DEBUG er.ajax.AjaxTree - AjaxTree item at level 0 with close count 0: com.cx.minikiswrapper.TreeModelCodeDelegate$RootCodeTreeNode@74d4db38
DEBUG er.ajax.AjaxTree - AjaxTree item at level 1 with close count 0: N41.0 - Akute Prostatitis
DEBUG er.ajax.AjaxTree - AjaxTree item at level 1 with close count 0: N41.1 - Chronische Prostatitis
DEBUG er.ajax.AjaxTree - AjaxTree item at level 0 with close count 1: null
DEBUG er.ajax.AjaxTree - AjaxTree item at level 0 with close count 0: com.cx.minikiswrapper.TreeModelCodeDelegate$RootCodeTreeNode@74d4db38

The first and last line come from AjaxTree.resetTree(). The culprit is line 4. It calculates the amount of close tags to generate at the end of the tree. When the root is displayed this is correct, but there is nothing to close, when it is hidden, as we are still displaying the first level.

A solution is to check for showRoot = false and then subtract one for the last closeCount.