Show TOC Start of Content Area

This graphic is explained in the accompanying textCode Example of Key Binding  Locate the document in its SAP Library structure

This binding concept can only be used for data types that can provide a value set to 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.

Example A

The following source code is an example of key binding, where the data type String is modified at runtime.

1. Defining the Context at Design Time (Creating a Context Attribute as a Root Node Attribute):

This graphic is explained in the accompanying text

Value-Attribut "MonthName”, type=”String”.

2. Initializing Node Elements Within the wdDolnit Method:

//Get access to runtime modifiable data type instance

ISimpleTypeModifiable myType=wdThis.wdGetAPI().getContext().getModifiableTypeOf("MonthName");

 

//Set allowed values for this data type

 

IModifiableSimpleValueSet values=myType.getSVServices().getModifiableSimpleValueSet();

   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.currentContextElement().setMonthName("10");

 

 

Caution

If you bind the selectedKey property of a radio button group to a context attribute that is not defined as a root node attribute, you must observe the cardinality of the associated context node when implementing the above source text (see example B).

3. Binding the Context Example to a Radio Button Group

You can bind a UI element that allows key binding to this context (in this case, the RadioButtonGroupByKey UI element) by assigning the context path to a radio button group at design time or by dynamically binding the radio button group to the above mentioned example context at runtime and generating it. You can use the wdDoModifyView method in the controller implementation provided by Web Dynpro.

Controller implementation for dynamic generation of a radio button group:

 

public static void wdDoModifyView(IPrivateMainView wdThis, IPrivateMainView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

  {

    //@@begin wdDoModifyView

 

      if (firstTime)

 

      {

        IWDRadioButtonGroupByKey radioButtonGroup =(IWDRadioButtonGroupByKey)

        view.createElement(IWDRadioButtonGroupByKey.class, "MyRadioButtonGroupByKey");

        radioButtonGroup.bindSelectedKey("MonthName");

        radioButtonGroup.setColCount(3);

        IWDTransparentContainer container=(IWDTransparentContainer)

        view.getElement("RootUIElementContainer");

        container.addChild(radioButtonGroup);

      } 

    //@@end

  }

Example B

1. Defining the Context at Design Time (Creating a Context Attribute as a Context Attribute of the NodeX Node):

This graphic is explained in the accompanying text

Value node NodeX

Value-Attribut "MonthName”, type=”String”.

2. Initializing Node Elements Within the wdDolnit Method:

If the cardinality of the NodeX node has been declared with O..n or O..1, there is no node element at runtime, therefore the system must generate a node element in the controller implementation.

//Get access to runtime modifiable data type instance

public void wdDoInit()

  {

      IPrivateMainView.INodeXElement newElement = wdContext.createNodeXElement();

      ISimpleTypeModifiable myType=wdThis.wdGetAPI().getContext().getModifiableTypeOf("NodeX.MonthName");

      IModifiableSimpleValueSet values=myType.getSVServices().getModifiableSimpleValueSet();

            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.nodeNodeX().addElement(newElement);

      wdContext.currentNodeXElement().setMonthName("0");

   wdContext.currentRadioButtonsElement().setMonthName("10");

   */

    //@@end

  }

If the cardinality of the NodeX node has been declared with 1..n or 1..1, a node element is present at runtime and you can use the controller implementation in example A, however, you must specify the exact path of the context attribute as a parameter of the getModifiableTypeOf method:

ISimpleTypeModifiable myType=wdThis.wdGetAPI().getContext().getModifiableTypeOf("NodeX.MonthName");

3. Binding the Context Example to a Radio Button Group

See example A

However, even in this case an exact description of the context attribute path is required:

radioButtonGroup.bindSelectedKey("NodeX.MonthName");

4. Result

In both cases, the user sees a radio button group over three columns with the names of the months:

This graphic is explained in the accompanying text

  

  

 

End of Content Area