public class FieldComments extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Retrieves, and optionally sets, the comments relating to the current document, as recorded in the BuiltInDocumentProperties.getComments() / BuiltInDocumentProperties.setComments(java.lang.String) property of the built-in document properties.
Examples:
Shows how to use the COMMENTS field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set a value for the document's "Comments" built-in property.
doc.getBuiltInDocumentProperties().setComments("My comment.");
// Create a COMMENTS field to display the value of that built-in property.
FieldComments field = (FieldComments) builder.insertField(FieldType.FIELD_COMMENTS, true);
field.update();
Assert.assertEquals(" COMMENTS ", field.getFieldCode());
Assert.assertEquals("My comment.", field.getResult());
// If we give the COMMENTS field's Text property value and update it, the field will
// overwrite the current value of the "Comments" built-in property with the value of its Text property,
// and then display the new value.
field.setText("My overriding comment.");
field.update();
Assert.assertEquals(" COMMENTS \"My overriding comment.\"", field.getFieldCode());
Assert.assertEquals("My overriding comment.", field.getResult());
doc.save(getArtifactsDir() + "Field.COMMENTS.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getText()
Gets the text of the comments.
|
void |
setText(java.lang.String value)
Sets the text of the comments.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic java.lang.String getText()
Examples:
Shows how to use the COMMENTS field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set a value for the document's "Comments" built-in property.
doc.getBuiltInDocumentProperties().setComments("My comment.");
// Create a COMMENTS field to display the value of that built-in property.
FieldComments field = (FieldComments) builder.insertField(FieldType.FIELD_COMMENTS, true);
field.update();
Assert.assertEquals(" COMMENTS ", field.getFieldCode());
Assert.assertEquals("My comment.", field.getResult());
// If we give the COMMENTS field's Text property value and update it, the field will
// overwrite the current value of the "Comments" built-in property with the value of its Text property,
// and then display the new value.
field.setText("My overriding comment.");
field.update();
Assert.assertEquals(" COMMENTS \"My overriding comment.\"", field.getFieldCode());
Assert.assertEquals("My overriding comment.", field.getResult());
doc.save(getArtifactsDir() + "Field.COMMENTS.docx");
public void setText(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to use the COMMENTS field.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set a value for the document's "Comments" built-in property.
doc.getBuiltInDocumentProperties().setComments("My comment.");
// Create a COMMENTS field to display the value of that built-in property.
FieldComments field = (FieldComments) builder.insertField(FieldType.FIELD_COMMENTS, true);
field.update();
Assert.assertEquals(" COMMENTS ", field.getFieldCode());
Assert.assertEquals("My comment.", field.getResult());
// If we give the COMMENTS field's Text property value and update it, the field will
// overwrite the current value of the "Comments" built-in property with the value of its Text property,
// and then display the new value.
field.setText("My overriding comment.");
field.update();
Assert.assertEquals(" COMMENTS \"My overriding comment.\"", field.getFieldCode());
Assert.assertEquals("My overriding comment.", field.getResult());
doc.save(getArtifactsDir() + "Field.COMMENTS.docx");
value - The text of the comments.java.lang.Exception