cancel
Showing results for 
Search instead for 
Did you mean: 

CreateAndAddXXXElement on a Node that is mapped to a model

Former Member
0 Kudos

Say I have a context node that is created by mapping it from the Component, which in turn mapped form a model. When I call the CreateAndAddXXXElement() on this node, I will get an error saying:

model node element cannot be created without a model instance

What additional steps do I need before calling CreateAndAdd? CreateAndAddXXXElement() works fine with a node that is not mapped to a model.

Thanks.

Accepted Solutions (0)

Answers (4)

Answers (4)

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Robert

>What additional steps do I need before calling CreateAndAdd? CreateAndAddXXXElement() works fine with a node that is not mapped to a model.

When you have model node you will not have CreateAndAddXXXElement() method. For model nodes it'll be createXXXElement(<ModelClassName> model) method. So you cannot create model element without having model class instance, because you have to pass the model class instance to the createXXXElement(...) as input parameter. Model elements always bound to model instances. That's why you get such exception.

BR, Siarhei

Former Member
0 Kudos

Hi,

Your solution uses a node that has the same structure as the mapped node, but it is not mapped to any model class. This is exactly what my workaround is for now. I know this will work as your "DataSourceDownload" node is not mapped but you do need to copy the data over from the mapped node.

I want to find out what needs to be done to a mapped node in order for the CreateAndAdd to work too.

Thanks.

Former Member
0 Kudos

Hi Poojith,

In ur sample code, C is the model node, right? If true, I think I tried this but it still gives me the same error.

Here is what I did, I went ot the "context" tab of the view and find out what model class my view node is mapped to, then I do the following: Here Templates is a view node and Z_Template_HD_S is the modle class.

Z_Template_HD_S model = new Z_Template_HD_S();

wdContext.nodeTemplates().bind(model);

ITemplatesElement savedtemplate = wdContext.nodeTemplates().createAndAddTemplatesElement();

But it still gives me the same error on line 3.

Former Member
0 Kudos

Hi,

I tried the following and it works in my case.

	 Z<name> get_orders = new Z<name>();	
	 get_orders.addI_Data(input);
	 wdContext.nodeZ<name>t().bind(get_orders);
	
	 try {
		 wdContext.currentZ<name>().modelObject().execute();
	 } catch (WDDynamicRFCExecuteException e) {
		 // TODO Auto-generated catch block
		 e.printStackTrace();
		 wdComponentAPI.getMessageManager().reportWarning( "Error in executing get RFC");		
	 }
	
	WDCopyService.copyElements(wdContext.nodeZ<name>()
		.nodeOutput().nodeI_Data_Get(), wdContext.nodeDataSourceDownload().nodeTableOutput());	
	wdContext.nodeDataSourceDownload().nodeTableOutput().removeElement(wdContext.nodeDataSourceDownload().nodeTableOutput().
	getElementAt(0));

The last line of code is to remove an empty row at the beginning. The "DataSourceDownload" node serves as a source for the table in the view (mapped node).

Hope this helps...

former_member214651
Active Contributor
0 Kudos

Hi Robert,

Even after mapping is done, the data flows from the model to controller and to the view when u are getting the values.

But to create values, u need to first create an instance of the model Node and bind it and only after that u can insert values to it.

Eg; -

If ur Value Node is A and binded to B node of Controller which is binded to C which is a Value node then before inserting values to C u need to create an instance of C:

C <ObjectName> = new C;

wdcontext.node<RFCName>.bind(<objectName>);

Only then will the data gets copied to the model node, else it throws an error.

hope this helps u.

Regards,

Poojith MV