aspose file tools*
The moose likes Spring and the fly likes spring mvc form submitting and many-to-one relation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "spring mvc form submitting and many-to-one relation" Watch "spring mvc form submitting and many-to-one relation" New topic

spring mvc form submitting and many-to-one relation

Fabrizio Pia

Joined: Apr 24, 2007
Posts: 10
Hello. Here my problem.

First object is named Persona.
Second object is named Societa. There is a relation many for Persona and one for Societa.
Societa has two properties, let's call them "des" and "desIndirizzo".

I've a spring form (<form:form>) with modelattribute="person" in order to change some person properties submitting such form.
Here an example:

From this form I need to change not only Persona's properties but also Societa's properties.

I think to write

This doesn't work.
I get "TransientObjectException: object is an unsaved transient instance - save the transient instance before merging:"
Anyway, in the browser I can see both the input texts correctly filled with the right values!

My questions are:
First: Because I set modelattribute="persona", I was expecting that "societa.des" is the same as "persona.societa.des". After a debug I see that "societa.des" is the same as "persona.des". Obviously this doesn't exists! Why? The only manner to work is to write

But in this case a new question arises:
Second: How can I relate the first <form:input> in order to submit the Societa's "des" property and the second <form:submit> to the Societa's "desIndirizzo" property?

Third: More in general, is it possible to change properties of a object (in my case Societa) from a form of a related object (Persona)?

I also wrote and registered a property editor like this:

Can anyobe help me please?
Thank you

I agree. Here's the link:
subject: spring mvc form submitting and many-to-one relation
Similar Threads
Neither BindingResult nor plain target object for bean name 'vids2m1' available as request attribute
How can I get a normal input tag's value?
Unable to call Controller method after form submission using Spring MVC 3
How to get Hebrew text from JSP page correctly?
Spring MVC + Hibernate: Update one column?