cancel
Showing results for 
Search instead for 
Did you mean: 

external context mapping problem

Former Member
0 Kudos

Hi,

I am trying to create a sample application for external context mapping

1. I created a webdynpro project.

2. In that project i created 2 web dynpro components PrComp and ChComp.

3. In the ChComp Interface controller context created a node MappedNode with attribute text.The node property isInputElement is set to true and also the carinality to 0..1

4. Added the ChComp as Used Component for PrComp.

5. Mapped the context of the ChComp Interface controller to ChComp Component controller and PrComp component Controller.

6. In the ChComp Component controller, i initialize the node atribute text with some value.

public void wdDoInit()

{

//@@begin wdDoInit()

wdContext.currentMappednodeElement().setMappedText("Mapped Attribute");

//@@end

}

7. In the PrComp component controller i create the ChComp and try to retrieve the value of the node attribute text.

public void wdDoInit()

{

//@@begin wdDoInit()

wdThis.wdGetChildCompComponentUsage().createComponent();

String text = wdContext.currentMappednodeElement().getMappedText();

wdComponentAPI.getMessageManager().reportSuccess("mapped value "+text);

//@@end

}

When i deploy and run the application i get the following error

java.lang.NullPointerException

at com.sap.tc.ram.sample.external.context.mapping.ChComp.wdDoInit(ChComp.java:98)

I am creating this app as a sample for external context mapping.please tell me if i am doing the rigth thing.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Shiram,

Your code will not work until you remove any node access from wdDoInit in ChComp (step 6).

Think about the actual execution sequence:

1. PrComp creates usage of child (ChComp) via createComponent

2. ChComp get initialized internally by WD framework, as part of process ChComp.wdDoInit is invoked

3. Context mapping is applied parent(source) <->child(target)

So step [2] happens always before [3], you didn't alter this behavior via cardinality as suggested by other readers.

What you can to do?

1. Do not use wdDoInit of ChComp to populate / access data. Populate data from PrComp instead.

2. Do you really need isInputElement? Think about it. If you remove isInputElement setting in child, then create mapped node in parent, then node in child will be source of data and you may safely populate it ChComp.wdDoInit.

And, as other pointed out, cardinality still can cause error -- you are using 0..* but not creating element manually. Either set cardinality to 1..* or create element in wdDoInit of "source" controller (PrComp for [1], ChComp for [2])

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Answers (2)

Answers (2)

abhijeet_mukkawar
Active Contributor
0 Kudos

hi,

this is because, you are refering the element which has not been created yet,

make the cardinality of node 1.1 or 1.n

it wont give error

regards

Former Member
0 Kudos

Hi ,

Is the node initialized in PrComponent ? You have to first create a node element and then append it using add element before accesssing elements using "currentElement"..

Or simpler.. make the cardinality as 1..1 or 1.n .. it would create an element by default. .

Regards

Bharathwaj

Former Member
0 Kudos

Hi,

the cardinality of my node in ChComp interface controller context is 1..n

but still i am getting the same error.

abhijeet_mukkawar
Active Contributor
0 Kudos

Hi Shriram,

do one thing, first initialise in parent and then try to see or access the value in

child, since you might be going against the flow of external context mapping

wdThis.wdGetChildCompComponentUsage().createComponent();

what is this above line for,

have you mapped the childs interface controller to parents component by going into

used web dynpro compo-><childUsage name>-interface controller->edit mapping->here select the parents component,

also check the <b>parents nodes cardinality</b>.

let me know if you face problem

regards

Former Member
0 Kudos

Hi,

Please read my message again.. Check the node cardinality in PrCompoenent.. and not in ChComponent.. !

Regards

Bharathwaj

abhijeet_mukkawar
Active Contributor
0 Kudos

have you solved your problem ?

Former Member
0 Kudos

Hi,

The cardinality of the node in the PrComp is 1..n.

@ Abhijeet,

Since the ChComp lifecycle is Manual,

I am creating the ChComp in the PrComp component controller using the component usage.

Since the ChComp is added as Used Component to PrComp, the interface controller of the ChComp is avalible to PrComp.

abhijeet_mukkawar
Active Contributor
0 Kudos

Hi,

yeah perfectly fine,

but while getting executed parent component must be getting called first and then childs, so parents must not be getting any value of child...since we are reading it before it gets initialised

just have a check on this

regards

Former Member
0 Kudos

Hi Abhijeet,

even i thought on the same line and there fore I canged the code in parent component

wdComponentAPI.getMessageManager().reportSuccess("Inside parent comp controller");

wdContext.currentMappednodeElement().setMappedText("Attribute value");

wdThis.wdGetChildCompComponentUsage().createComponent();

wdComponentAPI.getMessageManager().reportSuccess("mapped value");

and in wdDoInt of child component controller i have code as

String text = wdContext.currentMappednodeElement().getMappedText();

wdComponentAPI.getMessageManager().reportSuccess("Inside Child Comp Controller "+text);

abhijeet_mukkawar
Active Contributor
0 Kudos

Hi,

i checked personally, it throws same error like what you got initially if i initialise node in child and try to read that in parent.

error lies over their , just swap the position of initialisation and reading , build properly and deploy.

it should work

regards

Former Member
0 Kudos

Hi Abhijeet,

I used the Message manager to check the flow of webdynpro application.

From the PrComp Component Controller ---> ChComp Interface Controller ---> ChComp Component Controller --> back to PrComp Component Controller -- > wdDoInit of PrComp View

So initialisation in ChComp Component Controller should be possible.

Initializing the node attribute does not work in either component controller.

So i tried changing the Node cardinality in ChComp Interface controller to 0..n and in wdDoInit of Interface Controller added the following code

IWDNode node= wdContext.nodeMappednode();

IWDNodeElement ele = wdContext.nodeMappednode().createMappednodeElement();

node.addElement(ele);

wdContext.currentMappednodeElement().setMappedText("mapped attribute value");

But when i run the app follwoing error is thrown

<b>com.sap.tc.webdynpro.progmodel.context.ContextException: MappedNodeInfo(ChildCompInterface.mappednode): cannot create nodes, no mapping defined ye</b>t

abhijeet_mukkawar
Active Contributor
0 Kudos

Hi Shriram,

i doubt if it will work,

since the child node has no way to know who is acting as its mapped origin till it reaches the parent component.

Since child component has no way to who is mapped origin and parent component has know way whom it has mapped till both the component gets initialised , initialisation in init() is not possible.

if the same code you put in view's init(), it gotta work. i havent checked but it has to work , because by that time the initialisation of both child and parent compoent is over.

hope it will help

regards

abhijeet_mukkawar
Active Contributor
0 Kudos

Hi,

also one thing, the whole fuss is happening just because you are creating the component manually,

if you make its life as createOnDemand, the error we are getting due to initialisation in init() wont come.

because when you create child in parent, the control first goes to child's init(), if it is mapped to custom controller then control wil go to custom controller and then finally it will come back to main component.

if its life is CreateOnDeman, the childs component will get executed even after the initialisation of views in main component.

hope it helps

regards