cancel
Showing results for 
Search instead for 
Did you mean: 

Table and RadioButton

david_fryda2
Participant
0 Kudos

Hi everyone,

I created a radiobutton in each row of a table.

When I click on a button, I want to know on which row and what are the data of this row.

How it can be done ?

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Assign an action to the RadioButton.<i>onSelect</i> event with a parameter "selectedElement" of type I<Rows>Element, where "Rows" is the name of the table data source node.

Map (implicit) event parameter "nodeElement" to action parameter "selectedElement" like this:

wdDoModifyView():

if (firstTime)
{
  IWDRadioButton rb = (IWDRadioButton) view.getElement("ID-of-radio-button");
  rb.mappingOfOnSelect().addSourceMapping
  (
    "nodeElement", "selectedElement"
  );
}

Armin

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi David,

Here is a nice guide to provide this feature:

The context:

- Persons (Node)

-- Name (Attribute)

-- SelectedKey (Attribute, String)

-- Selection (Node, cardinality: 0..1, selection: 1..1, supplyFuntion selectPerson)

--- KeyToSelect (Attribute, String)

Layout:

- Add table with dataSource propertie: Persons

- Tablerow TextView with propertie text: Persons.Name

- Tablerow RadioButton with propertie keyToSelect: Persons.Selection.KeyToSelect, selectedKey: Persons.SelectedKey, onSelect: SelectPerson

Code:

public void selectPerson(......) {

ISelectionElement el = node.createSelectionElement();

node.addElement(el);

el.setKeyToSelect(parentElement.getName());

}

public void onActionSelectPerson(.....) {

for (int i=0; i < wdContext.nodePersons().size(); i++) {

if (i != wdContext.nodePersons().getLeadSelection()) {

wdContext.nodePersons().getElementAt(i).setAttributeValue("SelectedKey", null);

}

}

}

Method above is for not getting a multiple select (work-around)

If you have a button in your layout that submits the selection, you can read the selected row with:

String key = wdContext.nodePersons().currentPersonsElement().getSelectedKey();

wdComponentAPI.getMessageManager().reportSuccess(key);

Regards,

Björn

david_fryda2
Participant
0 Kudos

Thanks guys...it works...

Regards.

Former Member
0 Kudos

Hi,

It is superfluous to use radiobuttons inside table cells for the scenario you describe.

When you bind the table to a node with cardinality (0-n), and set the selectionmode to single, you can allways access the data for that row from the context:

wdContext.current<NodeName>Element.getProperty();

Good luck,

Roelof