Page 1 of 1

New content has no parent.

PostPosted: Tue Dec 18, 2012 10:44 pm
by garyg
Hi,

I'm adding a new paragraph (P) to a body (B). Later I need to go get that paragraph because I am inserting another paragraph after it, but before the next paragraph. So finding it's position int he parent is key.

However, for newly added content it appears there is no parent? Simple code as follows results in "NULL" being returned from newParagraph.getParent():

(in this example I have retreived paragraph - an instance of P - via some traversing.
Code: Select all
Body b= (Body)paragraph.getParent();
P newParagraph = new P();
b.add(newParagraph);
//do a bunch of stuff and lose position of newParagraph (many new paragraphs added in the real code)
Body b=(Body)newParagraph.getParent(); //This results in NULL


Thanks.

Re: New content has no parent.

PostPosted: Tue Dec 18, 2012 11:44 pm
by jason
That's true (the XJC parent pointer plugin didn't generate the code you are looking for), however, after b.add(newParagraph), you could just manually do newParagraph.setParent(b); the interface is there on the objects.