Skip to content

Commit fe904bb

Browse files
committed
Added Changes to UserFormController.java to redirect error ot user.
1 parent 7f1d5bb commit fe904bb

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

api/src/main/resources/messages.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ legacyui.manageuser.providerAccount=Provider Account
66
legacyui.manageuser.createProviderAccount=Create a Provider account for this user
77
legacyui.manageuser.providerIdentfier=Provider Identifier(s):
88
legacyui.manageuser.noProviderIdentifier=No Identifier Specified
9-
9+
legacyui.manageuser.DemographicInfo.lengthExceeded=Error in Demographic Info fields. The maximum allowed length of each field is {0}.
1010
${project.parent.artifactId}.Location.purgeLocation=Permanently Delete Location
1111
${project.parent.artifactId}.Location.confirmDelete=Are you sure you want to delete this Location? It will be permanently removed from the system.
1212
${project.parent.artifactId}.Location.purgedSuccessfully=Location deleted successfully

omod/src/main/java/org/openmrs/web/controller/user/UserFormController.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,20 @@ public String handleSubmission(WebRequest request, HttpSession httpSession, Mode
270270
}
271271

272272
new UserProperties(user.getUserProperties()).setSupposedToChangePassword(forcePassword);
273-
274273
userValidator.validate(user, errors);
275-
274+
if (errors.hasErrors()) {
275+
List<FieldError> fieldErrorList = errors.getFieldErrors();
276+
for (FieldError fieldError : fieldErrorList) {
277+
String[] errorCodes = fieldError.getCodes();
278+
for (String value : errorCodes) {
279+
if (value.contains("error.exceededMaxLengthOfField")) {
280+
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"legacyui.manageuser.DemographicInfo.lengthExceeded");
281+
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ARGS, "50");
282+
return "redirect:/admin/users/user.form?userId=" + request.getParameter("userId");
283+
}
284+
}
285+
}
286+
}
276287
if (errors.hasErrors()) {
277288
response.setStatus(HttpStatus.BAD_REQUEST.value());
278289
return showForm(user.getUserId(), createNewPerson, user, model);

0 commit comments

Comments
 (0)