Can you use two words for a Domain if you are planning to access it via Thymeleaf?

Viewed 32

Think I might have come across the strangest feature/bug that has caused me to pull my hair out for the last few hours. I have spring mvc program and I'm passing values from my controller to html page via thymeleaf. When my domain is named "Chicken" it works perfectly, but when my domain is named "ChickenBox" it gives me "java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'chickenbox' available as request attribute" error.

Could someone explain why this is the case? Also just throwing this out there as I didn't see anyone encounter this issue and hopefully it will save someone trouble.

P.S. I don't have an index so you have to type in "localhost:8080/officesignup" to open the page to the 500 error.

Here is my controller

@Controller
public class UserController {

    @Autowired 
    private LocOfficeRepository officeRepo;
    
    @Autowired
    private AdminRepository adminRepo;

  public UserController(LocOfficeRepository officeRepo) {
    this.officeRepo = officeRepo;
  }
  
  
  @RequestMapping({"/HQadmin-offices-view"})
  public String showOfficesList(Model model) {
      //model.addAttribute("offices", officeRepo.findAll());
      return "HQadmin-offices-view";
  }
  
  //@RequestMapping({"/HQadmin-admin-view"})
  //public String showAdminList(Model model) {
      //model.addAttribute("admins", adminRepo.findAll());
      //return "HQAdmin/HQadmin-admin-view";
  //}
  
  @RequestMapping({"/officesignup"})
  public String showOfficeSignUpForm(ChickenBox chicken) {
      return "add-office";
  }
  
  //@RequestMapping({"/adminsignup"})
  //public String showAdminSignUpForm(Admins admin) {
      //return "HQAdmin/add-LFadmin";
  //}
  
  @RequestMapping({"/addoffice"})
  public String addOffice(@Validated LocationsOffice office, BindingResult result, Model model) {
      if (result.hasErrors()) {
          return "add-office";
      }

      officeRepo.save(office);
      return "redirect:HQadmin-offices-view";
  }
  
  @RequestMapping({"/addadmin"})
  public String addAdmin(@Validated Admins admin, BindingResult result, Model model) {
      if (result.hasErrors()) {
          return "HQAdmin/add-LFadmin";
      }

      adminRepo.save(admin);
      return "redirect:/HQAdmin/HQadmin-admin-view";
  }
  
  
}

My Repository

@Service
public interface ChickenRepository extends CrudRepository<ChickenBox, Long> {
    
    
}

Domain

@Entity
public class ChickenBox {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    
    private String address;
    
    long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
        
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
        
    }

    public ChickenBox(long id, String address) {
        super();
        this.id = id;
        this.address = address;
    }

    public ChickenBox() {
        super();
    }
    
    
}

and lastly the html page in question

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="ISO-8859-1">
<title>Add Office</title>
</head>
<body>
<form action="#" th:action="@{/addoffice}" th:object="${chickenbox}" method="post">
    <label for="address">Address</label>
    <input type="text" th:field="*{address}" id="address" placeholder="Address">
    <input type="submit" value="Add Office">   
</form>
</body>
</html>
0 Answers
Related