Adding UI Elements
Programmatically
Web Dynpro enables you to statically declare objects at design time. This considerably reduces the programming effort. Dynamic UI Generation, however, enables you to develop programming sequences declared at design time and to develop source code that overwrites existing declarations. This could be for example configuration-driven parts of the user interface.
To create UI elements dynamically, the code has to be written into the wdDoModifyView method. The parameter firstTime specifies whether the wdDoModifyView method was called for the first time during the lifetime of the view.
1. Create a UI element with a given ID. If you don’t give an ID, an identifier is generated automatically. In this case, you may not change the sequence in which the UI elements are created to ensure the personalization.
2. Retrieve the container which the UI element should be inserted into. To get the RootUIElementContainer, use view.getRootElement().
3. Add the UI element to the container.
4. Bind the UI element property to the
context.
public static void
wdDoModifyView(IPrivate<view name> wdThis, IPrivate<view
name>.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView
view, boolean firstTime)
{
//@@begin wdDoModifyView
if(firstTime){
IWDButton theButton =
(IWDButton)view.createElement(IWDButton.class,
"myFirstButton");
IWDGroup theGroup = (IWDGroup)view.getElement("Group1");
theGroup.addChild(theButton);
theButton.bindText
("<ContextNodeName>.<ContextAttributeName>");
}
//@@end
}
5.
You can remove all UI
Elements, you have created programmatically using the following coding:
view.resetView();