!--a11y-->
Code Example of Key Binding 
As mentioned under Key Binding, you can use this binding concept only for data types that can provide a value set of key value pairs. This requires either the definition of a specific data type in the Java Directory or the extension of the data type String with metadata at runtime. We recommend to define new data types if the data type in the application is used frequently or the Web application is to be executed using the Java Dictionary.
The following source code is an example of key binding, the modification of the data type at runtime.
Value attribute "MonthName”, type=”String”.
//Get access to data type instance to be modified at runtime
|
ISimpleTypeModifiable myType=wdThis.wdGetAPI().getContext().getModifiableTypeOf("MonthName"); |
//Set valid values
for this data type
|
IModifiableSimpleValueSet values=myType.getSVServices().getModifiableValueSet(); values.put("0","January"); values.put("1","February"); values.put("2","March"); values.put("3","April"); values.put("4","May"); values.put("5","June"); values.put("6","July"); values.put("7","August"); values.put("8","September"); values.put("9","October"); values.put("10","November"); values.put("11","December");
wdContext.wdCurrentContextElement().setMonthName("10");
|
A UI element that allows key binding can be bound to this context by assigning the context path to a dropdown list box at design time or by dynamically binding the dropdown list box to the above mentioned example context at runtime. You can use the wdDoModifyView method in the controller implementation provided by Web Dynpro.
|
public static void wdDoModifyView(IPrivateMyView wdThis, IPrivateMyView.IContextNode wdContext, IWDView view, boolean firstTime) { //@@begin wdDoModifyView if (firstTime) { IWDDropDownByKey dropDownList =(IWDDropDownByKey) view.createElement(IWDDropDownByKey.class, “MyDropDownByKey”); dropDownList.bindSelectedKey(”MonthName”);
IWDTransparentContainer container=(IWDTransparentContainer) view.getElement(“RootUIElementContainer”); container.addChild(dropDownList);
//@@end }
|
