Skip to content

Chapter 4.4: Knowing your user #115

@bassgelo

Description

@bassgelo

In the method DesignTacoController.processDesign when the Taco has any error, the view default is to be shown again.
But there is one error, the view design cannot be rendered, it complaints about missing the user.

Code snippet

@PostMapping
  public String processDesign(
      @Valid Taco taco, Errors errors,
      @ModelAttribute Order order, Model model) {
    log.info("   --- Saving taco");
    if (errors.hasErrors()) {
      return "design";
    } 

design.html

<h2>Feelin' hungry, <span th:text="${user.fullname}">NAME</span>?</h2>

Error
An error happened during template parsing (template: "class path resource [templates/design.html]")... Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "user.fullname" (template: "design" - line 11, col 31)

Here the user is not part of the model, and the view design cannot be render.
Anyone has a smart elegant solution for it ? i.e. to tell the backend that needs to pass the user to the view.
ATTENTION, it is only in the redirect when there is an error. If the user logins, then the design view has not issues, this is because the GetMapping method is invoked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions