cancel
Showing results for 
Search instead for 
Did you mean: 

How to add a new Element to the Context

Former Member
0 Kudos

Hello all.

I created in the wdInit()


ArrayList datas = new ArrayList();
	for (int i = 0; i < 25; i++) {
		
		MyData data = new MyData();
               ....
		data.setMethods();
               ....
		datas.add(data);
		
	}
	wdContext.nodeMyData().bind(datas);

Now, I want by clicking on the Button "Create new Element", forward user to the other View, which elements are connected with the same model -> context, the new element should be added to context, the user should fill the form and click Save-Button.

How can I add a new Element to the Collection I created and choose it as a current element?

If I do: wdContext.nodeMyData().bind(new MyData()) all information will be lost. And I will have only one field.

If I do it like this:


IWDNodeElement dynTabElem=(IWDNodeElement)wdContext.nodeMyData().createElement();
wdContext.nodeMyData().addElement(dynTabElem);

I get an error: com.sap.tc.webdynpro.progmodel.context.ContextException: NodeInfo(DataComp.MyData): value node is created without a reference

Well I can pass to my new View a Collection as a parameter and then

Collection.add(new MyData()) and then bind it. But I find this solution not good.

Is there any possibility to get the existing Collection from the Context without passing it to the view?

Can I just add a new element to the existing collection?

Thanks in advance.

Accepted Solutions (0)

Answers (1)

Answers (1)

monalisa_biswal
Contributor
0 Kudos

For model nodes you can't directly add elements to the node.

1>Take reference of parent model class.

<Parent Model Class> <ref>=wdContext.current<Parent Model Node>Element().modelObject();

2>Add elements to the collection>

<ref>.add<Collection Name>(new <SubNode Model class>());

3><invalidate model node>

wdContext.node<SubNode>().invalidate();

Former Member
0 Kudos

Hallo Monalisa,

I did as you said. But I can't add something to my model class, because it is not collection.


                        MyData data = wdContext.currentBelegElement().modelObject();
			data.add() ???? - don't work
			wdContext.nodeMyData().invalidate();

Former Member
0 Kudos

Alex,


MyData newData = new MyData();
/* Some setup for model object, optional
newData.setMethods();
*/
IWDNodeElement dynTabElem=(IWDNodeElement)wdContext.nodeMyData().createMyDataElement(newData);
wdContext.nodeMyData().addElement(dynTabElem);

Valery Silaev

SaM Solutions

http://www.sam-solutions.net