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 16, 2021
1 parent 7f1d5bb commit 0300504
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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 @@ -33,6 +33,7 @@
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand Down Expand Up @@ -273,7 +274,23 @@ public String handleSubmission(WebRequest request, HttpSession httpSession, Mode

userValidator.validate(user, errors);


if (errors.hasErrors()) {

//check if length exceeded in DemographicInfo fields
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");
}
}
}

//check and inform the user for errors
response.setStatus(HttpStatus.BAD_REQUEST.value());
return showForm(user.getUserId(), createNewPerson, user, model);
}
Expand Down

0 comments on commit 0300504

Please sign in to comment.