null safe operator in the value attribute for the association.

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

null safe operator in the value attribute for the association.

Mauro
I have:

class Supplier {
  String companyName
  tatic hasMany = [ phones:Phone ]

and

class Phone {
  String number

To create a Supplier and associated phone at the same time I've done:

<g:textField name="companyName" required="" value="${supplierInstance?.companyName}"/>

<g:textField name="phones[0].number" value="${supplierInstance?.phones[0]?.number}" />

<g:textField name="phones[1].number" value="${supplierInstance?.phones[1]?.number}" />

<g:textField name="phones[2].number" value="${supplierInstance?.phones[2]?.number}" />

the error I have is:

Error evaluating expression [supplierInstance?.phones[0]?.number] on line [101]: Cannot invoke method getAt() on null object

How can it be used the null safe operator in the value attribute?
Reply | Threaded
Open this post in threaded view
|

RE: null safe operator in the value attribute for the association.

burtbeckwith
Use ?.getAt () instead of .? []


Burt

-------- Original message --------
From: Mauro Sanna
Date:12/26/2013 3:52 PM (GMT-05:00)
To: user
Subject: [grails-user] null safe operator in the value attribute for the association.

I have:

class Supplier {
  String companyName
  tatic hasMany = [ phones:Phone ]

and

class Phone {
  String number

To create a Supplier and associated phone at the same time I've done:

<g:textField name="companyName" required="" value="${supplierInstance?.companyName}"/>

<g:textField name="phones[0].number" value="${supplierInstance?.phones[0]?.number}" />

<g:textField name="phones[1].number" value="${supplierInstance?.phones[1]?.number}" />

<g:textField name="phones[2].number" value="${supplierInstance?.phones[2]?.number}" />

the error I have is:

Error evaluating expression [supplierInstance?.phones[0]?.number] on line [101]: Cannot invoke method getAt() on null object

How can it be used the null safe operator in the value attribute?
Reply | Threaded
Open this post in threaded view
|

Re: null safe operator in the value attribute for the association.

Mauro
do you mean
"${supplierInstance?.phones?.getAt(2)?.number}"


On 26 December 2013 22:17, Burt Beckwith <[hidden email]> wrote:
Use ?.getAt () instead of .? []


Burt


-------- Original message --------
From: Mauro Sanna
Date:12/26/2013 3:52 PM (GMT-05:00)
To: user
Subject: [grails-user] null safe operator in the value attribute for the association.

I have:

class Supplier {
  String companyName
  tatic hasMany = [ phones:Phone ]

and

class Phone {
  String number

To create a Supplier and associated phone at the same time I've done:

<g:textField name="companyName" required="" value="${supplierInstance?.companyName}"/>

<g:textField name="phones[0].number" value="${supplierInstance?.phones[0]?.number}" />

<g:textField name="phones[1].number" value="${supplierInstance?.phones[1]?.number}" />

<g:textField name="phones[2].number" value="${supplierInstance?.phones[2]?.number}" />

the error I have is:

Error evaluating expression [supplierInstance?.phones[0]?.number] on line [101]: Cannot invoke method getAt() on null object

How can it be used the null safe operator in the value attribute?

Reply | Threaded
Open this post in threaded view
|

Re: null safe operator in the value attribute for the association.

burtbeckwith
Right - all Groovy operators have a backing method. See http://groovy.codehaus.org/Operators for a table of several of them.

Burt

On 12/26/2013 04:54 PM, Mauro Sanna wrote:
do you mean
"${supplierInstance?.phones?.getAt(2)?.number}"


On 26 December 2013 22:17, Burt Beckwith <[hidden email]> wrote:
Use ?.getAt () instead of .? []


Burt


-------- Original message --------
From: Mauro Sanna
Date:12/26/2013 3:52 PM (GMT-05:00)
To: user
Subject: [grails-user] null safe operator in the value attribute for the association.

I have:

class Supplier {
  String companyName
  tatic hasMany = [ phones:Phone ]

and

class Phone {
  String number

To create a Supplier and associated phone at the same time I've done:

<g:textField name="companyName" required="" value="${supplierInstance?.companyName}"/>

<g:textField name="phones[0].number" value="${supplierInstance?.phones[0]?.number}" />

<g:textField name="phones[1].number" value="${supplierInstance?.phones[1]?.number}" />

<g:textField name="phones[2].number" value="${supplierInstance?.phones[2]?.number}" />

the error I have is:

Error evaluating expression [supplierInstance?.phones[0]?.number] on line [101]: Cannot invoke method getAt() on null object

How can it be used the null safe operator in the value attribute?