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

Chapter 4.4: Knowing your user #115

Open
bassgelo opened this issue May 7, 2022 · 0 comments
Open

Chapter 4.4: Knowing your user #115

bassgelo opened this issue May 7, 2022 · 0 comments

Comments

@bassgelo
Copy link

bassgelo commented May 7, 2022

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.

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

No branches or pull requests

1 participant