Skip to content

Commit

Permalink
Added Changes to UserFormController.java to redirect error ot user.
Browse files Browse the repository at this point in the history
  • Loading branch information
Parth59 committed Jul 9, 2021
1 parent 7f1d5bb commit fe904bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ legacyui.manageuser.providerAccount=Provider Account
legacyui.manageuser.createProviderAccount=Create a Provider account for this user
legacyui.manageuser.providerIdentfier=Provider Identifier(s):
legacyui.manageuser.noProviderIdentifier=No Identifier Specified
legacyui.manageuser.DemographicInfo.lengthExceeded=Error in Demographic Info fields. The maximum allowed length of each field is {0}.
${project.parent.artifactId}.Location.purgeLocation=Permanently Delete Location
${project.parent.artifactId}.Location.confirmDelete=Are you sure you want to delete this Location? It will be permanently removed from the system.
${project.parent.artifactId}.Location.purgedSuccessfully=Location deleted successfully
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,20 @@ public String handleSubmission(WebRequest request, HttpSession httpSession, Mode
}

new UserProperties(user.getUserProperties()).setSupposedToChangePassword(forcePassword);

userValidator.validate(user, errors);

if (errors.hasErrors()) {
List<FieldError> fieldErrorList = errors.getFieldErrors();
for (FieldError fieldError : fieldErrorList) {
String[] errorCodes = fieldError.getCodes();
for (String value : errorCodes) {
if (value.contains("error.exceededMaxLengthOfField")) {
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"legacyui.manageuser.DemographicInfo.lengthExceeded");
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ARGS, "50");
return "redirect:/admin/users/user.form?userId=" + request.getParameter("userId");
}
}
}
}
if (errors.hasErrors()) {
response.setStatus(HttpStatus.BAD_REQUEST.value());
return showForm(user.getUserId(), createNewPerson, user, model);
Expand Down

0 comments on commit fe904bb

Please sign in to comment.