on 03-06-2008 5:20 PM
Hi everybody,
I'm struggling with the following code.
public void wdDoInit()
{
//@@begin wdDoInit()
IPrivateTestView.IPersonNode personNode = wdContext.nodePerson();
IPrivateTestView.IPersonElement personElement = personNode.createPersonElement();
personElement.setText("John");
personNode.getNodeInfo().addAttribute("selected_0", "ddic:com.sap.dictionary.boolean");
personElement.setAttributeValue("selected_0", new Boolean(true));
personNode.addElement(personElement);
personNode = wdContext.nodePerson();
personElement = personNode.createPersonElement();
personElement.setText("Walter");
personNode.getNodeInfo().addAttribute("selected_1", "ddic:com.sap.dictionary.boolean");
personElement.setAttributeValue("selected_1", new Boolean(true));
personNode.addElement(personElement);
//@@end
}
public static void wdDoModifyView(IPrivateTestView wdThis, IPrivateTestView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
IWDTransparentContainer tc = (IWDTransparentContainer) view.getElement("container");
IWDCheckBox cb0 = (IWDCheckBox) view.createElement(IWDCheckBox.class, "cb_0");
IWDCheckBox cb1 = (IWDCheckBox) view.createElement(IWDCheckBox.class, "cb_1");
IPrivateTestView.IPersonElement personElement = (IPrivateTestView.IPersonElement) wdContext.nodePerson().getElementAt(0);
cb0.bindChecked(personElement.getAttributePointer("selected_0").getAttributeInfo());
tc.addChild(cb0);
personElement = (IPrivateTestView.IPersonElement) wdContext.nodePerson().getElementAt(1);
cb1.bindChecked(personElement.getAttributePointer("selected_1").getAttributeInfo());
tc.addChild(cb1);
//@@end
}
Context's structure is as follows:
- Person (cardinality: 0..n; selection:0..n)
- Text (String)
I cannot figure out why, when the program runs, it renders 2 checkboxes but only the first one is checked.
The second checkbox should be checked off as well since its checked property is bound to the attribute selected_1 which is set to true.
Thanks in advance.
Marco
Hi,
I also agree with Armin, better to use chkboxgroup.
See some changes in your code , use below code
public void wdDoInit()
{
//@@begin wdDoInit()
IPrivateTestView.IPersonNode personNode = wdContext.nodePerson();
IPrivateTestView.IPersonElement personElement = personNode.createPersonElement();
personElement.setText("John");
personNode.getNodeInfo().addAttribute("selected_0", "ddic:com.sap.dictionary.boolean");
personElement.setAttributeValue("selected_0", new Boolean(true));
personNode.addElement(personElement);
personNode = wdContext.nodePerson();
personElement = personNode.createPersonElement();
personElement.setText("Walter");
// personNode.getNodeInfo().addAttribute("selected_1", "ddic:com.sap.dictionary.boolean");
personElement.setAttributeValue("selected_0", new Boolean(true));
personNode.addElement(personElement);
//@@end
}
public static void wdDoModifyView(IPrivateTestView wdThis, IPrivateTestView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
IWDTransparentContainer tc = (IWDTransparentContainer) view.getElement("container");
IWDCheckBox cb0 = (IWDCheckBox) view.createElement(IWDCheckBox.class, "cb_0");
IWDCheckBox cb1 = (IWDCheckBox) view.createElement(IWDCheckBox.class, "cb_1");
IPrivateTestView.IPersonElement personElement = (IPrivateTestView.IPersonElement) wdContext.nodePerson().getElementAt(0);
cb0.bindChecked(personElement.getAttributePointer("selected_0").getAttributeInfo());
tc.addChild(cb0);
personElement = (IPrivateTestView.IPersonElement) wdContext.nodePerson().getElementAt(1);
cb1.bindChecked(personElement.getAttributePointer("selected_0").getAttributeInfo());
tc.addChild(cb1);
//@@end
}
Regards,
Naga
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Naga.
Well my requirements are actually a bit more complex. I need to display a matrix of checkboxes where, the first checkbox of the row, makes visible (or invisible) the remaining checkboxes of the row.
It's then like a matrix of checkboxes and if I use a Checkbox Group, as far as I know, I cannot address checkboxes individually to make them invisible.
Any solution to this?
Cheers,
Marco
Hi,
You can achieve the same by using check box group.
try this below
public void wdDoInit()
{
//@@begin wdDoInit()
String names[]={"John","Walter"};
boolean val[]={true,false,true};
for(int i=0;i<names.length;i++){
IPrivateTetView.IPersonElement ele=wdContext.createPersonElement();
ele.setText(names<i>);
wdContext.nodePerson().addElement(ele);
wdContext.nodePerson().setSelected(i,val<i>);
}
//@@end
}
public static void wdDoModifyView(IPrivateTetView wdThis, IPrivateTetView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
IWDTransparentContainer tc = (IWDTransparentContainer) view.getElement("RootUIElementContainer");
IWDCheckBoxGroup cb0 = (IWDCheckBoxGroup) view.createElement(IWDCheckBoxGroup.class, "cb_0");
cb0.bindTexts("Person.text");
tc.addChild(cb0);
//@@end
}
Regards,
Naga
Hi,
As per my understanding you are trying to create group of check boxes dynamaically and all check boxes should work independent of each other. Please try the following code, I have modified your code:
- Change the cardinality of the Peron node to 1..1
public void wdDoInit()
{
//@@begin wdDoInit()
IPrivateTestComponentView.IPersonNode personNode = wdContext.nodePerson();
IPrivateTestComponentView.IPersonElement personElement = personNode.currentPersonElement();
//personElement.setText("John");
personNode.getNodeInfo().addAttribute("selected_0", "ddic:com.sap.dictionary.boolean");
personElement.setAttributeValue("selected_0", new Boolean(true));
personNode.getNodeInfo().addAttribute("text_0", "ddic:com.sap.dictionary.string");
personElement.setAttributeValue("text_0","John");
//personNode.addElement(personElement);
//personNode = wdContext.nodePerson();
//personElement = personNode.createPersonElement();
//personElement.setText("Walter");
personNode.getNodeInfo().addAttribute("selected_1", "ddic:com.sap.dictionary.boolean");
personElement.setAttributeValue("selected_1", new Boolean(true));
personNode.getNodeInfo().addAttribute("text_1", "ddic:com.sap.dictionary.string");
personElement.setAttributeValue("text_1","Walter");
//personNode.addElement(personElement);
//@@end
}
public static void wdDoModifyView(IPrivateTestComponentView wdThis, IPrivateTestComponentView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)
{
//@@begin wdDoModifyView
if(firstTime)
{
IWDTransparentContainer tc = (IWDTransparentContainer) view.getElement("container");
IWDCheckBox cb0 = (IWDCheckBox) view.createElement(IWDCheckBox.class, "cb_0");
IWDCheckBox cb1 = (IWDCheckBox) view.createElement(IWDCheckBox.class, "cb_1");
//IPrivateTestComponentView.IPersonElement personElement = (IPrivateTestComponentView.IPersonElement) wdContext.nodePerson().getElementAt(0);
cb0.bindChecked(wdContext.nodePerson().getNodeInfo().getAttribute("selected_0"));
cb0.bindText(wdContext.nodePerson().getNodeInfo().getAttribute("text_0"));
tc.addChild(cb0);
//personElement = (IPrivateTestComponentView.IPersonElement) wdContext.nodePerson().getElementAt(1);
cb1.bindChecked(wdContext.nodePerson().getNodeInfo().getAttribute("selected_1"));
cb1.bindText(wdContext.nodePerson().getNodeInfo().getAttribute("text_1"));
tc.addChild(cb1);
}
//@@end
}
Here I have used 1..1 cardinaltiy node and created all attributes dynamically.
Regards
Abhilash
Hi,
I think this link will help you to create dynamic context nodes.
[http://help.sap.com/saphelp_nw04/helpdata/en/89/73a840bd6d3c13e10000000a155106/frameset.htm]
Thanks & Regards
Fazal
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Why not just using a CheckBoxGroup?
CheckBoxGroup.texts -> Person.Text
void supplyPersons(IPersonNode node,...)
{
IPersonElement person;
person = node.createPersonElement();
node.addElement(person);
person.setText("John");
node.setSelected(person.index(), true);
/* etc. */
}
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
9 | |
7 | |
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.