on 04-27-2007 10:20 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
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);
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
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
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
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.