Adding logic to a domain object's create

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

Adding logic to a domain object's create

barnesjd
Hi, I am new to Grails, Spring, and Groovy but I have years of J2EE experience.  I would like one of my domain objects to do some extra logic when it is initially created and persisted.  Can someone tell me how I can do this?  Ideally, it will be code inside the domain object.  Thanks!

Joe
Reply | Threaded
Open this post in threaded view
|

Re: Adding logic to a domain object's create

barnesjd
I believe I finally found it in the docs... I think I need a beforeInsert() defined.
Reply | Threaded
Open this post in threaded view
|

Re: Adding logic to a domain object's create

Jonathan Rosenberg
beforeInsert may do what you want, but it isn't the same as performing
some actions just after the "new."

beforeInsert just before the object is inserted into the DB.

--
Jonathan Rosenberg
Founder & Executive Director
Tabby's Place, a Cat Sanctuary
http://www.tabbysplace.org/


On Thu, Feb 23, 2012 at 7:42 PM, barnesjd <[hidden email]> wrote:

> I believe I finally found it in the docs... I think I need a beforeInsert()
> defined.
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Adding-logic-to-a-domain-object-s-create-tp4415647p4415738.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Adding logic to a domain object's create

barnesjd
Understood.  I believe this will work, since I really only need it to happen before the persistence time.  However, it may not work great as I'm not sure if these changes will appear to the view when the controller's create() is called.
Reply | Threaded
Open this post in threaded view
|

Re: Adding logic to a domain object's create

barnesjd
Well, it turns out that it wouldn't work.  In that method, I wanted to create another domain class which would be saved in a cascade, but it doesn't work.  Calling my code to create that other object in the controller before the save works well.
Reply | Threaded
Open this post in threaded view
|

Help in using QR Code Generator

Qin Ding
I installed the qrcode generator plugin.  Then 1) in my grail page, I added <%@ page import="org.codehaus.groovy.grails.plugins.qrcode.*" %> to the top of the page; 2) at the body section of the page , 
I added <qrcode:image text="hello world"/>

I got the following error:

| Error 2012-02-23 22:40:26,987 ["http-bio-8080"-exec-8] ERROR errors.GrailsExceptionResolver  - IllegalArgumentException occurred when processing request: [GET] /eguahao/customer/show_ticket/2
operation "Encode" requires parameter at index 0 to be non-null.. Stacktrace follows:
Message: operation "Encode" requires parameter at index 0 to be non-null.

I then added to my controller:

request.contentType = "image/png"
def outputStream = request.outputStream
QRCodeRenderer qrcodeRenderer = new QRCodeRenderer()
qrcodeRenderer.renderPng("hello world", 100, outputStream)

I got the error stating request.contentType is read only.  I comment out the request.contentType, then I got the exact same error about the "Encode" requires parameter at index  0 to be non-null.

What did I miss here?  I am using grails 2.x.  

QD
Reply | Threaded
Open this post in threaded view
|

Re: Help in using QR Code Generator

okelet
As you render the PNG to the user, should'nt you use
response.contentType instead of request?

El día 24 de febrero de 2012 05:58, Qin Ding <[hidden email]> escribió:

> I installed the qrcode generator plugin.  Then 1) in my grail page, I
> added <%@ page import="org.codehaus.groovy.grails.plugins.qrcode.*" %> to
> the top of the page; 2) at the body section of the page ,
> I added <qrcode:image text="hello world"/>
>
> I got the following error:
>
> | Error 2012-02-23 22:40:26,987 ["http-bio-8080"-exec-8] ERROR
> errors.GrailsExceptionResolver  - IllegalArgumentException occurred when
> processing request: [GET] /eguahao/customer/show_ticket/2
> operation "Encode" requires parameter at index 0 to be non-null.. Stacktrace
> follows:
> Message: operation "Encode" requires parameter at index 0 to be non-null.
>
> I then added to my controller:
>
> request.contentType = "image/png"
> def outputStream = request.outputStream
> QRCodeRenderer qrcodeRenderer = new QRCodeRenderer()
> qrcodeRenderer.renderPng("hello world", 100, outputStream)
>
> I got the error stating request.contentType is read only.  I comment out the
> request.contentType, then I got the exact same error about the "Encode"
> requires parameter at index  0 to be non-null.
>
> What did I miss here?  I am using grails 2.x.
>
> QD

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Help in using QR Code Generator

michael astreiko
In reply to this post by Qin Ding
Re: [grails-user] Help in using QR Code Generator

Hello Qin,


I've also tried to use it and fail. Then I just make it myself.

See http://grails4you.com/2012/02/qr-code-and-bar-code-rendering-in-grails/ for details


Friday, February 24, 2012, 7:58:40 AM, you wrote:



I installed the qrcode generator plugin.  Then 1) in my grail page, I added <%@ page import="org.codehaus.groovy.grails.plugins.qrcode.*" %> to the top of the page; 2) at the body section of the page , 

I added <qrcode:image text="hello world"/>


I got the following error:


| Error 2012-02-23 22:40:26,987 ["http-bio-8080"-exec-8] ERROR errors.GrailsExceptionResolver  - IllegalArgumentException occurred when processing request: [GET] /eguahao/customer/show_ticket/2

operation "Encode" requires parameter at index 0 to be non-null.. Stacktrace follows:

Message: operation "Encode" requires parameter at index 0 to be non-null.


I then added to my controller:


  request.contentType = "image/png"

  def outputStream = request.outputStream

  QRCodeRenderer qrcodeRenderer = new QRCodeRenderer()

  qrcodeRenderer.renderPng("hello world", 100, outputStream)


I got the error stating request.contentType is read only.  I comment out the request.contentType, then I got the exact same error about the "Encode" requires parameter at index  0 to be non-null.


What did I miss here?  I am using grails 2.x.  


QD




-- 

Best regards,

Michael Astreiko

--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

Re: Help in using QR Code Generator

iris
Thanks for your article. i was looking for a site to create my own barcode, but i don't know which one is better, cuz there are so many imformation on the net. at last, i choose this one
http://www.businessrefinery.com/products/barcode_net_win/2d_barcodes.html
i consider it from the whole site, this one is the best one and it works fine now.
Reply | Threaded
Open this post in threaded view
|

Re: Help in using QR Code Generator

arronlee
Hi,
As for me, I am testing the related java barcode generator these days. Do you have any ideas about it? Or any good suggestion? I am totally a green hand on barcode generating field. Any suggestion will be appreciated. Thanks in advance.


Best regards,
Arron