Cmobilecom AF 5.19 Developer Guide

7.7 Menu

A menu is a tree of menu nodes. A menu node can be a label, hyperlink or command link/button. 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", RenderStyle.COMMAND_LINK);
	commandMenuNode.setImmediate(true);
	commandMenuNode.setIcon(MenuNode.UI_ICON_EDIT, false);
	rootMenuNode.addChild(linkMenuNode);
	rootMenuNode.addChild(commandMenuNode);
Menu style supports menu bar, tiered menu, tree and accordion tree. A menu can be shown in a different style by changing menuStyle in its viewConfig:

	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 changeTypeMenuNode = new MenuNode(menuBean, "ChangeType", RenderStyle.COMMAND_LINK);

	RenderStyle renderStyle = new RenderStyle(RenderStyle.SELECT_ONE_MENU);
	renderStyle.setSelectItems(selectItems);
	PartialBehaviorSupport partialBehaviorSupport = new PartialBehaviorSupport(new PartialBehavior(
			PartialBehavior.EVENT_CHANGE, new VisitUIComponent(VisitTarget.THIS)));
	changeTypeMenuNode.addInputDataProperty(Integer.class, "Type",
			1, partialBehaviorSupport, renderStyle, true);
To handle property partial 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;

Partial Behavior

see Partial Behavior.

DOM Event

Menu nodes support dom events for web. Dom event handlers are java scripts 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;
Context HelpView ConfigFrames / No Frames