on 11-12-2007 8:15 PM
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>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
Hi,
You can make use of radio button group, for selecting answers
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.