for (Unit subUnit : parentUnit.getSubUnits()) {
List<Unit> subUnits = new ArrayList<Unit>(); subUnits.addAll(parentUnit.getSubUnits()); Collections.sort(subUnits, new BeanComparator("name"));  for (Unit subUnit : subUnits) {
    private void getUnitsList(Unit parentUnit, StringBuilder buffer) {                buffer.append("<li>");        if (parentUnit.hasAnySubUnits()) {            buffer.append("<img ").append("src='").append(getContextPath()).append(                    "/images/toggle_plus10.gif' id=\"").append(parentUnit.getIdInternal()).append("\" ")                    .append("indexed='true' onClick=\"").append("check(document.getElementById('")                    .append("aa").append(parentUnit.getIdInternal()).append(                            "'),document.getElementById('").append(parentUnit.getIdInternal()).append(                            "'));return false;").append("\"> ");        }        buffer.append("<a href=\"").append(getContextPath()).append(                "/facultyAdmOffice/functionsManagement/chooseFunction.faces?personID=").append(                personID).append("&unitID=").append(parentUnit.getIdInternal()).append("\">").append(                parentUnit.getName()).append("</a>").append("</li>");        if (parentUnit.hasAnySubUnits()) {            buffer.append("<ul class='mvert0' id=\"").append("aa").append(parentUnit.getIdInternal())                    .append("\" ").append("style='display:none'>\r\n");        }        for (Unit subUnit : parentUnit.getSubUnits()) {            if (subUnit.isActive(Calendar.getInstance().getTime())) {                getUnitsList(subUnit, buffer);            }        }        if (parentUnit.hasAnySubUnits()) {            buffer.append("</ul>");        }                  }