the transient keyword private transient Menu rootMenu; @Override public void onInit() { super.onInit(); MenuFactory menuFactory = new MenuFactory(); rootMenu = menuFactory.getRootMenu(); addControl(rootMenu); } @Override public void onDestroy() { if (rootMenu != null) { removeControl(rootMenu); } super.onDestroy(); } }
Caching
Loading Menus using {@link #getRootMenu()} will automatically cache themenus for improved performance (technically the menus are only cached when Click is in
production or
profile mode).
If you want to manage Menu caching yourself, use one of the {@link #getRootMenu(boolean) getRootMenu} methods that accepts a booleancontrolling whether or not the menus are cached.
A common use case for caching menus yourself is when you need to customize the menus based on the logged in user. For this scenario you would load the Menus using {@link #getRootMenu(boolean) getRootMenu(false)}, customize the menus according to the user profile, and cache the menus in the HttpSession.
@see Menu