cancel
Showing results for 
Search instead for 
Did you mean: 

Context Mapping problem

Former Member
0 Kudos

Hello,

I want to program following scenario.

Child component which uses Model (component with manual lifecycle). I want to Child automatically to enter its Model usage to referencing mode ... which points to usage of Model in Parent component.

I do this.

Parent Component:

- lifecycle of Model is set to manual.

- Parent component create Component of Model usage

- stores Usage reference in its context

- then use external mapping to get data to child component

Child component:

- data in interface controller are mapped to component controller and then accessed

So, and here comes problem: Null pointer exception in accessing context, its caused because of:

wdContext.currentNodeElement() returns null

So I realized that mapping is not yet finished.

I try to do that in Custom Controller, but at my surprise it seems that the code of custom controller was not even called.

Everything works only if I map that node also to view.

But I dont want that data in view contexts.

I only need to now how can I get to component input data during his creation, data which can be accessed in wdDoInit of Component controller.

Thanks for help

Best regards,

Miroslav Koskar

Accepted Solutions (1)

Accepted Solutions (1)

hschaefer123
Participant
0 Kudos

Hi Miroslav,

i figured out the same problems. At the moment my only solutions is the following:

In the ChildInterfaceController i added method

doPostInit() {
  wdThis.wdGetChildCompController().postInit();
}

In the ChildComponentController i added the method

doPostInit() {
  // code that normally would stay in wdDoInit()
}

In the Parent Controller i'm doing something like

wdDoInit() {
wdThis.wdGetChildCompInstanceInterfaceComponentUsage().createComponent();
wdThis.wdGetChildCompInstanceInterfaceInterface().doPostInit();
}

This solution seems to work.

In the doPostInit() the mapped external context was successfully initialized.

Also following view inits wdDoInit() are called right after the doPostInit() of the component controller.

Hint:

Make sure, that the LifeCycle of the embedded component is "manual".

I don't know when "createOnDemand" is triggered.

-


I think this is a bug of Web Dynpro.

Maybe a core SAP Web Dynpro developer can give a statement on this strange behavior of external mapped context, cause all entries concerning this topic only reference the use of mapped context from inside the view (like the sap.help example).

Best regards,

Holger Schaefer

Message was edited by: Holger Schaefer

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Miroslav

For the external mapping only two things are required

1: Propert isInputElement for the node of Interface controller of child set to be true

2. Parent component should define child component as used Web DynPro component.

Then you map the context of child's Interface controller with the parents Component controller by dragging the context of child's Interface controller to the parent's component controller.

You need not to map from child's Interface controller to the child's component controller.

and please use cardinality as required.

Former Member
0 Kudos

Hi Sandeep,

"Then you map the context of child's Interface controller with the parents Component controller by dragging the context of child's Interface controller to the parent's component controller."

Where do you define this mapping?I think you have to do this in the interface controller of the used components,where you also add the parent component in the list of required controllers,right?

I have tried this ,but I cannot drag and drop the source to the target.is that a problem with the IDE.

Does anyone know ,of any alternatives to do the mapping ?

Former Member
0 Kudos

Hi Sourav,

No you are thinking it in a wrong way

suppose you have a child component called chComponent and parent component as prComponent.

1 You have to make the property isInputElement for chComponent interface controller root node as "True

2 in PrCopmonent define chComponent as used Web Dynpro Component.

3 in PrComponent double click on PrComponent, now create a data link between chComponent Interface controller to component Controller and drag n drop node from right to left i.e. from chComponent Interface controller to component controller.

hope this ll help you for any doubt feel free to contact

regards

Sandeep

Former Member
0 Kudos

Hi Sandeep,

I get you and I am doing setp1 and step 2 correctly.

In step3 the problem is I am not able to do the drag and drop from right to left,neither do I get any option(right click)to map the child context to the parent context.

The only option I get is create a node in the left panel(parent) and map it to the context of the used child in the right.

But then it wont be the correct mapping I guess.

Best regards

Sourav

Former Member
0 Kudos

Hi Sourav

In Case of External Mapping both Interface controller of child component and Component controller of Parent controller should have node for mapping. So you have to create a node in left panel i.e. in the component controller then drag the node from right to map it.

go ahead it will solve your problem

Regards

Sandeep

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo Miroslav,

do not mix two independant solutions for feeding child components with data from a model component based on context mapping.

<b>Solution A (Referencing Mode): </b>

UI components define own usages to the model component.

UI components enter model component usage of root component in referencing mode.

UI component contexts are mapped to the model component interface context

This solution requires no external context mapping!

<b>Solution B (External Context Mapping): </b>

UI components do not define own usages to the model component.

UI component interface contexts are externally mapped to the model component interface context (defined in the parent or root component)

This solution requires external context mapping!

Back to your specific issue. Yes, the Web Dynpro Java Runtime has a problem (you might name it bug) with setting up context mapping chains accross multiple component borders <b>befor </b>initializing the envolved controller instances and befor invoking the wdDoInit() hook methods. Therefor you might get a NullPointerException when accessing the mapped context in the wdDoInit() method of a child component.

<b>Workaround</b>

Instead of accessing mapped "child" contexts in the wdDoInit() hook method you must postpone or delay this access to a point of time after all controller instances were created by the Web Dynpro Runtime and after the context mapping chains were completely set up. This can be achieved with interface method invocation:

Root Component > Interface View Controller > startup plug eventhandler(): invoke method doPostInit() in component interface controller of used child UI components.

Access mapped context in doPostInit() method of a child UI component controller (the component interface controller delegates to).

