cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Checkbox

Former Member
0 Kudos

All,

I need to read the DB tables, based on the table row entries I need to create the checkbox dynamically under the Tray called "Manager".

1. How can i create the multiple checkbox dynamically.

2. How can i add it under the tray..

I went thro some thread, but i could not get much detail..Can anyone give me a code please...

Thanks in advance..

<i>I will reward each useful answer...</i>

BM

Accepted Solutions (1)

Accepted Solutions (1)

venkatakalyan_karanam
Active Contributor
0 Kudos

Hi Bharathi

you can create a check box dynamically bu using the following code in wdModify method because what ever modifications to the Screen in webdynpro must be performed in this method

IWDCheckBox cb=(IWDCheckBox)view.createElement(IWDCheckBox.class,"checkbox1" ) ;

cb.setOnToggle(<any action reference>);

Like this you can create number of check boxes

//adding to tray

IWDTransparentContainer cont=(IWDTransparentContainer)view.getElement("<tray id.>");

cont.addElement(<your check box>);

regards

kalyan

Former Member
0 Kudos

I used the below code in DoMODIFY:

	  IWDCheckBox cb = (IWDCheckBox) view.createElement(IWDCheckBox.class, "checkbox1" ) ;
//	  cb.setOnToggle(<any action reference>);
//	  Like this you can create number of check boxes 
//		adding to tray
	  IWDTransparentContainer cont= (IWDTransparentContainer) view.getElement("tray1");
	  cont.addChild(cb);
     

Getting an exception at runtime as below:

The initial exception that caused the request to fail, was:



   java.lang.ClassCastException 

    at com.epiuse.us.rq.reqform.ReformView.wdDoModifyView(RequisitionFormView.java:174)
    at com.epiuse.us.rq.reqform.wdp.InternalReFormView.wdDoModifyView(InternalRequisitionFormView.java:1743)
    at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.doModifyView(DelegatingView.java:78)
    at com.sap.tc.webdynpro.progmodel.view.View.modifyView(View.java:337)
    at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.doModifyView(ClientComponent.java:480)
    ... 28 more

Could anyone tell me what is the issue?

BM

Former Member
0 Kudos

Hi,

Bind the checked property of the checkbox to some context attribute.

Former Member
0 Kudos

Bharathi,

Use eithee of below:


IWDCheckBox cb = (IWDCheckBox) view.createElement(IWDCheckBox.class, "checkbox1" ) ;
// cb.setOnToggle(<any action reference>);
// Like this you can create number of check boxes 
// adding to tray
IWDTray cont= (IWDTray) view.getElement("tray1");
cont.addChild(cb);

Or this way:


IWDCheckBox cb = (IWDCheckBox) view.createElement(IWDCheckBox.class, "checkbox1" ) ;
// cb.setOnToggle(<any action reference>);
// Like this you can create number of check boxes 
// adding to tray
IWDUIElementContainer cont= (IWDUIElementContainer) view.getElement("tray1");
cont.addChild(cb);

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Former Member
0 Kudos

Thanks for all your help. can anyone tell me how to bind the checkbox..I will reward fully once i solve the issue..

In my case i dont know how many checkbox i have to create becos its based on DB table entries...

Also i have another question..can i create the checkbox without checkbox group?

BM

vijayakhanna_raman
Active Contributor
0 Kudos

Hi,

Use this code below to bind the attribute.

This is Checkbox only not checkboxby group.

Create the attribute of type boolean and try this code.

IWDAttributeInfo Checked_att=wdContext.getNodeInfo().addAttribute("val1","ddic:com.sap.Boolean");

IWDCheckBox cb = (IWDCheckBox) view.createElement(IWDCheckBox.class, "checkbox1" ) ;

cb.bindChecked(Checked_att);

cb.setEnabled(true);

cb.setReadOnly(false);

cb.setText("Test Checkbox");

IWDTray cont= (IWDTray) view.getElement("tray1");

cont.addChild(cb);

Regards,

Vijai

Former Member
0 Kudos

Hi Bharati,

You can use the following line of code for cresting n number of checkbox.

For this first create a Node say Chkbox and set the

cardinality to 1..n

Note : This code cretaes 5 checkboxes.You can adapt it as

per your requirement.

if(firsttime)

{

IWDAttributeInfo Checked_att= wdContext.nodeChkbox

().getNodeInfo().addAttribute("checked","ddic:com.sap.dictionary.boolean");

for(int i=0;i<5;i++)

{

IWDCheckBox chkbox = (IWDCheckBox) view.createElement

(IWDCheckBox.class, "checkbox"+i ) ;

chkbox.bindChecked(Checked_att);

chkbox.setText("Test Checkbox");

IWDTransparentContainer cont= (IWDTransparentContainer)

view.getElement("RootUIElementContainer");

cont.addChild(chkbox);

}

}

Note : In wdDoModify put this code inside

if(firsttime){your code for dynamic generation}

else any attribute that you will add tries to get added

once again with any action or other changes in the view

I propose you use CheckBox group.

Else if you use checkbox then you have to create

a attribute of type boolean for each checkbox you

create dynamically.

If you bind only one attribute of type boolean to

