cancel
Showing results for 
Search instead for 
Did you mean: 

Get the first allowed value of an enumeration type

Former Member
0 Kudos

Hi,

I have a model that has a context attribute of a custom type. This data type is an enumeration (e.g.: allowed values: "0", "1" or "2"). I've bound that attribute to a RadioButtonGroupByKey in order to have the interface automatically populated from the backend data type description.

The problem is that I want to show to the user the first value available selected (i.e. set the value of the attribute to "'0" in the doInit). Now, I could set the value manually because I know what are the allowed values and which of them "comes first" in the enumeration list.

I was wondering instead if there was a way to get the first allowed value from the data type description ("0"), in order to make the code totally agnostic about the data type and its structure (so it can be changed from the backend without changing the front end code, taking aside the model reimport).

Is it possible to have something like that:

String (or Object) firstAllowedValue = ...;

wdContext.current...Element.setAttributeX(firstAllowedValue);

Thank you,

Pietro

ps. This is just for the purpose of learning how things works with data types.

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member185879
Active Contributor
0 Kudos

Hello Pietro,

Please use the following to get the first value in the simpletype and set the same.

IWDAttributeInfo attributeInfo = wdContext.nodeABC().getNodeInof().getAttribute("Att1")

ISimpleType simpleType = attributeInfo.getSimpleType();

ISimpleValueSet valueset = simpleType.getSVServices().getValues();

wdContext.currentABCElement().setAtt1(valueset.getKey(0).toString());

Reply for any issues.

Regards

Nizamudeen SM

Former Member
0 Kudos

Hi,

May be you can do as follows .


IModifiableSimpleValueSet<?> s = wdContext.getNodeInfo().getAttribute(
				"Rmb").getModifiableSimpleType().getSVServices()
				.getModifiableSimpleValueSet();
		Object[] objs = s.keySet().toArray();
		if (objs.length > 0) {
			wdContext.currentContextElement().setRmb(objs[0].toString());
		}

Edited by: Pitcher_ABC on May 11, 2011 11:56 AM

Former Member
0 Kudos

Hi Pietro,

It's been a while since I last opened WDJ, so I cannot test this for you. However, I'd suggest you trying something like:

http://help.sap.com/javadocs/NW04S/SPS09/wd/com/sap/tc/webdynpro/progmodel/api/IWDNode.html#getNodeI...

http://help.sap.com/javadocs/NW04S/SPS09/wd/com/sap/tc/webdynpro/progmodel/api/IWDNodeInfo.html#getA...

http://help.sap.com/javadocs/NW04S/SPS09/wd/com/sap/tc/webdynpro/progmodel/api/IWDAttributeInfo.html...

As soon you have the SimpleType, you might want to check this:

http://help.sap.com/javadocs/NW04S/SPS09/dr/com/sap/dictionary/runtime/ISimpleType.html#getEnumerati...

http://help.sap.com/javadocs/NW04S/SPS09/dr/com/sap/dictionary/runtime/ISimpleType.html#getEnumerati...

First returns a Set, which you can iterate and find the stuff you want. It does not work for back-end types thou, so you might want to check the second, which returns a Map.

Hope it helps,

D.