on 05-20-2007 2:29 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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
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
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);
Thanks!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I forgot one thing. Bind the value attribute CB.CheckBox in "texts" property of CheckBoxGroup
Regards
Fahad Hamsa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
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.