Bug 62589 - Creating of simple fields when writing DOCX doesn't work in current code
Summary: Creating of simple fields when writing DOCX doesn't work in current code
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 4.0.x-dev
Hardware: PC Mac OS X 10.1
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2018-07-31 15:28 UTC by Eliot Kimber
Modified: 2021-05-20 11:28 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Eliot Kimber 2018-07-31 15:28:28 UTC
When creating new DOCX the XWPFFieldRun class does not work to create paragraphs with CTSimpleFields.

The problem is that the field is not written out during commit. The current unit test only tests the read path but does not test the write path, which would fail.

I'm not sure what the right solution is (or I would have simply implemented it).

This code works:

CTSimpleField ctField = para.getCTP().addNewFldSimple();

So it's not a critical issue but it's definitely an annoyance in the API that you can't create simple fields directly.

I don't have time at the moment to puzzle through this so I was hoping somebody might have more cogent ideas about how best to address this in the API.

But my fear is that addressing this would require serious adjustment or extension to the internals of XWPFParagraph.

Ideally I'd like something like:

XWPFSimpleField field = para.createSimpleField("PAGE");
Comment 1 Mark Murphy 2018-07-31 16:09:35 UTC
This works and you can stick with the schema rather than dealing with cursors.

    XWPFParagraph p;


    CTP ctP = p.getCTP();
    CTSimpleField field = ctP.addNewFldSimple();
Comment 2 Mark Murphy 2018-08-01 01:02:48 UTC
I think I can fix this rather quickly.
Comment 3 Sayi 2021-05-20 11:28:24 UTC
This problem seems to have been resolved in the latest version, you can use the XWPFParagraph#createFieldRun method to create.