0

i am trying to create login-register page application in spring framework.

In my registration form, intelij idea says Cannot resolve 'global'.

i changed springsecurity4 to springsecurity3 but didn't change anything.

This my form element:

<form class="form-signin" th:action="@{/registration}" th:object="${user}" method="post">
  <input type="text" class="form-control" placeholder="Full Name" th:field="*{fullname}" required autofocus>
  <label style="color: red" th:if="${#fields.hasErrors('fullname')}" th:errors="*{fullname}">Username Error</label>
  <input type="text" class="form-control" placeholder="email" th:field="*{email}" required autofocus>
  <label style="color: red" th:if="${#fields.hasErrors('email')}" th:errors="*{email}">Username Error</label>
  <input type="password" class="form-control" placeholder="Password ..." name="password" required>
  <label style="color: red" th:if="${#fields.hasErrors('password')}" th:errors="*{password}">Password Error</label>
  <input type="submit" class="btn btn-lg btn-default btn-block" value="Sign Up" />
  <td th:if="${#fields.hasGlobalErrors()}" th:errors="*{global}">Global Error</td>
</form>

this is my html element:

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">

This is my controller method :

@RequestMapping(value = "/registration", method = RequestMethod.POST)
public ModelAndView createNewUser(@Valid User user, BindingResult bindingResult) {
    ModelAndView modelAndView = new ModelAndView();
    User userExists = userService.findUserByEmail(user.getEmail());
    if (userExists != null) {
        bindingResult
                .rejectValue("email", "error.user",
                        "There is already a user registered with the email provided");
    }
    if (bindingResult.hasErrors()) {
        modelAndView.setViewName("registration");
    } else {
        userService.saveUser(user);
        modelAndView.addObject("successMessage", "User has been registered successfully");
        modelAndView.addObject("user", new User());
        modelAndView.setViewName("registration");

    }
    return modelAndView;
}

This is my pom.xml file :

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>net.sourceforge.nekohtml</groupId>
        <artifactId>nekohtml</artifactId>
    </dependency>
</dependencies>
riddle_me_this
  • 8,575
  • 10
  • 55
  • 80
Mert Doe
  • 549
  • 5
  • 15

1 Answers1

0

I believe the source of the problem is related to the th:object tag and that the solution (actually linked to other related questions) is already to be found here: Spring Thyme Leaf checking for global errors results in NPE

Additionally, I noticed you are using <td> tag outside of a <table> element, this is not how it should be used according to: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/td