• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MApping nested model objects in spring mvc

 
selvakumar venkat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have the below scenario for my requirements. Im not able to map the nested objects to my form fields ..

Class A{

string a1;
@ManyToOne(cascade={})
B a2;
@ManyToOne(cascade={})
B a3;

}

Class B{
string b1;
string b2

}

Class C{

@ManyToOne(cascade={})
B c1;
String c2;
String c3;

}


Class D{
@ManyToOne(cascade={})
A d2;
String d1;
}

I tried creating Parent class to hold all the above child models as below


Class nested{

A a=new A();

B b=new B();

C c=new C();

D d =new D()'
...
getters/setter()
}

In jsp
<form:form method="POST" commandName="nested">

<form:input path="nested.A.a1" size="80" />
</form:form>


The above code in jsp throws error as invalid property for nested.no getter/setter found for nested.

Is the above mapping for nested models is correct.?

Also the c2 in the class C needs to be mutiple text boxes of the same form.How can I map the c2 to the multiple form fields in jsp.

Please suggest
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think your el is incorrect. You can access any depth with the "."

so if nested is your top variable to represent Class A, then

nested.a2.b1

In your example you have

<form:input path="nested.A.a1" size="80" />

What is the capital "A" for? That isn't a property name in any of your classes.

Mark
 
selvakumar venkat
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Spritzler wrote:I think your el is incorrect. You can access any depth with the "."

so if nested is your top variable to represent Class A, then

nested.a2.b1

In your example you have

<form:input path="nested.A.a1" size="80" />

What is the capital "A" for? That isn't a property name in any of your classes.

Mark




Sorry it would be

<form:input path="nested.a.a1" size="80" />
</form:form>


a--> A a=new A() in class named nested
a1--> refers to property name in class A
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you just use

"a.a1" and not include "nested." in front of it, since that is the command variable that is there already?

Just guessing here.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic