aspose file tools*
The moose likes Spring and the fly likes MApping nested model objects in spring mvc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "MApping nested model objects in spring mvc" Watch "MApping nested model objects in spring mvc" New topic
Author

MApping nested model objects in spring mvc

selvakumar venkat
Greenhorn

Joined: Jun 19, 2006
Posts: 4
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

Joined: Feb 05, 2001
Posts: 17260
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
selvakumar venkat
Greenhorn

Joined: Jun 19, 2006
Posts: 4
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

Joined: Feb 05, 2001
Posts: 17260
    
    6

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MApping nested model objects in spring mvc