on 12-07-2007 6:26 AM
Dears,
I met a problem while studying the official tutorial "MasterDetail". The code in tutorial works well. I made a little modification to it, and got the exception as titled. I'm rather confused at the cause of the exception.
As you know, the scenario is that, the view context has node "Customer" (cardinality: 0..n; singleton: true), and the "Customer" has a child node "Address" (cardinality: 0..1; singleton: false).
My error occurs when: Adding Element "Address" to node "Customer".
The code in the turorial is something like that:
// Create and Bind Customer Element
IPrivateMasterDetailView.ICustomerElement newCustomerElement = wdContext.createCustomerElement();
newCustomerElement.setName(customerObj.getCustomerName());
wdContext.nodeCustomer().addElement(newCustomerElement);
// Create new Address Element
IPrivateMasterDetailView.IAddressElement addressElement = wdContext.createAddressElement();
addressElement.setAddress(customerObj.getAddress());
// Add AddressElement to CustomerNode
newCustomerElement.nodeAddress().addElement(addressElement);
My modification is just on the last sentence:
wdContext.nodeCustomer().currentCustomerElement().nodeAddress().addElement(addressElement);
The modification results the exception:
<b>com.sap.tc.webdynpro.progmodel.context.ContextException: Node(MasterDetailView.Customer.0.Address): must not add elements to a Node of cardinality 0..1 or 1..1</b>
I'm wondering, isn't "newCustomerElement" equals to "wdContext.nodeCustomer().currentCustomerElement()"?
Why is it allowed to add elements in the tutorial, but not in my code?
Thanks in advance.
Hi,
You can try this:
wdContext.nodeCustomerElement().getChildNode("Address", 0).addElement(addressElement);
Regards,
Kiran Chennapai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Ayyapparaj,
Thanks for your quick response.
Dear Kiran,
Thank you. your code works.
It seems I havn't made myself clear:
I'm not seeking a solution for a piece of code working well - the tutorial code works well.
I just want to know, what's the difference between the tutorial code and my code, and why this exception is thrown out?
Message was edited by:
gangtee gangtee
HI,
One thing we have to observe here..
Adding an element to a child without adding to Parent will throw this sort of Exception
If we use like in the tutorial.. It is first adding an element to the Parent <Custoemer>
But if you use
wdContext.nodeCustomer().currentCustomerElement().nodeAddress().addElement(addressElement);
Here No parent element will be created in this statement
so, we have to add child element <addressElement> to the parentelement <newCustomerElement> which is previously created
Regards
LakshmiNarayana
Dear LakshmiNarayana,
What I modify on the turorial code is just the last sentense:
from -->
<b>
newCustomerElement
</b>
.nodeAddress().addElement(addressElement);
to -->
<b>
wdContext.nodeCustomer().currentCustomerElement()
</b>
.nodeAddress().addElement(addressElement);
As you have seen in the former code,
wdContext.nodeCustomer().addElement(newCustomerElement);
Since an CustomerElement has been added to CustomerNode, in my opinion,
"<b>wdContext.nodeCustomer().currentCustomerElement()</b>" should return the "<b>newCustomerElement</b>" or something equivalent,
shouldn't it?
Hi gangtee,
<b>newCustomerElement</b> is an object of class <b>IPrivateMasterDetailView.ICustomerElement</b>. You can perform all functionality <b>[.setX(),.addX() etc.]</b> of <b>IPrivateMasterDetailView.ICustomerElement</b> for <b>newCustomerElement</b>. But <b>wdContext.nodeCustomer().currentCustomerElement()</b> is an element that is at lead selection. By creating and adding element to node does not set the lead selection. So, in this case <b>wdContext.nodeCustomer().currentCustomerElement()</b> returns <b>null</b>, since there is no element at lead selection.
Hope I have made it clear.
regards,
Siva
Message was edited by:
Siva Rama Krushna
Hi gangtee,
As you know to set the leadSelection we use node.setLeadSelection(int); Coming to your question wdContext.nodeCustomer().currentCustomerElement() should be handled with care. Generally we use in the table post Output oprations such as update/delete the selected element in table. It always throws an error if you use currenElement while creating even after the element is created and bound to the parent node.Once you start the node and element operations you will understand the cocepts gradually.
Best reagrds,
Siva
Hi Gangtee,
use "bind" method instead off "addElement" for node cardinality 0..1 or 1..1.
wdContext.nodeCustomer().currentCustomerElement().nodeAddress().bind(addressElement);
For 0..n node use code
wdContext.node<node_name>().addElement(wdContext.create<node_name>Element());
For 0..1 node use code.
wdContext.node<node_name>().bind(wdContext.create<node_name>Element());
Make sure cardinality of node Customer is 0..1 .
Regards,
Mithu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Just check the cardinality of the address node , is it 1..1
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
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.