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

SpringValidatorAdapter's ResolvableAttribute is not serializable [SPR-14778] #19344

Closed
spring-projects-issues opened this issue Oct 5, 2016 · 0 comments
Assignees
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Oct 5, 2016

Łukasz Glapiński opened SPR-14778 and commented

After switching to spring-session-redis management there is no way to simply implement POST redirect GET scenario by assigning BindResult to RedirectAttributes.
It's because ResolvableAttribute does not implement Serializable interface and it's part of FieldError class (as one of arguments objects).

Example:

protected <T> boolean valid(T obj, String name, BindingResult result, RedirectAttributes redirectAttributes) {
    if (result.hasErrors()) {
        redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult." + name, result);
        redirectAttributes.addFlashAttribute(name, obj);
        return false;
    }
    return true;
}

@RequestMapping(value = {"/join"}, method = RequestMethod.GET)
public String handleGetSignup(Model model) {
    if (!model.containsAttribute("userJoinForm")) {
        model.addAttribute("userJoinForm", new UserJoinForm());
    }
    return "/join/signup";
}

@RequestMapping(value = {"/join"}, method = RequestMethod.POST)
public String handlePostSignup(RedirectAttributes redirectAttributes,
                               @Validated @ModelAttribute UserJoinForm userJoinForm,
                               BindingResult result) {

    if (!valid(userJoinForm, "userJoinForm", result, redirectAttributes)) {
        return "redirect:/join";
    }
    ...
}

Affects: 4.3.3

Issue Links:

  • #17986 Support MessageSourceResolvable to string argument value at SpringValidatorAdapter

Referenced from: commits d2079f3, ebed7b7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants