You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Dmitry Kochelaev <dk...@gmail.com> on 2011/04/24 13:31:53 UTC

Reloading elements after applying changes to children list

Hi everybody,

I'm using apache poi of version 3.7 to create docx files, or to be more
precise to modify existing documents.
I'm facing following issue: if I apply any change to children list (e.g.
list of XWPFRun for XWPFParagraph) I'm the list is not refreshed, yet the
changes are applied. For Instance:

I have XWPFParagraph par with 3 runs inside, so that:
par.getRuns().size(); //returns 3

then I add a new run at the end:
par.createRun();
par.getRuns.size(); //returns 3, however 4 is expected.

the same with rows in table, the same with deletion of runs in paragraph.

However, when I execute document.write(..); The modified content is saved
successfully.

So the question is: if it's possible to synchronize java representation, and
structure which lies underneath. Since as I can see (XWPFParagraph code):
public XWPFRun createRun() {
    return new XWPFRun(paragraph.addNewR(), this);  //paragraph is of type
CTP here
}
No changes are applied to runs list.

Lurking deeper in the code shows that for creating paragraphs inside table
cell additional actions are taken:
public XWPFParagraph addParagraph() {
    XWPFParagraph p = new XWPFParagraph(ctTc.addNewP(), this);
    addParagraph(p);
    return p;
}
public void addParagraph(XWPFParagraph p){
    paragraphs.add(p);
}

Should it be the same way all around?

--
 Best Regards,
 Dmitry Kochelaev

Re: Reloading elements after applying changes to children list

Posted by Dmitry Kochelaev <dk...@gmail.com>.
I've added new issues to bugzilla concerning this behavior: 51111, 51112,
51113


--
 Best Regards,
 Dmitry Kochelaev


On Sun, Apr 24, 2011 at 8:30 PM, Dmitry Kochelaev <dk...@gmail.com>wrote:

> This code samples were taken from source of library. So I'll create bugs in
> bugzilla and will attach my patches.
>
> As for insertNewRun it acts a little bit better. On XWPF level it inserts
> Run in the of the list and doesn't take position parameter in account. I'll
> send patch as well.
>
> --
>  Best Regards,
>  Dmitry Kochelaev
>
>
>
> On Sun, Apr 24, 2011 at 5:39 PM, Nick Burch <ni...@alfresco.com>wrote:
>
>> On Sun, 24 Apr 2011, Dmitry Kochelaev wrote:
>>
>>> I'm facing following issue: if I apply any change to children list (e.g.
>>> list of XWPFRun for XWPFParagraph) I'm the list is not refreshed, yet the
>>> changes are applied. For Instance:
>>>
>>
>> You need to make your changes at the XWPF level. If you change the
>> underlying CT objects, then you'll see the problem you've got of the XWPF
>> code not being aware of the underlying changes
>>
>>
>>  then I add a new run at the end:
>>> par.createRun();
>>> par.getRuns.size(); //returns 3, however 4 is expected.
>>>
>>
>> That ought to add it in. Can you open a new bug in bugzilla if it isn't?
>> Also, does insertRun behave properly?
>>
>> Nick
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
>> For additional commands, e-mail: user-help@poi.apache.org
>>
>>
>

Re: Reloading elements after applying changes to children list

Posted by Dmitry Kochelaev <dk...@gmail.com>.
This code samples were taken from source of library. So I'll create bugs in
bugzilla and will attach my patches.

As for insertNewRun it acts a little bit better. On XWPF level it inserts
Run in the of the list and doesn't take position parameter in account. I'll
send patch as well.

--
 Best Regards,
 Dmitry Kochelaev


On Sun, Apr 24, 2011 at 5:39 PM, Nick Burch <ni...@alfresco.com> wrote:

> On Sun, 24 Apr 2011, Dmitry Kochelaev wrote:
>
>> I'm facing following issue: if I apply any change to children list (e.g.
>> list of XWPFRun for XWPFParagraph) I'm the list is not refreshed, yet the
>> changes are applied. For Instance:
>>
>
> You need to make your changes at the XWPF level. If you change the
> underlying CT objects, then you'll see the problem you've got of the XWPF
> code not being aware of the underlying changes
>
>
>  then I add a new run at the end:
>> par.createRun();
>> par.getRuns.size(); //returns 3, however 4 is expected.
>>
>
> That ought to add it in. Can you open a new bug in bugzilla if it isn't?
> Also, does insertRun behave properly?
>
> Nick
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
>
>

Re: Reloading elements after applying changes to children list

Posted by Nick Burch <ni...@alfresco.com>.
On Sun, 24 Apr 2011, Dmitry Kochelaev wrote:
> I'm facing following issue: if I apply any change to children list (e.g. 
> list of XWPFRun for XWPFParagraph) I'm the list is not refreshed, yet 
> the changes are applied. For Instance:

You need to make your changes at the XWPF level. If you change the 
underlying CT objects, then you'll see the problem you've got of the XWPF 
code not being aware of the underlying changes

> then I add a new run at the end:
> par.createRun();
> par.getRuns.size(); //returns 3, however 4 is expected.

That ought to add it in. Can you open a new bug in bugzilla if it isn't? 
Also, does insertRun behave properly?

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org