Skip to content
Advertisement

ComponentHierarchyIterator alternative in Apache Wicket 9.2 version

I got stuck while doing migration of Apache Wicket 7.9 to 9.2 version.

In 7.9 version, there is visitChildren (link) method which returns ComponentHierarchyIterator (link) based on clazz parameter. Both ComponentHierarchyIterator and the visitChildren method are deprecated in 7.9 and removed in latest versions.

The documentation says to use Use {@link org.apache.wicket.util.visit.IVisitor} instead of ComponentHierarchyIterator. However, IVisitor is an interface and I was not able to find an implementation of visitor which returns all the components hierarchy or fulfils the requirement.

There is one DeepChildFirstVisitor abstract class which is an implementation of IVisitor which I’m trying to use.

My 7.9 version codebase is :

       for (Component m : pushMenuContainer.visitChildren(PushMenu.class)) {
            if (!menu.equals(m)) {
                ((PushMenu) m).hide();
            }
        }

My 9.2 codebase after migration will be something like

       for (Component m : pushMenuContainer.visitChildren(PushMenu.class, new IVisitorUnknownImplementation())) {
            if (!menu.equals(m)) {
                ((PushMenu) m).hide();
            }
        }

I need guidance as to which visitor I should use, if it’s available in Apache Wicket 9.2 as an alternative to ComponentHierarchyIterator?

Also, if there is none available, then does it mean that I have to implement my own Hierarchy visitor?

Advertisement

Answer

You can use an anonymous implementation of IVisitor:

pushMenuContainer.visitChildren(PushMenu.class, new IVisitor<PushMenu, Void>() {
      @Override public void component(PushMenu pushMenu, IVisit<Void> visit) {
          if (!menu.equals(pushMenu)) {
              pushMenu.hide();
          }
      }
});
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement