• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

SpringMVC form handling, domain objects fields not present form are nullified after commit

Ranch Hand
Posts: 111
PHP Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am just starting with Spring/Hibernate integration and have some problems in handling the form commit. My application to develop is concentrated around the domain objects Activity and Member.
The application core functionality consists of members who can create events (like outdoor events, movies, dinners) where other members can subscribe for.

The domain objects are defined as follows with Hibernate annotations (getter and setters omitted):

I am starting with the functionality of adding and editing activities for the logged in member (which is now hardcoded because the login system still has to be developed).

I am using a Spring annotated controller and Thymeleaf view. THe problem occurs when editing an existing activity.

This is the code for the controller:

The form part of the view file looks like this:

Most tutorials and examples I find on the internet have domain objects without id field and always have input form fields for all of the available domain object fields.

First I noticed that the id field itself was set to null in the submitForm() method when using the "/formsubmit" pattern. I changed it to "/{id}/formsubmit" and extract the id using a PathVAriable annotation. An alternative would be using a hidden id attribute as one sees a lot in legacy web applications.

I am not sure what is the best practice here. But in this way it is working anyway.

But still the "organiser" field is nullified after the submit. THe organiser of an event cannot be modified after the first create and therefore is not in the form. It is probably possible to use a hidden field for this property too but I thought this should not be necessary with Spring MVC and form backing objects.
So I think my question boils down to how to retains the values of domain object fields which are references to other domain objects and -in rthis case- not editable after the first time create and not part of the edit form (and therefore not part of the POST request variables).
Any tips are more than welcome!
    Bookmark Topic Watch Topic
  • New Topic