After 15 hours of trial and horror I've decided to share my issues with the world, because quite frankly, I have no idea how to solve my problem anymore:
I've created a custom form for users to check checkboxes and press a save button: Here's the snippet of the relevant code:
<form th:action="@{/profile}" action="/profile" th:object="${profileModel}" method="POST">
<div class="row" style="margin-left: 5px;"><h4>Select</h4></div>
<div class="row">
<!-- Barbell -->
<section class="panel panel-default panel-equipment col-md-3">
<header class="panel-heading panel-heading-profileform">
<h3 class="panel-title"><b>Barbell</b></h3>
</header>
<div class="col-md-12">
<div><input type="checkbox" th:field="*{equipment.barbellLight}" th:value="1"> Light</input></div>
<div><input type="checkbox" th:field="*{equipment.barbellMedium}" th:value="1"> Medium</input></div>
<div><input type="checkbox" th:field="*{equipment.barbellHeavy}" th:value="1"> Heavy</input></div>
</div>
</section>
</div>
</div>
</form>
My controller: The request:
@RequestMapping(value = "/profilestage", method=RequestMethod.POST)
public String updateProfileStage(@ModelAttribute ProfileModel profileModel, Model model){
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String username = auth.getName();
model.addAttribute("signedin", true);
model.addAttribute("username", username.substring(0, 1).toUpperCase() + username.substring(1));
UserEntity user = userService.findByUsername(username);
ProfileEntity profile = user.getProfile();
model.addAttribute("profileModel", ModelEntityConvertor.profileEntityToModel(profile));
return "profile_new";
}
This isn't all of the controller, but as far as you need to know, I've debugged all of this code VERY thoroughly and the profileModel going in, the one used in th:object
, is never null and always has all required fields set (in my case all 0's).
The form is posting to this controller:
@RequestMapping(value = "/profile", method=RequestMethod.POST)
public String updateProfile(@ModelAttribute ProfileModel profileModel, Model model){
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String username = auth.getName();
UserEntity user = userService.findByUsername(username);
ProfileEntity profile = user.getProfile();
profile.setEquipment(ModelEntityConvertor.equipmentModelToEntity(profileModel.getEquipment(), profile.getEquipment()));
profileService.updateProfile(profile);
return this.getProfile(model);
}
This controller is never reached whenever my application decides to not work, but whenever it IS reached, it works like a charm and works exactly as it should.
The big issue I'm trying to wrap my head around, is the fact that all of this occasionally works.. One minute I run the code, no problems. I then rerun the exact same code, try doing this with another user, or both and after clicking on save
spring's default error page is displayed.
No error message is provided anywhere...
I've tried:
- cleaning the project
- closing eclipse
- rebuilding project entirely
- working in chrome's developer mode (I always do this, any changes in css are always displayed)
- added both spring.template.cache: false and spring.thymeleaf.cache: false to properties
I honestly don't understand what I'm doing wrong and will REALLY appreciate your help =)
Thnx in advance for reading my wall of text and apologies for the latter. If any more of my code is required, I'm here non-stop.