Start of Content Area

Background documentation Context Attributes  Locate the document in its SAP Library structure

Context attributes save the actual data contents. Each attribute defined in the context exists at runtime only once for each node element. A context node contains the list of node elements, a node element is a structure, and a context attribute saves a value (or an object). Context attributes themselves cannot contain additional child elements.

It is easier to define context attributes than context nodes. Usually you only have to specify an attribute name and select the data type.

The following properties are based on the declaration of a context attribute:

·        name: Name of the context attribute. Context attributes should begin with a capital letter.

·        readOnly: This property defines whether or not UI elements that are bound to a context attribute can be edited correspondingly.

·        structureElement: Name of the field in the Java Dictionary structure to which the context nodes belonging to the context attribute is bound (structure binding). The property cannot be edited.  

·        type: The data type of a context attribute can either be defined in the Java Dictionary or using any Java class.

·        calculated: If the value true is assigned to this property, then the values of context attributes are not saved in the node elements, instead they are calculated as required by calling a defined controller method. The default value for the calculated property is false.

Data Types  

Context attributes can be typed differently. You can use either types in the Java Dictionary or any Java classes. The main difference between them is that the context attributes used for UI element data binding have to be typed using the Java Dictionary. This is due to the fact that the Java Dictionary fulfils special tasks, such as reading user data that is input or formatting data for display in interface elements. If context data should also be displayed in the user interface, then the context attributes have to have a Dictionary type.

This graphic is explained in the accompanying text

A context attribute that uses a Java class (outside the Java Dictionary) as a type cannot be used to for the data binding of a UI element. More detailed information is available under Typing Context Attributes for Data Binding

The Java Dictionary contains the following predefined data types:

·        Primitive data types: binary, boolean, date, decimal, double, float, integer, long, short, string, time and timestamp. These data types are displayed in a selection list when you define the type property of a context attribute:

This graphic is explained in the accompanying text 
The primitive data types are represented in the Java Dictionary by corresponding Java classes in the namespace com.sap.dictionary (Dictionary class types).

·        Simple data types: You can also use the simple data types provided by default by the Java Dictionary to type individual context attributes. These data types can be divided into the following categories:

¡        Namespace com.sap.dictionary.predefined.currency:  Contains the data types currency and currencyNormalized for displaying the ISO currency codes.

¡        Namespace com.sap.dictionary.predefined.objecttypes:  Contains data types for displaying the objects of the primitive data types boolean, double, float, integer, long and short. This type of typed context attributes save object instances instead of primitive values, as is the case with the primitive data types.

¡        Namespaces com.sap.ide.webdynpro.uielementdefinitions and com.sap.ide.webdynpro.uielementlibraries.*: Contain enumeration types that contain the values that are permitted for different UI element properties such as Visibility (visible, none, blank) or ButtonSize (small, standard). If such UI element properties are bound to context attributes, they have to be typed accordingly.

·        Simple data types in the local Dictionary: In addition to the default Dictionary types, application developers can also define new simple data types in the Web Dynpro project’s local Dictionary. 

Note

For further information, see Creating Data Types in the local Dictionary.

·        Simple data types in logical Dictionaries: When an adaptive RFC model is imported, all data types used in the model classes are stored in what is called the logical Dictionary. The simple data types contained in it can also be used to type context attributes. 

The predefined data types in Dictionary namespace com.sap.dictionary are represented by special Java classes that have the necessary validation and formatting properties. These special properties are required for binding data between UI and context attributes.

The predefined types, the built-in types and the corresponding classes and primitive data types in Java are connected as follows:

Dictionary class type

Built-in type

Java class, primitive data type

com.sap.dictionary.binary

binary

byte[] (primitive). This type cannot be bound by UI elements as there is no general option for formatting and parsing binary data.

com.sap.dictionary.boolean

boolean

boolean (primitive data type)

com.sap.dictionary.date

date

java.sql.Date

com.sap.dictionary.decimal

decimal

java.math.BigDecimal

com.sap.dictionarydouble.

double

double (primitive data type)

com.sap.dictionary.float

float

float (primitive data type)

com.sap.dictionary.integer

integer

integer (primitive data type)

com.sap.dictionary.long

long

long (primitive data type)

com.sap.dictionary.short

short

short (primitive data type)

com.sap.dictionary.string

string

java.lang.String

com.sap.dictionary.time

time

java.sql.Time

com.sap.dictionary.timestamp

timestamp

java.sql.Timestamp

Data Type Interfaces

The type information for a context attribute can be accessed at runtime using the IWDAttributeInfointerface in package com.sap.tc.webdynpro.progmodel.api. This interface is provided in turn by the IWDNodeInfo-interface of a context node:

IWDNodeInfo nodeInfo = wdContext.getNodeInfo();

IDataType type = nodeInfo.getAttribute("Color").getDataType();

The IDataType interface only knows the data type name and the Java class that is used to represent values.

The types contained in the table above in namespace com.sap.dictionary implement the ISimpleType interface at runtime. To check a context attribute data type, IWDAttributeInfoprovides method hasSimpleType(). If a context attribute is of type ISimpleType, then you can use method IWDAttributeInfo.getSimpleType() to access the corresponding simple type. Otherwise, this method throws an exception.

Interface ISimpleType has the following characteristics:

·        It supports IDs for input fields, quick infos and so on if such metadata was defined (getTextServices()).

·        It can return language-dependent value sets, that is, key text pairs (if they were defined using getSVServices()).

·        The IWDAttributeInfo interface can be used to create a special instance of the simple data type for an individual context attribute, and you can modify almost all of its properties at runtime.

·        You can perform a conversion in both directions between the language-dependent string display (that is displayed in the interface) and the object representation (format(Object)and parse(String)).

·        You can perform a conversion in both directions between the language-independent displays (toString(Object)and parse(String)).

 

 

End of Content Area