cancel
Showing results for 
Search instead for 
Did you mean: 

Radiobuttons in table

Former Member
0 Kudos

Hi all,

I have different problems with adding radiobuttons in my table.

In my context I have:

-DynamicText (ValueNode)

--Persons (ValueNode)

---PersonsText (ValueAttribute)

-TableProperties (ValueNode)

--Selection (ValueNode)

---KeyToSelect (ValueAttribute)

--SelectedKey (ValueAttribute)

With binding I set the PersonsText in my table with a radioButton in every row.

I tried to set the selection with the following code:

int personsSize = wdContext.nodePersons().size();

ITablePropertiesElement table = wdContext.createTablePropertiesElement();

for (int i=0; i<personsSize; i++) {

ISelectionElement element = wdContext.nodeSelection().createSelectionElement();

element.setKeyToSelect(wdContext.nodePersons().getPersonsElementAt(i).getPersons());

wdContext.nodeSelection().addElement(element);

}

I try to get the selection with:

String key = wdContext.currentTablePropertiesElement().getSelectedKey();

IWDMessageManager mng = wdComponentAPI.getMessageManager();

mng.reportSuccess("selected is:" +key);

This returns null.

When I deploy and start the application also all the radiobuttons are selected.

I tried to set the propertie from the table "selectionMode" to single.

That doesn't help.

Can anyone help me with this problems please?

Accepted Solutions (1)

Accepted Solutions (1)

vijayakhanna_raman
Active Contributor
0 Kudos

Hi,

Check this thread

Regards,

Vijayakhanna Raman

Former Member
0 Kudos

Hi,

I've used this thread as an example and worked it out as above.

The selection works fine now except that i can choose more than 1 options now.

Former Member
0 Kudos

Hi,

Check if you have done this:

-Root

--TableProperties(cardinality=1..n,singleton=true)

---Selection(cardinality=0..1,singleton=false,supplyFunction=supplySelection)

-


KeyToSelect(String)

---PersonName(String)

---SelectedKey(String)

Now in your event handler for onSelect of radio button, use this:


for(int i = 0; i < wdContext.nodeTableProperties().size(); i++){
if(i != wdContext.nodeTableProperties().getLeadSelection()){
wdContext.nodeTableProperties().getElementAt(i).setAttributeValue("SelectedKey",null);
}
}
    
String key = wdContext.nodeTableProperties().currentTablePropertiesElement().getSelectedKey();
wdComponentAPI.getMessageManager().reportSuccess("Key is:" + key);

Actually this should have been done with cardinality, but this is a workaround. I'll try to fix this.

Regards,

Satyajit.

vijayakhanna_raman
Active Contributor
0 Kudos

Hi,

U want to select one at a time or more

Regards,

Vijayakhanna Raman

Former Member
0 Kudos

Hi Satyajit,

Thanks for your answers in this toppic!

With this last workarround my problems are solved.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Check if node bound to the RadioButton has 1...1 cardinality, singleton=false and initializeLeadSelection=true.

Also there is something missing in your code:

int personsSize = wdContext.nodePersons().size();
ITablePropertiesElement table = wdContext.createTablePropertiesElement();
for (int i=0; i<personsSize; i++) {
ISelectionElement element = wdContext.nodeSelection().createSelectionElement();
element.setKeyToSelect(wdContext.nodePersons().getPersonsElementAt(i).getPersons());
wdContext.nodeSelection().addElement(element);
}
//<b>This is missing I guess.</b>
wdContext.nodeTableProperties().addElement(table);

Regards,

Satyajit.

Former Member
0 Kudos

Hi Satyajit,

When I set the cardinality to 1...1 I got the following exception:

com.sap.tc.webdynpro.progmodel.context.ContextException: Node(MyView.TableProperties.0.Selection): must not add elements to a Node of cardinality 0..1 or 1..1

For the missing code, see the explanation above.

Thnx in advance

Former Member
0 Kudos

Hi,

Try making the cardinality to 0...1. Don't pay too much attention to the error message Sometimes they can be a little misguiding.

Regards,

Satyajit.

Former Member
0 Kudos

I've got the same exception when I change the cardinality to 0..1

Former Member
0 Kudos

Hi,

How have you bound the "selectedKey" property of the radio buttons?

Regards,

Satyajit.

Former Member
0 Kudos

Hi,

I've set this propertie to: TableProperties.SelectedKey

Former Member
0 Kudos

Hi,

Is the <i>initializeLeadSelection</i> property of the node bound to the radio button set to true?

Also have you set the <i>singleton</i> property of this node to false?

Regards,

Satyajit.

Former Member
0 Kudos

Hi,

Yes all the properties are set like this.

I also tried something else, I changed the context:

Context

- Table (ValueNode)

-- KeyToSelect (ValueAttribute)

- SelectedKey (ValueAttribute)

I bind this properties to my RadioButton and changed the code to set the KeyToSelect in the valuenode Table.

Now my second problem (all the checkboxes selected in the beginning) is solved.

Now I want to read the SelectedKey in my code in the view.

How can I read the SelectedKey (straight under the context) now?

Former Member
0 Kudos

Hi,

Have a context that looks like this:

-RootNode

--TableProperties(node, cardinality=1..n,singleton=false)

---Selection(node,cardinality=1..n,singleton=false,supplyFunction=supplySelection)

-


KeyToSelect(String)

---SelectedKey(String)

---PersonName(String)

Bind TableProperties.Selection.KeyToSelect to the keyToSelect property of the radio button. And bind TableProperties.SelectedKey to the selectedKey property of the radio button.

The supply function supplySelection looks like:


IPrivateSDNCompView.ISelectionElement elem = node.createSelectionElement();
    	
node.addElement(elem);
elem.setKeyToSelect("Key_" + parentElement.getPersonName());

Now in the event handler for the onSelect event of the radio button, write this code:


String key = wdContext.nodeTableProperties().currentTablePropertiesElement().getSelectedKey();
		
wdComponentAPI.getMessageManager().reportSuccess("Key is:" + key);

Regards,

Satyajit.

Former Member
0 Kudos

Hi Satyajit,

Thanks for your answer!

This works fine with the selected key, except that I can choose more than 1 options now in my Table.

Maybe because I couldn't use your example totally.

This is how I did it.

-Context

--DynamicText(node, cardinality=0..n, singleton=true)

---Persons(node, cardinality=0..n, singleton=false)

-


Selection(node, cardinality=0..n, singleton=false,supplyFunction=supplySelection)

-


KeyToSelect(String)

---PersonText(String)

---SelectedKey(String)

I couldn't set the singleton of the first item to false because its just below the context-root (you can't change that singleton property)

Do you know how I can change this so I can't select more than 1 option?

Thanks in advance!

Former Member
0 Kudos

The key works with this example but I can choose more than one radiobutton.

Does anyone know how I can use this and still only can select one radiobutton at the time?

Former Member
0 Kudos

Hi B.

i dont know if that is reason of your problom or only mistake in post but in your code:

nt personsSize = wdContext.nodePersons().size();
ITablePropertiesElement table = wdContext.createTablePropertiesElement();

wdContext.nodeTableProperties.addElement(table); //that is missing!!!!

for (int i=0; i<personsSize; i++) {
ISelectionElement element = wdContext.nodeSelection().createSelectionElement();
element.setKeyToSelect(wdContext.nodePersons().getPersonsElementAt(i).getPersons());
wdContext.nodeSelection().addElement(element);
}

an insert tableelement to table node is missing.

Regards

Bogdan

Former Member
0 Kudos

Hi Bogdan,

No sorry, that didn't solve my problem.

In this code that table isn't nessesary, I use this tableElement to set the number of rows depending on how many persons I have.