cancel
Showing results for 
Search instead for 
Did you mean: 

How to populate dropdown list with String [][] array

Former Member
0 Kudos

Hi

I have a 2 dimentional array returned from EJB like String [] [] myarray.Now using this array how to populate a dropdown list with this.

Thanks in advance.

Ananda

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Ananda,

1. Create a Dropdown UI element in your View

2. In the view context, create a value attribute("X") and assign it to the dropdown UI element.

Do some modifications to mentioned code below and add it in your VIEW implementation.

ISimpleTypeModifiable myType=wdThis.wdGetAPI().getContext
                             ().getModifiableTypeOf("X");
IModifiableSimpleValueSet values=myType.getSVServices
                      ().getModifiableSimpleValueSet();

for (int i=0; i< <Your ArraySize>; i++)
{
    //Insert Another loop (you array is two dimensional)
    values.put(<value from array>, <value from array>);
}

Thanks

Senthil

P.S. Reward Points for useful/helpful answers

Former Member
0 Kudos

Thanks Senthill

I have awarded you points

Another query: How to retrieve the <key> and the <value> in the values.put(<key>,<value>) so that I can populate a second dropdown with the <key> and use <value> for simple display to the browser.

Thanks in advance

Ananda.

Former Member
0 Kudos

Hello Roy,

Use this code to retrieve the values from the simple value services.


for (int i=0; i< <Your ArraySize>; i++)
{
    String _key = values.getKey(i);
    String _value =  values.getText(i);
}

Bala

Please reward appropriate points

Message was edited by: Bala Krishnan

Former Member
0 Kudos

Hi Ananda,

Retrieve the Dropdown UI element from View.

IWDDropDownByKey ddElement = (IWDDropDownByKey)

view.getElement("<ui element id>");

String key = ddElement.getSelectedKey();

You could even read lead selection element of the node and get the key and values..

Thanks

Senthil

Former Member
0 Kudos

Hello

My query is how to retrieve the exact key which is selected from the drop down list;since the dropdown list shows the description part of SVS

Thanks

Ananda

Former Member
0 Kudos

No, don't do this. To access the selected key of a DropDownByKey element, you do not have to access the view layout and get the UI element instance. Use the bound view context attribute instead.

Armin

Former Member
0 Kudos

Thanks Armin, but how to do that ?

Ananda

Former Member
0 Kudos

Hello Roy,

Follow Armin's idea. Access the key for the selected description using the code

wdContext.currentContextElement.get<attributeThatisMappedtoDropDown>;

i.e the value attribute "X" in your code above

Please reward appropriate points.

Bala

Former Member
Former Member
0 Kudos

Hi All

I have succesfully populated the 2 dropdown list box where the contents of the second dropdown depends on the first BUT with one DEFECT:

When changing the first drop down each time the previous elements of the second dropdown are NOT erased out;

How to refresh the second drop down ?

Thanks

Ananda

Former Member
0 Kudos

Assign an action to the "onSelect" event of the first drop-down list. In the action handler, reset the value set for the second.

Armin

Former Member
0 Kudos

Hello

I have used this code to reset

wdContext.currentContextElement().set<context_element>("")

but it is not reseting .Can you please help with code to reset the second dropdown .

Thanks

ananda

Former Member
0 Kudos

Do I understand you correctly, you want to change the value set of the second drop-down list after selection of an item in the first drop-down list?

Then you could do this:

In the selection handler for the first drop-down list, get the DDIC type (modifiable simple type) of the context attribute used for the second drop-down list and <b>replace </b>its value set according to the selected key in the first drop-down list.

Armin

Message was edited by: Armin Reichert

Former Member
0 Kudos

Hello Armin You are correct I have done it already what you have said BUT in the second dropdown new values are ADDED to the previous one's.

SO what I want is to completely delete the values of the second dropdown and create a new dropdown list when the first drop down changes.

Thanks in Advance

Ananda

Former Member
0 Kudos

Hello Anandha,

U can put the required logic in the OnSelect event of the First dropdown.

The following is a pointer code for doing the same.


/*** modiableType of Second dropdown
ISimpleTypeModifiable mySecondType = 
wdControllerAPI.getContext()
.getModifiableTypeOf("<modifiableType of Second DropDown>");

IModifiableSimpleValueSet secondSetOfValues = 
mySecondType.getSVServices()
.getModifiableSimpleValueSet();

String Name = wdContext.currentContextElement().getName_Char();

int i = wdContext.nodeClasscharvalues_Output().size();

<b>/*** Clear the values in the second dropdown ***/
secondSetOfValues.clear();</b>

/*** Populate the values in the second dropdown based on some logic ***/

for (int valueList = 0;valueList < i; valueList++ )
{
IWDNodeElement element = 
wdContext.nodeClasscharvalues_Output()
.getClasscharvalues_OutputElementAt(valueList);

Sring NameStr = (String)element.getAttributeValue("Name_Char");

if(Name.equalsIgnoreCase(NameStr))
{
secondSetOfValues.put((String)element.getAttributeValue("Char_Value") , 
(String)element.getAttributeValue("Char_Value"));
}
}

Please reward appropriate points

Bala

Message was edited by: Bala Krishnan

Former Member
0 Kudos

Hi,

In the onSelect() action of firstdropdown,

add this piece of code to clear the values in 2nd Dropdown and populate with fresh values.

onSelectFirstDropDown()
{
ISimpleTypeModifiable myType=wdThis.wdGetAPI().
     getContext().getModifiableTypeOf(<Att Name mapped to 2nd dropdown>);
IModifiableSimpleValueSet valSet = myType.getSVServices
                        ().getModifiableSimpleValueSet();

valSet.clear();
// Add piece of code to populate the 2nd dropdown list
}

Hope this helps.

Thanks

Senthil