Problem creating many-to-one relation through scaffolded view

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem creating many-to-one relation through scaffolded view

Dierk König
Hi,

I have a many-to-one relation from TutorialEntry to Author.
With one Author created, New TutorialEntry is called.

The form looks (correctly as much as I can tell) like this:

----
<form action="/tutor/tutorialEntry/save" method="post" >
<div class="dialog">
<table>
<tr class='prop'><td valign='top' style='text-align:left;' width='20%'>
  <label for='author'>Author:</label></td><td valign='top'
style='text-align:left;' width='80%' class=''>
  <select name='author.id' >
    <option value="1" >Guillaume</option>
 </select></td>
</tr>
----

clicking [Create] brings

----
Message: org.springframework.beans.NullValueInNestedPathException: Invalid
property 'author' of bean class [TutorialEntry]: Value of nested property
'author' is null
Caused by: org.springframework.beans.NullValueInNestedPathException: Invalid
property 'author' of bean class [TutorialEntry]: Value of nested property
'author' is null
Class: TutorialEntryController
At Line: [64]
Code Snippet:
64: tutorialEntry.properties = params
65: if(tutorialEntry.save()) {
----

Is there some mismatch between 'author.id' being the submitted value and
'author' being expected?

cheers
Mittie

Reply | Threaded
Open this post in threaded view
|

Re: Problem creating many-to-one relation through scaffolded view

graemer
You need to instantiate your related properties as part of the class like:

@Property Author author = new Author()

Its a general rule, with relationship as the same applies to one-to-manys

Graeme

On 01/03/06, Dierk Koenig <[hidden email]> wrote:

> Hi,
>
> I have a many-to-one relation from TutorialEntry to Author.
> With one Author created, New TutorialEntry is called.
>
> The form looks (correctly as much as I can tell) like this:
>
> ----
> <form action="/tutor/tutorialEntry/save" method="post" >
> <div class="dialog">
> <table>
> <tr class='prop'><td valign='top' style='text-align:left;' width='20%'>
>   <label for='author'>Author:</label></td><td valign='top'
> style='text-align:left;' width='80%' class=''>
>   <select name='author.id' >
>     <option value="1" >Guillaume</option>
>  </select></td>
> </tr>
> ----
>
> clicking [Create] brings
>
> ----
> Message: org.springframework.beans.NullValueInNestedPathException: Invalid
> property 'author' of bean class [TutorialEntry]: Value of nested property
> 'author' is null
> Caused by: org.springframework.beans.NullValueInNestedPathException: Invalid
> property 'author' of bean class [TutorialEntry]: Value of nested property
> 'author' is null
> Class: TutorialEntryController
> At Line: [64]
> Code Snippet:
> 64: tutorialEntry.properties = params
> 65: if(tutorialEntry.save()) {
> ----
>
> Is there some mismatch between 'author.id' being the submitted value and
> 'author' being expected?
>
> cheers
> Mittie
>
>
Reply | Threaded
Open this post in threaded view
|

RE: Problem creating many-to-one relation through scaffolded view

Dierk König
Ah! ok, thanks.

But doesn't that lead to an endless recursion in cases like:

class TutorialEntry {
    @Property Long id;
    @Property Long version;

    @Property belongsTo = ['author': Author.class]

    @Property TutorialEntry parentEntry  // <- here new TutorialEntry() ???
    @Property Set           childEntries = new HashSet()

    @Property Author        author       = new Author()
}

(more endless recursions can occur in cyclic dependencies...)

???
Mittie


> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]On Behalf
> Of Graeme Rocher
> Sent: Mittwoch, 1. März 2006 23:12
> To: [hidden email]
> Subject: Re: [grails-dev] Problem creating many-to-one relation through
> scaffolded view
>
>
> You need to instantiate your related properties as part of the class like:
>
> @Property Author author = new Author()
>
> Its a general rule, with relationship as the same applies to one-to-manys
>
> Graeme
>
> On 01/03/06, Dierk Koenig <[hidden email]> wrote:
> > Hi,
> >
> > I have a many-to-one relation from TutorialEntry to Author.
> > With one Author created, New TutorialEntry is called.
> >
> > The form looks (correctly as much as I can tell) like this:
> >
> > ----
> > <form action="/tutor/tutorialEntry/save" method="post" >
> > <div class="dialog">
> > <table>
> > <tr class='prop'><td valign='top' style='text-align:left;' width='20%'>
> >   <label for='author'>Author:</label></td><td valign='top'
> > style='text-align:left;' width='80%' class=''>
> >   <select name='author.id' >
> >     <option value="1" >Guillaume</option>
> >  </select></td>
> > </tr>
> > ----
> >
> > clicking [Create] brings
> >
> > ----
> > Message:
> org.springframework.beans.NullValueInNestedPathException: Invalid
> > property 'author' of bean class [TutorialEntry]: Value of
> nested property
> > 'author' is null
> > Caused by:
> org.springframework.beans.NullValueInNestedPathException: Invalid
> > property 'author' of bean class [TutorialEntry]: Value of
> nested property
> > 'author' is null
> > Class: TutorialEntryController
> > At Line: [64]
> > Code Snippet:
> > 64: tutorialEntry.properties = params
> > 65: if(tutorialEntry.save()) {
> > ----
> >
> > Is there some mismatch between 'author.id' being the submitted value and
> > 'author' being expected?
> >
> > cheers
> > Mittie
> >
> >

Reply | Threaded
Open this post in threaded view
|

Re: Problem creating many-to-one relation through scaffolded view

graemer
On 01/03/06, Dierk Koenig <[hidden email]> wrote:

> Ah! ok, thanks.
>
> But doesn't that lead to an endless recursion in cases like:
>
> class TutorialEntry {
>     @Property Long id;
>     @Property Long version;
>
>     @Property belongsTo = ['author': Author.class]
>
>     @Property TutorialEntry parentEntry  // <- here new TutorialEntry() ???
>     @Property Set           childEntries = new HashSet()
>
>     @Property Author        author       = new Author()
> }
>
> (more endless recursions can occur in cyclic dependencies...)

That's true, maybe I can update the binder to automatically attempt to
instantiate the class if its null.. let me give it some thought

Graeme

>
> ???
> Mittie
>
>
> > -----Original Message-----
> > From: [hidden email] [mailto:[hidden email]]On Behalf
> > Of Graeme Rocher
> > Sent: Mittwoch, 1. März 2006 23:12
> > To: [hidden email]
> > Subject: Re: [grails-dev] Problem creating many-to-one relation through
> > scaffolded view
> >
> >
> > You need to instantiate your related properties as part of the class like:
> >
> > @Property Author author = new Author()
> >
> > Its a general rule, with relationship as the same applies to one-to-manys
> >
> > Graeme
> >
> > On 01/03/06, Dierk Koenig <[hidden email]> wrote:
> > > Hi,
> > >
> > > I have a many-to-one relation from TutorialEntry to Author.
> > > With one Author created, New TutorialEntry is called.
> > >
> > > The form looks (correctly as much as I can tell) like this:
> > >
> > > ----
> > > <form action="/tutor/tutorialEntry/save" method="post" >
> > > <div class="dialog">
> > > <table>
> > > <tr class='prop'><td valign='top' style='text-align:left;' width='20%'>
> > >   <label for='author'>Author:</label></td><td valign='top'
> > > style='text-align:left;' width='80%' class=''>
> > >   <select name='author.id' >
> > >     <option value="1" >Guillaume</option>
> > >  </select></td>
> > > </tr>
> > > ----
> > >
> > > clicking [Create] brings
> > >
> > > ----
> > > Message:
> > org.springframework.beans.NullValueInNestedPathException: Invalid
> > > property 'author' of bean class [TutorialEntry]: Value of
> > nested property
> > > 'author' is null
> > > Caused by:
> > org.springframework.beans.NullValueInNestedPathException: Invalid
> > > property 'author' of bean class [TutorialEntry]: Value of
> > nested property
> > > 'author' is null
> > > Class: TutorialEntryController
> > > At Line: [64]
> > > Code Snippet:
> > > 64: tutorialEntry.properties = params
> > > 65: if(tutorialEntry.save()) {
> > > ----
> > >
> > > Is there some mismatch between 'author.id' being the submitted value and
> > > 'author' being expected?
> > >
> > > cheers
> > > Mittie
> > >
> > >
>
>