cancel
Showing results for 
Search instead for 
Did you mean: 

deselecting the radio buttons

Former Member
0 Kudos

Hi,

I am creating the radio buttons dynamically in the following way

String answers[] = qForm.getAnswers();

for (int j=0;j<qForm.getNoOfChoices();j++)

{

IWDRadioButton radio =

(IWDRadioButton)view.createElement(IWDRadioButton.class , "radio"ij);

radio.setText(answers[j]);

wdContext.getNodeInfo().addAttribute("radio"ij,"ddic:com.sap.dictionary.string");

radio.bindKeyToSelect("radio"ij);

radio.bindSelectedKey("radio"ij);

rootContainer.addChild(radio);

}

<b>but what is the problem is when i access the view all the radio buttons are selected by default which i donot want to happen.and how do i know which radio button is selected when i select any one.

Please let me know what are the various options</b>

Accepted Solutions (1)

Accepted Solutions (1)

raja_thangamani
Active Contributor
0 Kudos

Refer this link, it will solve your problem:

Raja T

Message was edited by:

Armin Reichert

Answers (3)

Answers (3)

Former Member
0 Kudos

Radio buttons must be bound to the same context attribute to realize the "radio button" behavior.

Why do you want to do all this by code instead by using the IDE?

Create a context attribute named "selectedKey", type=string, at design-time.


String answers[] = qForm.getAnswers();
for (int j=0; j < qForm.getNoOfChoices(); j++)
{
  IWDRadioButton radio =
(IWDRadioButton) view.createElement(IWDRadioButton.class , null);
  radio.setText(answers[j]);
  radio.setKeyToSelect(String.valueOf(j));
  radio.bindSelectedKey("selectedKey");
  rootContainer.addChild(radio);
}
/* select first button */
wdContext.currentContextElement().setSelectedKey("0");

Armin

Former Member
0 Kudos

Hi Armin,

what does this mean

<b>Why do you want to do all this by code instead by using the IDE?</b>

Former Member
0 Kudos

Hi,

wdContext.getNodeInfo().addAttribute("radio1","ddic:com.sap.dictionary.string");

for (int j=0;j<qForm.getNoOfChoices();j++)

{

IWDRadioButton radio =

(IWDRadioButton)view.createElement(IWDRadioButton.class , "radio"ij);

radio.setText(answers[j]);

radio.setKeyToSelect("radio"ij);

radio.bindSelectedKey(radio1);

rootContainer.addChild(radio);

}

wdContext.currentContextElement.setAttribute("radio1",radio11);//key that you want to be selected by default.

Regards,

Murtuza

Former Member
0 Kudos

Hi Murtuza,

This is not working for me and here is what i wrote

wdContext.getNodeInfo().addAttribute("radio1","ddic:com.sap.dictionary.string");

for (int j=0;j<qForm.getNoOfChoices();j++)

{

IWDRadioButton radio =

(IWDRadioButton)view.createElement(IWDRadioButton.class , "radio"ij);

radio.setText(answers[j]);

radio.setKeyToSelect("radio"ij);

radio.bindSelectedKey("radio"ij);

rootContainer.addChild(radio);

}

wdContext.currentContextElement().setAttributeValue("radio1","radio"i0);//key that you want to be selected by default.

and this is the error i am getting

<b>com.sap.tc.webdynpro.progmodel.context.ContextException: DataNodeInfo(SCJP): unknown child node radio00 </b>

any other thoughts

Former Member
0 Kudos

somebody help me in solving this issue

Former Member
0 Kudos

Hi Bala,

You have changed a line in the code mentioned:

<b>radio.bindSelectedKey(radio1);</b>

wdContext.getNodeInfo().addAttribute("radio1","ddic:com.sap.dictionary.string");

for (int j=0;j<qForm.getNoOfChoices();j++)

{

IWDRadioButton radio =

(IWDRadioButton)view.createElement(IWDRadioButton.class , "radio"ij);

radio.setText(answers[j]);

radio.setKeyToSelect("radio"ij);

<b>//radio.bindSelectedKey("radio"ij);</b>

<b>radio.bindSelectedKey(radio1);</b>

rootContainer.addChild(radio);

}

wdContext.currentContextElement().setAttributeValue("radio1","radio"i0);

Regards,

Murtuza

Former Member
0 Kudos

Hi Murtuza,

I didnot understand where this <b>radio1 </b>is coming from

Former Member
0 Kudos

Hi,

radio1 is the attribute that we have added dynamically in the code itself. Just refer the first line of your code.

Regards,

Murtuza

Former Member
0 Kudos

Hi Murtuza,

<b>I am sorry i didnot mention radio1 initially . after u sent me the below code snippet I modified a little bit but still it is not working </b>

wdContext.getNodeInfo().addAttribute("radio1","ddic:com.sap.dictionary.string");

for (int j=0;j<qForm.getNoOfChoices();j++)

{

IWDRadioButton radio =

(IWDRadioButton)view.createElement(IWDRadioButton.class , "radio"ij);

radio.setText(answers[j]);

radio.setKeyToSelect("radio"ij);

radio.bindSelectedKey(radio1);

rootContainer.addChild(radio);

}

wdContext.currentContextElement.setAttribute("radio1",radio11);//key that you want to be selected by default.

But anyways i got the working code from armin but still i need to do a lot like

<b>I am generating four checkboxes and one button dynamically .I will check some checkboxes and on the click of the button i want to capture what checkboxes have been checked and need to do the same thing for radio buttons</b>

any thoughts on this

Former Member
0 Kudos

Hi,

For radio button you can check the value of the context binded to the selectedKey to know the currently selected radio button.

But for checkbox group, you will have a node to loop around and check whether it is selected or not.

wdContext.node<nodename>().isMultiSelected();

Regards,

Murtuza

Former Member
0 Kudos

Hi,

You can make use of radio button group, for selecting answers

Regards

Ayyapparaj

Former Member
0 Kudos

even this option is not of much help.on the loading of the view all the radio buttons are selected by default.

any other ways of doing this