cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot retreive index of selected radio button

Former Member
0 Kudos

Hi,

I have implemented a RadioButtonGroupByIndex as follow:

String[] monthNames = new String []  {
   "January", "February", "March", "April",
   "May", "June", "July", "August", 
   "September", "October", "November", "December",
};

//1. Create context elements for node "MonthsOfYear"
List monthsOfYear = new ArrayList();
for (int i =  0; i < monthNames.length; ++i) {
   IPrivateMainView.IMonthsOfYearElement month = 
   wdContext.createMonthsOfYearElement();
   month.setMonthName(monthNames<i>);
   monthsOfYear.add(month);
}

//2. Bind node to element list
wdContext.nodeMonthsOfYear().bind(MonthsOfYear);


//set lead selection
 wdContext.nodeMonthsOfYear().setLeadSelection(5);

I have created an onSelect event on the RadioButtonGroupByIndex. I am trying to retreive the index of the selected radio button to enable an edit field. When trying to display the id of the selected radio button, the result is "0" for each one of them. How come the index is not 0 for the first one, 1 for the second... ?

Thanks in advance for your help.

Thibault

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

int selectedIndex = wdContext.nodeMonthsOfYear().getLeadSelection();

Armin

Former Member
0 Kudos

Armin, thank you

Former Member
0 Kudos

You might also change your code to


String[] monthNames = new String []  {
   "January", "February", "March", "April",
   "May", "June", "July", "August", 
   "September", "October", "November", "December",
};
 
for (int i =  0; i < monthNames.length; ++i) 
{
   IPrivateMainView.IMonthsOfYearElement e =  wdContext.createAndAddMonthsOfYearElement();
   e.setMonthName(monthNames<i>);
}

and put it into a supply function for the context node.

Armin

Answers (1)

Answers (1)

p330068
Active Contributor
0 Kudos

Hi Thibault,

Please try this :

IPrivateMainView.IMonthsOfYearElement month = null;

for (int i = 0; i < monthNames.length; ++i)

{

month = wdContext.createMonthsOfYearElement();

month.setMonthName(monthNames<i>);

wdContext.nodeMonthsOfYear().addElement(month);

}

//set lead selection

wdContext.nodeMonthsOfYear().setLeadSelection(5);

Hope it helps

Regards

Arun

Former Member
0 Kudos

The retreived id is still "0" with this solution. Thanks for helping.

p330068
Active Contributor
0 Kudos

Hi Thibault,

Try to retrive id of the selected radio button:-

wdContext.nodeMonthsOfYear().currentMonthsOfYearElement().getMonthName();

Print the value

Hope it helps

Regards

Arun

Former Member
0 Kudos

In fact this is not the way I would do it. I have associated an event on the redioButtonGroupByIndex. When a user click on one of the buttons, the onActionSelected function is called. Its parameters are the event and the radio button key. When trying to display this key, its value is 0 for each button...