I have a very strange error of password being displayed as label when form validation fails on other form elements (not the password input textbox itself). The code for the view is below.
<s:if test="%{username == null}">
<form method="post" enctype="multipart/form-data"
action="manageUser_create.action">
</s:if>
<s:else>
<form method="post" enctype="multipart/form-data"
action="manageUser_update.action">
</s:else>
<div>
<s:textfield name="firstName" key="First Name" cssClass="text-input" />
<br class="clear" />
<s:textfield name="lastName" key="Last Name" cssClass="text-input" />
<br class="clear" />
<s:file name="practiceLogo" id="practiceLogo" key="Upload Logo" cssClass="text-input" />
<br class="clear" />
<s:if test="%{username == null}">
<s:textfield name="username" id="username" key="Username" cssClass="text-input" />
<br class="clear" />
</s:if>
<s:else>
<s:hidden name="username"></s:hidden>
</s:else>
<s:password name="password" key="Password" cssClass="text-input" />
<br class="clear" />
<s:textfield name="email" cssClass="text-input" key="Email Address" />
<br class="clear" />
<s:textfield name="replyToEmail" key="Reply To Email" cssClass="text-input" />
<br class="clear" />
<s:submit align="center" value="Save" id="submitButton" cssClass="btn btn-primary" />
</div>
</form>
The action uses annotation for validation as below –
@Validations(requiredStrings = {
@RequiredStringValidator(type = ValidatorType.FIELD, shortCircuit=true, fieldName = "firstName", key = "opd.error.name.required"),
@RequiredStringValidator(type = ValidatorType.FIELD, shortCircuit=true, fieldName = "lastName", key = "opd.error.name.required"),
@RequiredStringValidator(type = ValidatorType.FIELD, shortCircuit=true, fieldName = "username", key = "opd.error.username.required"),
@RequiredStringValidator(type = ValidatorType.FIELD, shortCircuit=true, fieldName = "password", key = "opd.error.password.required"),
@RequiredStringValidator(type = ValidatorType.FIELD, shortCircuit=true, fieldName = "email", key = "opd.error.email.required"),
@RequiredStringValidator(type = ValidatorType.FIELD, shortCircuit=true, fieldName = "replyToEmail", key = "opd.error.email.required")
},
emails = {
@EmailValidator(type = ValidatorType.FIELD, shortCircuit=true, fieldName = "email", key = "opd.error.email.format"),
@EmailValidator(type = ValidatorType.FIELD, shortCircuit=true, fieldName = "replyToEmail", key = "opd.error.email.format")})
public String update() {
When I don’t enter password, the validation fails just like it should and then I see the correct message above the Password label and textbox. This works fine.
What does not work is if I enter password but leave out something else, like reply to email. Instead of the Password label being display, the password itself gets displayed where it should say “Password:”. For example, if the password is abcd, then abcd gets displayed as a label.
EDIT
This seems like a serious bug. If the attribute “key” of password is changed to anything other than Password or password, it gets displayed as the label.
Struts 2 version: 2.2.1
I found the workaround.
Using the attribute “label” instead of “key” in the Password field fixes this issue.
So
needs to be changed to
Seems very strange though because all other fields work with key.