Professional Documents
Culture Documents
Overview
This sample application demonstrates the usage of Web Dynpro popup menus that come with SAP
NetWeaver 2004s.
You will learn how to add a popup menu to a Tray UI element, how to declare menu item events, and
how to disable or enable menu action items by programmatically disabling or enabling the associated
action objects within action event handlers.
The sample application also shows popup menus in table cell editors. To select the contained menu
items without changing the table’s lead selection, the special table selection mode ‘nw04Plus’
combined with parameter mapping is applied.
Besides the static definition of popup menus at design time, this tutorial demonstrates how to add
popup menus dynamically at runtime by modifying the view layout within the wdDoModifyView()
controller hook method.
Contents
1. Introduction
2. Creating Component and Context
3. Designing the View Layout using Popup Menus
4. Implementing Action Event Handlers
5. Applying the Table Selection Behavior ‘nw04Plus’
6. Dynamically Adding Popup Menus to the View Layout
7. Related Content
Keywords
Web Dynpro, Menu, Popup menu, IWDMenu, IWDMenuActionItem, IWDMenuCheckBox,
IWDMenuRadioButton, IWDMenuSeparator, Web Dynpro Table, dynamic programming, dynamic UI
modification, end user UI customizing, action, action object, parameter mapping, table selection
Behavior, compatibiltyMode
1. Introduction
Demo Application Sshowing Popup Menus
The application scenario will demonstrates the following popup menu functions:
...
The end user is able to customize the Web Dynpro view on the UI using popup menus in both trays
(product detail tray, product table tray):
1. Swap (move down or move down) the position of both trays on the UI
2. Delete one row in the table with a popup menu item of a product cell editor (Product ID column)
without implicitly changing the table’s lead selection.
3. Display product details with a popup menu item of a product cell editor (Product ID column)
without implicitly changing the table’s lead selection.
4. Hide the product table tray and show it again.
5. The popup menu of the product detail tray is dynamically added at runtime within the
wdDoModifyView() hook method of the view controller.
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 1
Web Dynpro Foundation For Java SAP NetWeaver 2004s
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 2
Web Dynpro Foundation For Java SAP NetWeaver 2004s
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 3
Web Dynpro Foundation For Java SAP NetWeaver 2004s
product = wdContext.createProductsElement();
product.setName("Product 2");
product.setPrice("849,00");
product.setProductId("PRD-4711");
product.setQuantity(12);
product.setDetails("Detailed description of product 2");
products.add(product);
product = wdContext.createProductsElement();
product.setName("Product 3");
product.setPrice("0,89");
product.setProductId("ZR-0124");
product.setQuantity(1000);
product.setDetails("Detailed description of product 3");
products.add(product);
product = wdContext.createProductsElement();
product.setName("Product 4");
product.setPrice("1,15");
product.setProductId("ZR-1454");
product.setQuantity(1000);
product.setDetails("Detailed description of product 4");
products.add(product);
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 4
Web Dynpro Foundation For Java SAP NetWeaver 2004s
The popup menu is used to group actions in a space-saving way. After a user action the menu is
opened according to the UI element to which it is assigned. A MenuBar and a popup menu consist of
the following elements:
• Submenus for hierarchical menu structures, defined as a menu.
• Different menu items which can be defined as the following UI elements: MenuActionItem,
MenuRadioButton, MenuCheckBox, MenuSeparator. The MenuSeparator element adds a
separator between two menu items and thus provides a structure to the menu items.
Please note that popup menus do not fulfill real context menu functions like populating
menus on demand or adapting them to the UI context in which they are opened.
To use a popup menu you have to select the UI element you want to use for a popup menu (e. g. tray)
and select Insert PopupMenu.
• In this demo application select the ProductTableTray Tray UI element an insert a PopupMenu
with id PopupMenuTableTray.
• Insert the following three menu items by selecting Insert Item.
• Bind the onAction event of the two MenuActionItem UI elements to new actions. Defining a new
action is done by pressing the utmost right button […] in the line onAction:
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 5
Web Dynpro Foundation For Java SAP NetWeaver 2004s
The text property of each menu action item must not be explicitly set as it is retrieved
from the associated action object at runtime. For this reason the texts must be defined on
action level (action texts) at design time.
For the definition of a popup menu in the table you have to select the TableCellEditor of the column
you want to provide with a popup menu.
• Select the context menu item ProductId_editor Æ Insert Menu to insert a menu with ID
MenuProductTable.
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 6
Web Dynpro Foundation For Java SAP NetWeaver 2004s
Such a behavior can be achieved by setting the table property compatibilityMode to nw04Plus in
combination with implementing a parameter mapping relation.
The parameter mapping relation must be implemented to transfer the event parameter nodeElement of
a MenuActionItem UI element to a corresponding parameter in the action event handler. With this
mechanism a reference to the clicked node element (product in table line) is automatically passed to
the action event handler by the Web Dynpro runtime. The lead selection no longer needs to be
implicitly changed or accessed for this purpose.
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 7
Web Dynpro Foundation For Java SAP NetWeaver 2004s
After this step the signature of the generated action event handler onActionDeleteProduct()
looks like this:
View Controller PopupMenuView.java - Component PopupMenuComp
//@@begin javadoc:onActionDeleteProduct(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionDeleteProduct(
com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent,
com.sap.tc.wd.samples.menus.wdp.IPrivatePopupMenuView.IProductsElement product )
{
//@@begin onActionDeleteProduct(ServerEvent)
...
//@@end
}
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 8
Web Dynpro Foundation For Java SAP NetWeaver 2004s
Please notice how the state (disabled or enabled) of the MenuActionItem UI element is
implicitly managed by disabling or enabling the action objects to which its onAction
event is bound. Based on the event-to-action binding mechanism the Web Dynpro
Runtime automatically renders a UI element as disabled in case its event is bound to a
disabled action object.
This implicit action-object-based disabling/enabling of menu items is not applied for the
UI elements MenuCheckBox and MenuRadioButton. They keep enabled for disabled
actions.
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 9
Web Dynpro Foundation For Java SAP NetWeaver 2004s
//@@begin javadoc:onActionShowProductDetails(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionShowProductDetails(
com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent,
com.sap.tc.wd.samples.menus.wdp.IPrivatePopupMenuView.IProductsElement
product)
{
//@@begin onActionShowProductDetails(ServerEvent)
wdContext.currentContextElement().setProductDetail(
"Details for " + product.getProductId() + ": " + product.getDetails());
//@@end
}
//@@begin javadoc:onActionHideProductTray(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionHideProductTray(
com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionHideProductTray(ServerEvent)
wdContext.currentUIStateElement().setProductTrayVisibility(WDVisibility.NONE);
wdThis.wdGetShowProductTrayAction().setEnabled(true);
wdContext.currentContextElement().setProductDetail("");
//@@end
}
//@@begin javadoc:onActionShowProductTray(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionShowProductTray(
com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionShowProductTray(ServerEvent)
wdContext.currentUIStateElement().setProductTrayVisibility(
WDVisibility.VISIBLE);
wdThis.wdGetShowProductTrayAction().setEnabled(false);
//@@end
}
//@@begin javadoc:onActionMoveUp(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionMoveUp(
com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionMoveUp(ServerEvent)
wdThis.wdGetMoveUpAction().setEnabled(false);
wdThis.wdGetMoveDownAction().setEnabled(true);
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 10
Web Dynpro Foundation For Java SAP NetWeaver 2004s
wdContext.currentUIStateElement().setDoSwapTrays(true);
//@@end
}
//@@begin javadoc:onActionMoveDown(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionMoveDown(
com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionMoveDown(ServerEvent)
wdThis.wdGetMoveUpAction().setEnabled(true);
wdThis.wdGetMoveDownAction().setEnabled(false);
wdContext.currentUIStateElement().setDoSwapTrays(true);
//@@end
}
RootUIElementContainer
2
swapChildren(1,2)
Within the action event handlers onActionMoveDown() and onActionMoveUp()we set the context
attribute UIState.DoSwapTrays to true.
Within the wdDoModifyView() hook method we can then access this context attribute in order to
swap the position of both Tray UI element containers. This can be done by calling the method
swapChildren(1,2) which is implemented by all UI element containers of type
IWDUIElementContainer. The RootContainerUIElement is of type IWDTransparentContainer
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 11
Web Dynpro Foundation For Java SAP NetWeaver 2004s
which extends the IWDUIElementContainer interface. The integer values 1 and 2 are based on the
fact, that the UI Element HeaderTextView as the first child of the RootContainerUIElement is at
position 0.
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 12
Web Dynpro Foundation For Java SAP NetWeaver 2004s
7. Related Content
• Ready-to-use popup menu sample application: 41TutWD_PopupMenus.zip.
• This Readme document (PDF 49 KB) describes how to import the sample application into your
NetWeaver Developer Studio.
• Web Dynpro UI Element Reference: MenuBar and PopupMenu
How to use Popup Menus in Web Dynpro Applications – SAP NetWeaver 2004s 13