all the checkbox created then on click of one

checkbox all the checkbox get checked or unchecked

Former Member
0 Kudos

Thanks for all your help.

Now the problem is all the 5 checkboxes are in same link, I need to display one after another, how can i do that?

Also if i checked 1st & 5th checkbox, on which variable the data checked/unchecked information will be stored?

THanks again..

BM

Former Member
0 Kudos

Hi Bharati,

The checkbox display depends on the layout that you use.Say if you want to dispaly 5 checkboxes one after the other then deifne layout as GridLayout with colcount 5.

The context attribute that is bind to the checkbox has the boolean value of checked/unchecked

You can get the status of checkbox as

wdContext.current<checkbox node>Element().get<checkbox context attribute>();

====================

Alternate solution

Bharati what I propose is you use checkbox group.

If you use CheckboxGroup then you dont need dynamic creation of checkbox nor you need to worry about the checkbox display.

Assume you need to display 6 checkboxes one after the other with a limitaion of 4 checkboxes in a row.

1.Create a Node say NodeChkbxGrp with attribute chkTexts of type String.The attribute chkTexts will have the values that are to displayed as labels of the checkboxes.

2.create a checkbox group and set the colocunt property to 4.

3. Bind the texts property of checkbox group to context attribute chkTexts.

When you run the application the checkboxes are displayed as shown below

CheckBox1 CheckBox2 CheckBox3 CheckBox4

CheckBox5 CheckBox6

To get the values of the checkboxes that are selected use the following code

String selected = "Selected values = "; // just used to display the checked checkboxes

for(int j=0;j<wdContext.nodeNodeChkbxGrp().size();j++)

{

if(wdContext.nodeNodeChkbxGrp().isMultiSelected(j))

{

selected = wdContext.nodeNodeChkbxGrp().getNodeChkbxGrpElementAt(j).getchkTexts()" ";

}

}

wdComponentAPI.getMessageManager().reportSuccess(selected);

Former Member
0 Kudos

Thanks for all your help..

I can check the boxes now. rite now im using only checkbox not checkbox grp. If i have any problem i will come back. time being closing the thread..

BM

Former Member
0 Kudos

Hi,

Happy to hear that your problem was solved.

Need anything post it, would be gald to help you.

Former Member
0 Kudos

Thanks a lot.. I would be need all your help since I'm new to webdynpro Java.

BM

Answers (6)

Answers (6)

Former Member
0 Kudos

Thanks!!!

Former Member
0 Kudos

BM,

Type casting IWDTray object to IWDTransparentContainer is simply not allowed in WD. So, do this.


IWDCheckBox cb = (IWDCheckBox) view.createElement(IWDCheckBox.class, null ) ;
....
....

// Type cast the object to IWDTray
IWDTray tray= (IWDTray) view.getElement("tray1");
tray.addChild(cb);

Bala

Former Member
0 Kudos

Hi Bharthi,

Can you please elaborate on the following:

1. Where are you getting the class cast exception.Line 337 does'nt make sense here.

2. Have you binded it dynamically to some attribute.

Regards

Amit

Former Member
0 Kudos

I forgot one thing. Bind the value attribute CB.CheckBox in "texts" property of CheckBoxGroup

Regards

Fahad Hamsa

Former Member
0 Kudos

Hi Bharathi,

1.Create a Node ( Say CB) in ur context with value attribute(Say CheckBox) of type String

2. Make cardinality and Selection properties of Node CB as 0.N

3.In ur tray, add a CheckBoxGroup UI Element

4.Create an action(Say onActionChecked) and bind it to this CheckBoxGroup

5.After calling RFC, u can add the following code

IPrivateMyCompView.ICBNode cN=wdContext.nodeCB();

IPrivateMyCompView.ICBElement cE;

for(int i=0;i<5;i++)

{

cE=cN.createCBElement();

cN.addElement(cE);

cE.setCheckBox("Value"+i);

//svs1.put("Key"i,"Value"i);

}

This will add 5 checkboxes with text as Value0....Value4.

In this for loop , instead of hardcoding the values, u can put the values from RFC by accessing those model nodes

Hope this will be helpful

Regards

Fahad Hamsa

Former Member
0 Kudos

Hi,

You don't need to create the check box dynamiclly, you can just bind text and map the actions:

1. Create a CheckBoxGroup UI element.

2. Bind the texts field to a node (Which will be filled dynamiclly, it should also contain a value attribute of type boolean which will store the check box status).

3. Add the following in the wdDoModifyView method of the view:

if (firstTime) {

IWDCheckBoxGroup checkBoxGroup = (IWDCheckBoxGroup)view.getElement(<check box group ID>);

checkBoxGroup.mappingOfOnToggle().addSourceMapping("checked","checked");

checkBoxGroup.mappingOfOnToggle().addSourceMapping("index","index");

}

4. Create an action and bind it to the "OnToggleEvent" of the CheckBoxGroup:

wdContext.node<yourNode>().setLeadSelection(index);

wdContext.current<yourNode>Element().set<yourBooleanAttribute>(checked);

5. You can check the status of the check boxes by going through your node and checking the status of your boolean attribute.

Hope this helps.

Yaniv