Best regards, Bertram

Former Member
0 Kudos

Hi Bertram,

I donot fully get the last part of the solution that you provide as a workaround.

"<i>Root Component > Interface View Controller > startup plug eventhandler(): invoke method doPostInit() in component interface controller of used child UI components</i>."

I have my WD component compA which decalres comp B as the <i>Used Components</i>.

Now in the controller of compA I decalred my source ContextA and mapped it to the target ContextB of used component compB.

Now from compA I invoke a method doPostInit() in used compB(after the wdDoInit hook method of compA).

Not sure what to do after that.

I expect that once I have done the mapping.I fill up my source contextA in compA and the data is available in contextB of compBthrough external mapping.

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Sourav,

when you map a context in the parent comp to an interface context in the used child component you do not define an external context mapping relation. That's normal context mapping as the data context resides in the child component.

In case you access the context in the wdDoInit() method a parent component's controller class you get a NullPointerException too. In this case you must invoke a public method of the parent component's controller class (non-view controller like custom or component controller) inside the startup plug event handler of the root component's default view.

Regards, Bertram

Former Member
0 Kudos

> Hi Sourav,

>

> when you map a context in the parent comp to an

> interface context in the used child component you do

> not define an external context mapping relation.

> That's normal context mapping as the data context

> resides in the child component.

>

> In case you access the context in the wdDoInit()

> method a parent component's controller class you get

> a NullPointerException too. In this case you must

> invoke a public method of the parent component's

> controller class (non-view controller like custom or

> component controller) inside the startup plug event

> handler of the root component's default view.

>

> Regards, Bertram

Hi Bertram,

Sorry but i am really confused now.

My scenario is that

1)I have a WebDynpro component Interface InfA having contxtA(inputElement=true)

2)InfA is implemented by compC so the context(contxtA) is available for mapping in compC.

3)Now the data in the contexts are filled by compB which uses the interface infA as a used component.So the "source" for the data is the context in compC and this

context is mapped to context of the Interface controller infA through external context mapping,please correct me if am wrong.

Now i have done the mapping at design time but when does the mapping get completed?

Do I call a doInit() in the child component?(I ahve done that already)

Because whenevr in the paarent comp compB I try to fill data in the Context nodes I am getting this null pointer error.

Best regards

Sourav

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Sourav,

as I understand your scenario your data context resides in the child component and the parent component context is mapped to the child component's interface context.

Now you fill the data context outside the child component in the parent component which maps to the child component context. This is a contradictory approach. The child component should populate the data context itself and the parent component should then consume this data via context mapping. But it should not populate this context initially.

Instead you should define a supply function inside the child component to populate the child component's data context intially.

Or there is a misunderstanding, this means your child component does not contain the data context but externally maps to it in the parent component. What's true now?

Regards, Bertram

Former Member
0 Kudos

Hi Bertram,

Sorry for the misunderstanding,But the scenario is :

The parent component uses the child component interface,the child component has the context.

Now I want to fill data to child's context from the parent,so the parents context acts as the source node for the data and the data is then available in any component which implements this interface.

So I believe I have to define an external mapping from parent component(source) to child component(target).

Now my question is ,is it possible to define a mapping with parent component context as the source and child as the target in the interface controller editor?

I could not define a mapping from parent context to used componenet context in the editor.

Regards

Sourav

Message was edited by:

Sourav Chatterjee

Former Member
0 Kudos

Hai,

Try to write the same code in

wdModifyView(){

if(firsttime){

//paste the code in wdDoinit here

}

}

it will solve the problem. and also the code pasted above is also called only once.

regards,

Sunil

hschaefer123
Participant
0 Kudos

Hi Sunil,

the problem resists only insisde the controller.

The external context mapping feature works well for the view, but not for the controller.

You do not need the

wdModifyView()

.

Best wishes,

Holger

Former Member
0 Kudos

Hi Holger,

I have the same problem with external context mapping and I have done the steps as you mentioned,but I did not get this part:

"In the ChildInterfaceController i added method

doPostInit() {

wdThis.wdGetChildCompController().postInit();

}"

I understand you add the method doPostInit() in your interface.But where do you add the line?

wdThis.wdGetChildCompController().postInit();

Do you add this in the controller of the child component?I dont think that is possible.

I did not add this line in my child compoenent.Maybe thats why I still get the null pointer error in my parent component.

Also,is there any alternate solution available to this workaround this day?

Thanks in advance.

Regards

Sourav

Former Member
0 Kudos

Hi,

What is the cardinality of your node? Change it to 1...n unless it is already so.

Regards,

Satyajit.

Former Member
0 Kudos

Hi Satyajit,

Thanks for reply.

Yes, I've already tried that, set Node cardinality to 1..1

But no success. Still cant access mapped context data in component controller wdDoInit() method.

Has anyone idea in which order WD framework creates inner component controllers ? and when the mapping is established ?

Thanks,

Regards, Miroslav Koskar

Yashpal
Active Contributor
0 Kudos

Hi Miroslav,

U want to pass data to child component ...

so in interface contoller make the node u want and set the isInputElement property to true for all nodes ...

then in the embedder component fill the data in the component contoller and declare the usage of the child component and then add the interface contoller of child in the properties of parent compo.....map the nodes u want to from the parent to the child ......

hope this help..

Regards,

Yash

Former Member
0 Kudos

Hi Miroslav,

Did the solution proposed by Yash work? Iam also facing similar issue. Tried the solution, it still fails to map the interface controller contexts of the used DC to my DC component context.

Thanks,

Dhanya