public class FieldUserName extends Field
To learn more, visit the Working with Fields documentation article.
Remarks:
Retrieves the current user's name.
Examples:
Shows how to use the USERNAME field.
Document doc = new Document();
// Create a UserInformation object and set it as the source of user information for any fields that we create.
UserInformation userInformation = new UserInformation();
userInformation.setName("John Doe");
doc.getFieldOptions().setCurrentUser(userInformation);
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a USERNAME field to display the current user's name,
// taken from the UserInformation object we created above.
FieldUserName fieldUserName = (FieldUserName) builder.insertField(FieldType.FIELD_USER_NAME, true);
Assert.assertEquals(userInformation.getName(), fieldUserName.getResult());
Assert.assertEquals(" USERNAME ", fieldUserName.getFieldCode());
Assert.assertEquals("John Doe", fieldUserName.getResult());
// We can set this property to get our field to override the value currently stored in the UserInformation object.
fieldUserName.setUserName("Jane Doe");
fieldUserName.update();
Assert.assertEquals(" USERNAME \"Jane Doe\"", fieldUserName.getFieldCode());
Assert.assertEquals("Jane Doe", fieldUserName.getResult());
// This does not affect the value in the UserInformation object.
Assert.assertEquals("John Doe", doc.getFieldOptions().getCurrentUser().getName());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.USERNAME.docx");
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getUserName()
Gest or sets the current user's name.
|
void |
setUserName(java.lang.String value)
Gest or sets the current user's name.
|
getDisplayResult, getEnd, getFieldCode, getFieldCode, getFormat, getLocaleId, getResult, getSeparator, getStart, getType, isDirty, isDirty, isLocked, isLocked, needStoreOldResultNodes, remove, setLocaleId, setResult, unlink, update, updatepublic java.lang.String getUserName()
Examples:
Shows how to use the USERNAME field.
Document doc = new Document();
// Create a UserInformation object and set it as the source of user information for any fields that we create.
UserInformation userInformation = new UserInformation();
userInformation.setName("John Doe");
doc.getFieldOptions().setCurrentUser(userInformation);
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a USERNAME field to display the current user's name,
// taken from the UserInformation object we created above.
FieldUserName fieldUserName = (FieldUserName) builder.insertField(FieldType.FIELD_USER_NAME, true);
Assert.assertEquals(userInformation.getName(), fieldUserName.getResult());
Assert.assertEquals(" USERNAME ", fieldUserName.getFieldCode());
Assert.assertEquals("John Doe", fieldUserName.getResult());
// We can set this property to get our field to override the value currently stored in the UserInformation object.
fieldUserName.setUserName("Jane Doe");
fieldUserName.update();
Assert.assertEquals(" USERNAME \"Jane Doe\"", fieldUserName.getFieldCode());
Assert.assertEquals("Jane Doe", fieldUserName.getResult());
// This does not affect the value in the UserInformation object.
Assert.assertEquals("John Doe", doc.getFieldOptions().getCurrentUser().getName());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.USERNAME.docx");
String value.public void setUserName(java.lang.String value)
throws java.lang.Exception
Examples:
Shows how to use the USERNAME field.
Document doc = new Document();
// Create a UserInformation object and set it as the source of user information for any fields that we create.
UserInformation userInformation = new UserInformation();
userInformation.setName("John Doe");
doc.getFieldOptions().setCurrentUser(userInformation);
DocumentBuilder builder = new DocumentBuilder(doc);
// Create a USERNAME field to display the current user's name,
// taken from the UserInformation object we created above.
FieldUserName fieldUserName = (FieldUserName) builder.insertField(FieldType.FIELD_USER_NAME, true);
Assert.assertEquals(userInformation.getName(), fieldUserName.getResult());
Assert.assertEquals(" USERNAME ", fieldUserName.getFieldCode());
Assert.assertEquals("John Doe", fieldUserName.getResult());
// We can set this property to get our field to override the value currently stored in the UserInformation object.
fieldUserName.setUserName("Jane Doe");
fieldUserName.update();
Assert.assertEquals(" USERNAME \"Jane Doe\"", fieldUserName.getFieldCode());
Assert.assertEquals("Jane Doe", fieldUserName.getResult());
// This does not affect the value in the UserInformation object.
Assert.assertEquals("John Doe", doc.getFieldOptions().getCurrentUser().getName());
doc.updateFields();
doc.save(getArtifactsDir() + "Field.USERNAME.docx");
value - The corresponding String value.java.lang.Exception