Hi, I'm using a domain object as a command object in the web layer. In one case, this command object is backing a form that represents a partial update of the domain object.
@RequestMapping( value = "/club/edit", method = RequestMethod.GET )
public String setupEditClubForm( ModelMap model, @RequestParam( "clubId" ) Long clubId ) {
Club club = clubService.findClubById( clubId );
model.addAttribute( "club", club );
model.addAttribute( "action", "edit" );
return "clubForm";
}
@RequestMapping( value = "/club/edit", method = RequestMethod.POST )
public String processEditClubForm( ClubEntity club, BindingResult result ) {
if ( result.hasErrors() ) {
return "clubForm";
}
clubService.updateClub( club );
return "redirect:/club/" + club.getId();
}
My problem is that the domain object has some fields that are not changed by submitting this form. These fields that don't have the corresponding request parameters become null, I need them to stay as they are.
I though that this could be fixed by putting the object in the session (via @SessionAttributes) to allow it to live between the two requests, but it doesn't work.
I looked in the Spring reference, but I couldn't find any information on how Spring manipulates the command objects.