FormFieldCollection
Inheritance: java.lang.Object
All Implemented Interfaces: java.lang.Iterable
public class FormFieldCollection implements Iterable
A collection of FormField objects that represent all the form fields in a range.
To learn more, visit the Working with Form Fields documentation article.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
///
/// Visitor implementation that prints details of form fields that it visits.
///
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
///
/// Called when a FormField node is encountered in the document.
///
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
///
/// Adds newline char-terminated text to the current output.
///
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
///
/// Gets the plain text of the document that was accumulated by the visitor.
///
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
Methods
Method | Description |
---|---|
clear() | Removes all form fields from this collection and from the document. |
get(int index) | Returns a form field at the specified index. |
get(String bookmarkName) | Returns a form field by bookmark name. |
getCount() | Returns the number of form fields in the collection. |
iterator() | Returns an enumerator object. |
remove(String formField) | Removes a form field with the specified name. |
removeAt(int index) | Removes a form field at the specified index. |
clear()
public void clear()
Removes all form fields from this collection and from the document.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
///
/// Visitor implementation that prints details of form fields that it visits.
///
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
///
/// Called when a FormField node is encountered in the document.
///
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
///
/// Adds newline char-terminated text to the current output.
///
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
///
/// Gets the plain text of the document that was accumulated by the visitor.
///
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
get(int index)
public FormField get(int index)
Returns a form field at the specified index.
Remarks:
The index is zero-based.
Negative indexes are allowed and indicate access from the back of the collection. For example -1 means the last item, -2 means the second before last and so on.
If index is greater than or equal to the number of items in the list, this returns a null reference.
If index is negative and its absolute value is greater than the number of items in the list, this returns a null reference.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
///
/// Visitor implementation that prints details of form fields that it visits.
///
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
///
/// Called when a FormField node is encountered in the document.
///
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
///
/// Adds newline char-terminated text to the current output.
///
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
///
/// Gets the plain text of the document that was accumulated by the visitor.
///
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
Parameters:
Parameter | Type | Description |
---|---|---|
index | int | An index into the collection. |
Returns: FormField - A form field at the specified index.
get(String bookmarkName)
public FormField get(String bookmarkName)
Returns a form field by bookmark name.
Remarks:
Returns null if the form field with the specified bookmark name cannot be found.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
///
/// Visitor implementation that prints details of form fields that it visits.
///
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
///
/// Called when a FormField node is encountered in the document.
///
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
///
/// Adds newline char-terminated text to the current output.
///
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
///
/// Gets the plain text of the document that was accumulated by the visitor.
///
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
Parameters:
Parameter | Type | Description |
---|---|---|
bookmarkName | java.lang.String | Case-insensitive bookmark name. |
Returns: FormField - A form field by bookmark name.
getCount()
public int getCount()
Returns the number of form fields in the collection.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
///
/// Visitor implementation that prints details of form fields that it visits.
///
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
///
/// Called when a FormField node is encountered in the document.
///
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
///
/// Adds newline char-terminated text to the current output.
///
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
///
/// Gets the plain text of the document that was accumulated by the visitor.
///
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
Returns: int - The number of form fields in the collection.
iterator()
public Iterator iterator()
Returns an enumerator object.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
///
/// Visitor implementation that prints details of form fields that it visits.
///
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
///
/// Called when a FormField node is encountered in the document.
///
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
///
/// Adds newline char-terminated text to the current output.
///
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
///
/// Gets the plain text of the document that was accumulated by the visitor.
///
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
Returns: java.util.Iterator
remove(String formField)
public void remove(String formField)
Removes a form field with the specified name.
Remarks:
If there is a bookmark associated with the form field, the bookmark is not removed.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
///
/// Visitor implementation that prints details of form fields that it visits.
///
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
///
/// Called when a FormField node is encountered in the document.
///
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
///
/// Adds newline char-terminated text to the current output.
///
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
///
/// Gets the plain text of the document that was accumulated by the visitor.
///
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
Parameters:
Parameter | Type | Description |
---|---|---|
formField | java.lang.String | The case-insensitive name of the form field to remove. |
removeAt(int index)
public void removeAt(int index)
Removes a form field at the specified index.
Remarks:
If there is a bookmark associated with the form field, the bookmark is not removed.
Examples:
Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.
public void visitor() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Use a document builder to insert a combo box.
builder.write("Choose a value from this combo box: ");
FormField comboBox = builder.insertComboBox("MyComboBox", new String[]{"One", "Two", "Three"}, 0);
comboBox.setCalculateOnExit(true);
Assert.assertEquals(3, comboBox.getDropDownItems().getCount());
Assert.assertEquals(0, comboBox.getDropDownSelectedIndex());
Assert.assertTrue(comboBox.getEnabled());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert a check box.
builder.write("Click this check box to tick/untick it: ");
FormField checkBox = builder.insertCheckBox("MyCheckBox", false, 50);
checkBox.isCheckBoxExactSize(true);
checkBox.setHelpText("Right click to check this box");
checkBox.setOwnHelp(true);
checkBox.setStatusText("Checkbox status text");
checkBox.setOwnStatus(true);
Assert.assertEquals(50.0d, checkBox.getCheckBoxSize());
Assert.assertFalse(checkBox.getChecked());
Assert.assertFalse(checkBox.getDefault());
builder.insertBreak(BreakType.PARAGRAPH_BREAK);
// Use a document builder to insert text input form field.
builder.write("Enter text here: ");
FormField textInput = builder.insertTextInput("MyTextInput", TextFormFieldType.REGULAR, "", "Placeholder text", 50);
textInput.setEntryMacro("EntryMacro");
textInput.setExitMacro("ExitMacro");
textInput.setTextInputDefault("Regular");
textInput.setTextInputFormat("FIRST CAPITAL");
textInput.setTextInputValue("New placeholder text");
Assert.assertEquals(TextFormFieldType.REGULAR, textInput.getTextInputType());
Assert.assertEquals(50, textInput.getMaxLength());
// This collection contains all our form fields.
FormFieldCollection formFields = doc.getRange().getFormFields();
Assert.assertEquals(3, formFields.getCount());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
Assert.assertEquals(3, doc.getRange().getFields().getCount());
Assert.assertEquals(" FORMDROPDOWN ", doc.getRange().getFields().get(0).getFieldCode());
Assert.assertEquals(" FORMCHECKBOX ", doc.getRange().getFields().get(1).getFieldCode());
Assert.assertEquals(" FORMTEXT ", doc.getRange().getFields().get(2).getFieldCode());
// Allow each form field to accept a document visitor.
FormFieldVisitor formFieldVisitor = new FormFieldVisitor();
Iterator fieldEnumerator = formFields.iterator();
while (fieldEnumerator.hasNext())
fieldEnumerator.next().accept(formFieldVisitor);
System.out.println(formFieldVisitor.getText());
doc.updateFields();
doc.save(getArtifactsDir() + "FormFields.Visitor.html");
}
///
/// Visitor implementation that prints details of form fields that it visits.
///
public static class FormFieldVisitor extends DocumentVisitor {
public FormFieldVisitor() {
mBuilder = new StringBuilder();
}
///
/// Called when a FormField node is encountered in the document.
///
public int visitFormField(FormField formField) {
appendLine(formField.getType() + ": \"" + formField.getName() + "\"");
appendLine("\tStatus: " + (formField.getEnabled() ? "Enabled" : "Disabled"));
appendLine("\tHelp Text: " + formField.getHelpText());
appendLine("\tEntry macro name: " + formField.getEntryMacro());
appendLine("\tExit macro name: " + formField.getExitMacro());
switch (formField.getType()) {
case FieldType.FIELD_FORM_DROP_DOWN:
appendLine("\tDrop down items count: " + formField.getDropDownItems().getCount() + ", default selected item index: " + formField.getDropDownSelectedIndex());
appendLine("\tDrop down items: " + String.join(", ", formField.getDropDownItems()));
break;
case FieldType.FIELD_FORM_CHECK_BOX:
appendLine("\tCheckbox size: " + formField.getCheckBoxSize());
appendLine("\t" + "Checkbox is currently: " + (formField.getChecked() ? "checked, " : "unchecked, ") + "by default: " + (formField.getDefault() ? "checked" : "unchecked"));
break;
case FieldType.FIELD_FORM_TEXT_INPUT:
appendLine("\tInput format: " + formField.getTextInputFormat());
appendLine("\tCurrent contents: " + formField.getResult());
break;
}
// Let the visitor continue visiting other nodes.
return VisitorAction.CONTINUE;
}
///
/// Adds newline char-terminated text to the current output.
///
private void appendLine(String text) {
mBuilder.append(text + '\n');
}
///
/// Gets the plain text of the document that was accumulated by the visitor.
///
public String getText() {
return mBuilder.toString();
}
private final StringBuilder mBuilder;
}
Parameters:
Parameter | Type | Description |
---|---|---|
index | int | The zero-based index of the form field to remove. |