on 05-10-2011 2:22 PM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
As soon you have the SimpleType, you might want to check this:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.