cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronize 2 components of same type

Former Member
0 Kudos

Hi,

I've build a basket component. I've used this component on 2 different tabs...which means i have to create 2 different instances. As you might suspect, the things in the basket are allways the same...so the basket components have to be synchronized. Is this possible?

You might also think that its much handier to have just 1 basket component....but they want to have 2 tabs which contain both the basket so i cannot re-use the view because this is a singleton.

anyone have any ideas?

much thanks,

Hugo Hendriks

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hugo,

Below is just theory, but anyway...

1. In inner component create 2 winbows

2. In outer component create single ComponentUsage of inner component

3. In outer component embed different windows of inner component on different tabs.

While usage is the same, data will be always synchronized. Oh, inner component views must use mapped context node. I mean, nodes mapped to context of component controller.

If this doesn't work, then do reverse context mapping:

1. In interface controller of inner component create node(s) with isInputElement set to true

2. In inner component views must be mapped to the nodes created in [1]

3. In outer component create 2 usages of inner component

4. In outer component create context nodes that holds data

5. Map context of component usage to node from [4] of outer component

While there is only one actual context node (in outer component) then there is always single source of truth and both component usages will stay in sync via mapping.

Valery Silaev

SaM Solutions

http:/www.sam-solutions.net

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo Valery,

your first approach of showing one single component instance in two different flavors by embedding separate component interface views/windows of it is very interesting. The advantage would be to define only one component usage.

But the problem of this approach is, that it only works for <b>disjoint view compositions</b> defined in window A and window B (comp interface views A and B) of this visual component. As soon as the same view instance is visible within window A and window B at the same time the Web Dynpro Runtime throws an exception.

Therefore your second alternative based on two component usages and external context mapping is the only feasible one.

Best regards, Bertram

Former Member
0 Kudos

Hi,

Just tested the first one, and as Bertram just told....it raises an exception. I'm trying the second option now..

Thanks both for schedding some light on this topic btw.

best regards,

Hugo

Former Member
0 Kudos

Hi Valery,

Im a bit confused at step 4 and 5 of your sollution.....Im quite new to inter-component context mapping....

<b>4. In outer component create context nodes that holds data</b>

Does this mean create the nodes in the outer controller view that contains both component-usages?

<b>5. Map context of component usage to node from [4] of outer component</b>

How do i map the context of the usage to the just created nodes in the outer controller view?

Much thanks,

Hugo

Former Member
0 Kudos

Hugo,

<i>4. In outer component create context nodes that holds data

Does this mean create the nodes in the outer controller view that contains both component-usages?</i>

You must create this node in <b>component controller</b> of outer component

<i>5. Map context of component usage to node from [4] of outer component

How do i map the context of the usage to the just created nodes in the outer controller view?</i>

In outer component structure tree expand node with usage and double-click on usage (or usage interface) node. WD should open dialog with usage properties / mapping. Add outer component as required controller to usage then on mapping tab perform mapping.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Former Member
0 Kudos

Valery,

Works perfectly....much thanks!

regards,

Hugo

Former Member
0 Kudos

oops, ok, stil have 2 more questions if thats ok?

In the inner component I have a downloadFile UI element. In the context of the view a downloadUrl which is a binary neccesary for the UIelement.

First question is that i cant set this attribute to isInputElement = true because its under the root. To fix this, do i just create a node and in the wdInit or do I have to something else because now i cannot map it?

Second question is that in the wdDoModify i have some code also for the downloadFile UI element to set the mime type:


	// get attribute info for context attribute 'FileResource'
	IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute(IPrivateBasketCompView.IContextElement.DOWNLOAD_URL);
	// create a modifiable binary type for the context attribute
	// which stores the MIME-object.
	IWDModifiableBinaryType binaryType =(IWDModifiableBinaryType) attributeInfo.getModifiableSimpleType();
	binaryType.setMimeType(WDWebResourceType.UNKNOWN);
	//create date/time stamp to incorporate into the name of the zip
	DateFormat dateFormatter = new SimpleDateFormat("ddMMyyyyHHmm");
	String fileName = "TPD-" + dateFormatter.format(Calendar.getInstance().getTime())+".zip";
	binaryType.setFileName(fileName);

but when i leave this code, i get an exception saying:must not modify the datatype of a mapped attribute

How do i solve this?

Thanks & regards,

Hugo

Former Member
0 Kudos

Hugo,

As with any mapping you may modify only original node but not mapped ones.

In your case (reverse context mapping) original node is one declared in outer component, and mapped are in inner component.

So just move your code that modifies simple type from inner to outer component.

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Valery,

thanks for that...seems that it works now.

regards,

Hugo

Former Member
0 Kudos

DownloadFile UI Element mapping errors

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo Hugo,

toplevel context attributes cannot be mapped externally. Read my last comment on this restriction within the SAP Online Help: http://help.sap.com/saphelp_nw2004s/helpdata/en/66/a5384162316532e10000000a1550b0/frameset.htm.

<i>Note that context attributes cannot be defined as “can be mapped externally later“ directly below the root node (top level context attribute) in the component interface content. External context mapping is possible only for those context attributes that belong to independent or dependent context nodes.</i>

Define an independent context node with cardinaltiy 1..1 instead and add the attribute there.

Regards, Bertram