Skip to content

Commit 2144ca5

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

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.springframework.ui.ModelMap;
3434
import org.springframework.util.StringUtils;
3535
import org.springframework.validation.BindingResult;
36+
import org.springframework.validation.FieldError;
3637
import org.springframework.web.bind.WebDataBinder;
3738
import org.springframework.web.bind.annotation.InitBinder;
3839
import org.springframework.web.bind.annotation.ModelAttribute;
@@ -273,6 +274,19 @@ public String handleSubmission(WebRequest request, HttpSession httpSession, Mode
273274

274275
userValidator.validate(user, errors);
275276

277+
if (errors.hasErrors()) {
278+
List<FieldError> fieldErrorList = errors.getFieldErrors();
279+
for (FieldError fieldError : fieldErrorList) {
280+
String[] errorCodes = fieldError.getCodes();
281+
for (String value : errorCodes) {
282+
if (value.contains("error.exceededMaxLengthOfField")) {
283+
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ATTR,"legacyui.manageuser.DemographicInfo.lengthExceeded");
284+
httpSession.setAttribute(WebConstants.OPENMRS_ERROR_ARGS, "50");
285+
return "redirect:/admin/users/user.form?userId=" + request.getParameter("userId");
286+
}
287+
}
288+
}
289+
}
276290
if (errors.hasErrors()) {
277291
response.setStatus(HttpStatus.BAD_REQUEST.value());
278292
return showForm(user.getUserId(), createNewPerson, user, model);

0 commit comments

Comments
 (0)