Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Changes to UserFormController.java to redirect error message back to user. #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we combine the logic of this if-clause with the if-clause immediately below it (line 290)?

It looks like the condition is the same and collapsing them into a single if-clause might make the error-handling logic of this section a little more readable.

Copy link
Contributor Author

@Parth59 Parth59 Jul 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Issac, I have refactored the code as per suggestions.


//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");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Parth59 . How far with this ticket.

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