cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Creation of Context Nodes

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

In any case Naga,

the changes you highlighted don't work.

If I set the first checkbox to true (i.e. it's checked) and the second to false (i.e. it's not checked) then both are checked at runtime.

So there's still something wrong in it?

Former Member
0 Kudos

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

former_member182294
Active Contributor
0 Kudos

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

Answers (2)

Answers (2)

former_member201361
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Well basically it's a set of checkboxex which shouldn't group together since they don't refer to homogeneous elements.

Can any of you see the reason why the code at hand doesn't run as expected?

Cheers!

Former Member
0 Kudos

Yes, I see why the code is wrong. But I don't see the reason why you don't use a CheckBoxGroup because your code adds the check boxes one after the other into the same container.

Armin

Former Member
0 Kudos

Hi Armin,

well, I'll try and make use of a checkbox group. But anyway, for the sake of argument, what would be the problem with the code provided?

Thanks.

Marco