You can add actions to the admin studio dynamically, that is, after your work unit starts to run.
For example, a work unit for editing a page may enable the administrator to select iViews to add to the page. The work unit can add an action to the Portal Catalog called Add iView to Page for all iViews, which triggers a Web Dynpro action that adds the iView to the page.
...
1. Create and map the following context attributes
a. Component Controller:
■ IActionNodeList (java.util.List): List of dynamic actions
b. Tab View:
■ IActionNodeList (java.util.List): List of dynamic actions. Map this attribute to the IActionNodeListattribute in the component controller.
2. Create the Web Dynpro actions that will be triggered when the administrator selects admin studio actions.
For each Web Dynpro action, add a parameter called eventData of type com.sap.portal.service.EventData to get information about the portal object for which action was triggered.
You can get the following strings by calling the eventData.getString() method:
Key |
Value |
ResourceID |
The ID of the object selected. |
DisplayName |
The name of the object selected |
IsWebdynproObject |
Indicates that the selected portal object is Web Dynpro based. |
3. In the wdDoInit() method of the work unit view, add code that specifies the admin studio actions to add and the Web Dynpro actions to be triggered when each admin studio action is selected.
The following is a sample:
//Create an (executable) action, specifying the ID, display name
// and Web Dynpro action to be triggered.
ExecutableActionNode action1 = newExecutableActionNode("action1ID", null,
new WebDynproActionMetaData("action1ID", "Dynamic Action1
Title",wdThis.wdGetCallMeActionAction()));
//Add the dynamic actions for this work unit to a List
List<IActionNode> actionList = new ArrayList<IActionNode>();
actionList.add(action1);
//Save the List to the context
wdContext.currentContextElement().setIActionNodeList(actionList);
See Action Filters and Submenus below for more options when creating actions.
4. In the component controller's getActions() method, get the List of actions in the context and return it as an array, as follows:
List<IActionNode> actions = wdContext.currentContextElement()
.getIActionNodeList();
returnactions.toArray(newIActionNode[actions.size()]);
To set the actions while the work unit runs and not just at startup of the work unit, call setActions(), as follows:
List <IActionNode> actions = wdContext.currentContextElement()
.getIActionNodeList();
wdThis.wdGetIWUFrameworkInterface().setActions(
actions.toArray(newIActionNode[actions.size()]));
To set the actions, you must declare the IWUFramework component interface controller as a required controller of the view.
You can create an action filter so that your action only appears for a subset of portal objects based on:
● Object type
● Permissions
The following creates a filter so that an action is only displayed for iViews for which the current administrator has write permission, and then applies it to an action:
//Create an action filter
ActionFilteringData actionFilter = newActionFilteringData();
actionFilter.addValue(IActionConfig.ATTR_REQUIRED_OBJECT_CLASSES,
"com.sapportals.portal.iview");
addIviewToPageFilter.addValue(IActionConfig.ATTR_REQUIRED_CAPABILITIES,
"com.sapportals.portal.iview");
actionFilter.addValue(IActionConfig.ATTR_REQUIRED_PERMISSIONS,
"admin_read_write");
//Create an (executable) action, specifying the ID, display name,
// Web Dynpro action to be triggered, and the action filter.
ExecutableActionNode action1 = newExecutableActionNode("action1ID", null,
new WebDynproActionMetaData("action1ID", "Dynamic Action1 Title",
wdThis.wdGetCallMeActionAction()),actionFilter);
//Add the dynamic actions for this work unit to a List
List<IActionNode> actionList = newArrayList<IActionNode>();
actionList.add(action1);
//Save the List to the context
wdContext.currentContextElement().setIActionNodeList(actionList);
You can create a tree structure by creating folder action nodes, and then adding executable actions under the folder action nodes.
The following creates an action called action1, and places it in a folder action node called myActions:
//Create an (executable) action, specifying the ID, display name
// and Web Dynpro action to be triggered.
ExecutableActionNode action1 = newExecutableActionNode("action1", null,
new WebDynproActionMetaData("action1", "Dynamic Action1 Title",
wdThis.wdGetCallMeActionAction()));
//Create a folder action, specifying the ID and display name
FolderActionNode myActions = newFolderActionNode(
"MyActions",null,"My Actions");
//Add the executable action to the folder action
myActions.add(action1,null);
//Add only the folder action to a List
List<IActionNode> actionList = new ArrayList<IActionNode>();
actionList.add(myActions);
//Save the List to the context
wdContext.currentContextElement().setIActionNodeList(actionList);