Menu

A menu is a tree of menu nodes. A menu node can be a label, hyperlink or ajax command. For example, create a menu bean and adding menu nodes:

	MenuViewConfig viewConfig = new MenuViewConfig(MenuStyle.TREE);
	MenuBean menuBean = new MenuBean(null, viewConfig);
	
	MenuNode rootMenuNode = new MenuNode(menuBean, "root", "root", true);
	menuBean.setRootMenuNode(rootMenuNode);

	MenuNode linkMenuNode = new MenuNode(menuBean, "Help", "Help", false, "/help/index.html");
	MenuNode commandMenuNode = new MenuNode(menuBean, "Edit", false, "Edit", RenderStyle.COMMAND_LINK);
	commandMenuNode.setImmediate(true);
	commandMenuNode.setIcon(MenuNode.UI_ICON_EDIT, false);
	rootMenuNode.addChild(linkMenuNode);
	rootMenuNode.addChild(commandMenuNode);
Menu style supports menu bar, tree, tiered menu, accordion tree, and list. A menu can be shown in a different style by changing menuStyle in its viewConifg:

	menuBean.getViewConfig().setMenuStyle(MenuStyle.MENU_BAR);

Action Handler

Menu nodes of a menu bean can be created by different MenuNodeFactory(s) and can have different action handlers.

	MenuNodeActionHandler actionHandler = ...;
	menuNode.setActionHandler(actionHandler);
At least, an Action Handler needs to implement
	
  public PageNavigation clickMenuNode(MenuNode menuNode) throws SystemException;
If a menu node needs to open a dialog for input data as the argument to the action, its action handler needs to implement

  public void createDialogContent(DialogBean dialogBean, MenuNode menuNode) throws SystemException;

Menu Node Input Data

A menu node can have an input data bean that is an EntityBackingBean. and it will be rendered before the menu node. User can input data as command arguments before the action is being executed.

Add properties to input data bean:


	MenuNode menuNode = new MenuNode(...);
	PartialBehaviorSupport partialBehaviorSupport = new PartialBehaviorSupport(new PartialBehavior(PartialBehavior.EVENT_CHANGE, new VisitUIComponent(VisitTarget.THIS))); 
	menuNode.addInputDataProperty("type", 
			EntityProperty.class, 1, partialBehaviorSupport,
			new RenderStyle(RenderStyle.SELECT_ONE_MENU), true);
To support property ajax behavior of input data bean, the menu node action handler needs to implement

	public <M> extends PersistenceEntity> PageNavigation handlePartialBehaviorEvent(PartialBehaviorEvent event, MenuNode menuNode, 
			EntityBackingBean<M> inputDataBackingBean, EntityProperty<M> property) throws SystemException;

Ajax Behavior

see Object-oriented Ajax.

DOM Event

Menu nodes support dom events. Dom event handlers are javascipts that are executed in client side.

	MenuNode menuNode = new MenuNode(...);
	DomEventSupport domEventSupport = menuNode.getDomEventSupport(true);
	domEventSupport.addEventHandler(DomEventSupport.EVENT_CLICK, "alert('clicked')");		
If the DOM event handler is dynamic, for example, it is different from entity to entity in the entity list view:

	MenuNode menuNode = new MenuNode(...);
	DomEventSupport domEventSupport = menuNode.getDomEventSupport(true);
	domEventSupport.setDynamic(DomEventSupport.EVENT_CLICK, true);		
Then the menu node action handler needs to implement:

	public String getDomEventDynamicHandler(MenuNode menuNode, String event) throws SystemException;