Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

MApping nested model objects in spring mvc

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
This is my favorite tiny ad:
The trailboss has a kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic