cancel
Showing results for 
Search instead for 
Did you mean: 

Reading Dynamic Checkbox

Former Member
0 Kudos

All,

I have created <b>Multiple</b> checkbox (Without checkbox Grp) at runtime using below code. I have question..

How can I read the value of all checkboxes?


			IWDAttributeInfo Checked_att =
				wdContext.nodeSkill().getNodeInfo().addAttribute(
					"checked",
					"ddic:com.sap.dictionary.boolean");
			final int size = wdContext.nodeT_Req().size();
			for (int i = 0; i < size; i++) {
				IWDCheckBox chkbox =
					(IWDCheckBox) view.createElement(
						IWDCheckBox.class,
						"checkbox" + i);
				chkbox.bindChecked(Checked_att);
				String chk_text =
					wdContext.nodeT_Req().getT_ReqElementAt(i).getStext();
				chkbox.setText(chk_text);
				IWDTray cont = (IWDTray) view.getElement("tray");
				cont.addChild(chkbox);

			}

Thanks in advance..

BM

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Bharathi,

First of all -- your code seems to have a bug. All check-boxes are bound to single attribute, hence all of them edit single value.

I bet you need something like this:


final int size = wdContext.nodeT_Req().size();
final IWDTray cont = (IWDTray) view.getElement("tray");
for (int i = 0; i < size; i++) {
  final IWDAttributeInfo Checked_att = wdContext.nodeSkill().getNodeInfo()
    .addAttribute("checked" + i, "ddic:com.sap.dictionary.boolean");

  final IWDCheckBox chkbox = (IWDCheckBox) 
    view.createElement(IWDCheckBox.class, "checkbox" + i);
  chkbox.bindChecked(Checked_att);
  final String chk_text = wdContext.nodeT_Req().getT_ReqElementAt(i).getStext();
  chkbox.setText(chk_text); 
  cont.addChild(chkbox);
}

To get value you should use:


final Boolean _isFirstChecked = wdContext.currentSkillElement().getAttributeValue("checked0");
final boolean isFirstChecked = _isFirstChecked == null ? false : _isFirstChecked.booleanValue();

Use "checked1", "checked2"... for rest attributes

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Former Member
0 Kudos

You are great..I can see that it bound to same name..Thanks...

I will implement this code & get back to you..

BM

Former Member
0 Kudos

All,

Sorry to get back delayed..

Im trying to read the checkbox(which created dynamically) using below code, but getting an error:

 "Type Mismatch :can not convert from obuject to bollean.

Here is the code
final Boolean _isFirstChecked = wdContext.currentSkillElement().getAttributeValue("checked0");
final boolean isFirstChecked = _isFirstChecked == null ? false : _isFirstChecked.booleanValue();

Can anyone tell me what is wrong? or is there anyother way to read the checkbox value..

Thanks..

BM

Former Member
0 Kudos

Is this compilation error that you are getting at

final Boolean _isFirstChecked = wdContext.currentSkillElement().getAttributeValue("checked0"); ???

If so try replacing this with

final Boolean _isFirstChecked = (Boolean)wdContext.currentSkillElement().getAttributeValue("checked0");

Anilkumar