cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Type Value Displayed

Former Member
0 Kudos

I have a Simple Type that has numerical values and text descriptions. It is bound to a dropdownbykey box. I am using this code to retrieve the users selection:

String sField = wdThis.wdGetApplicationController().wdGetContext().currentContextElement().getFields();

This returns the value (e.g., 1 or 2) which is great because I need this index to send to the database, however I would also like to display the description(e.g., blue or green) for the user so they can be reminded of their selection.

What is the best way to retrieve the description for the selected item?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

First, this can be simplified by using context mapping: Map the attribute "fields" from the view controller to the component controller. Then you can just write


String sField = wdContext.currentContextElement().getFields();

To get the description from the value, you have to access the value set defined for the simple type. Something like


ISimpleValueSet valueSet = wdContext.getNodeInfo().getAttribute(IContextElement.FIELDS)
  .getSimpleType().getSVServices().getValues();
String description = valueSet.getText(value, WDClientUser.getCurrentUser().getLocale() );

Armin

Former Member
0 Kudos

>

> To get the description from the value, you have to access the value set defined for the simple type. Something like

>


> ISimpleValueSet valueSet = wdContext.getNodeInfo().getAttribute(IContextElement.FIELDS)
>   .getSimpleType().getSVServices().getValues();
> String description = valueSet.getText(value, WDClientUser.getCurrentUser().getLocale() );
> 

>

> Armin

I see what you are saying here and I hate to sound simple but I don't understand where the ISimpleValueSet and IContextElement are coming from...

I get an error saying cannot be resolved or is not a type. Is this something you defined earlier or am I missing an import statement somewhere?

Former Member
0 Kudos

For getting the imports, just press CTRL-SHIFT-O (Organize imports).

The IContextElement.FIELDS is only available if you have defined the mapped attribute "fields" in the view controller. Make sure to select the right import (IPrivate<View>.IContextElement).

Armin

Answers (1)

Answers (1)

PradeepBondla
Active Contributor
0 Kudos

Hi,

In drop down by key, you will store values as (key, value) pair. presently you are retrieving key. same way retrieve the value.

hope you have drop down key value pair as (1,blue), (2,red)......

in your same code String sField = wdThis.wdGetApplicationController().wdGetContext().currentContextElement().get<VALUES>();

PradeeP

Former Member
0 Kudos

Thanks Pradeep but I don't understand:

Fields is the name of my simple type so when I said

String sField = wdThis.wdGetApplicationController().wdGetContext().currentContextElement().getFields();

getFields returns the value of Simple Type Fields.

I am trying to return the description - as you said I have it set up as (1,blue) and (2,green). Your replay stated to use:

String sField = wdThis.wdGetApplicationController().wdGetContext().currentContextElement().get<VALUES>();

What does <VALUES> stand for?

PradeepBondla
Active Contributor
0 Kudos

Hi,

This is my code to populate the drop down by key


		IWDAttributeInfo pColorAttInfo=wdContext.nodePstatus_out().getNodeInfo().getAttribute("color");
		ISimpleTypeModifiable pColorSMT= pStatAttInfo.getModifiableSimpleType();
		IModifiableSimpleValueSet pColorSimpValSet= pColorSMT.getSVServices().getModifiableSimpleValueSet();
			//hard coding the drop down values
			pColorSimpValSet.put(1,blue);
                        pColorSimpValSet.put(2,red);
		        pColorSimpValSet.put(3,green);
	}

In the above code (1,blue), (2,red)... is (key, value).

i.e. you are storing as valueset.put ( key, value).

when retrieving pass the key it will display the value. i.e in my code it will give you value like blue,red....

PradeeP

Edited by: pradeep bondla on Jul 30, 2008 4:40 PM