grails-services

Grails 3 call taglib from a service

徘徊边缘 提交于 2021-02-08 10:08:00
问题 I'm trying to use grails internal taglib from a service but I receive this error: No signature of method: MyService.message() is applicable for argument types: (java.util.LinkedHashMap) values: [[code:default.app.name]] This is the code I'm using: class MyService { def myMethod() { def appName = message(code: 'default.app.name') } } 回答1: Grails 3 The solution is to inject the grailsApplication object and use its context to get the taglib bean: class MyService { def grailsApplication def

Error in Declaration of service within Grails service

偶尔善良 提交于 2019-12-25 02:44:28
问题 I have concerns about the use of Services within other Services. Some work, but others don't. The problem is that I can't figure out what's wrong. When you add a service that generates the error always occurs the same problem, then I withdraw the reference to service problematic and the system returns to normal. I wonder if the same is effecting any circular reference creating instability. class UserService { def terceirizadoService def unidadeService def grailsApplication def

Uploading photos using Grails Services

 ̄綄美尐妖づ 提交于 2019-12-25 02:27:08
问题 I would like to ask, What would be the most suitable scope for my upload photo service in Grails ? I created this PhotoService in my Grails 2.3.4 web app, all it does is to get the request.getFile("myfile") and perform the necessary steps to save it on the hard drive whenever a user wants to upload an image. To illustrate what it looks like, I give a skeleton of these classes. PhotoPageController { def photoService def upload(){ ... photoService.upload(request.getFile("myfile")) ... } }

How to set formula in grails domain class?

烈酒焚心 提交于 2019-12-22 13:04:50
问题 I am trying to write formula in my domain class which helps me in creating criteria. class MyClass { //some fields Date appointmentTime String ddmmyy int year int month int day static transients = [ 'ddmmyy', 'year', 'month', 'day' ] static mapping= { ddmmyy formula('DATE_FORMAT(appointmentTime)') year formula('YEAR(appointmentTime)') month formula('MONTH(appointmentTime)') day formula('DAYOFMONTH(appointmentTime)') } } Whenever I am trying to use this fields in my criteria it throws error i

How to set formula in grails domain class?

帅比萌擦擦* 提交于 2019-12-22 13:03:08
问题 I am trying to write formula in my domain class which helps me in creating criteria. class MyClass { //some fields Date appointmentTime String ddmmyy int year int month int day static transients = [ 'ddmmyy', 'year', 'month', 'day' ] static mapping= { ddmmyy formula('DATE_FORMAT(appointmentTime)') year formula('YEAR(appointmentTime)') month formula('MONTH(appointmentTime)') day formula('DAYOFMONTH(appointmentTime)') } } Whenever I am trying to use this fields in my criteria it throws error i

How to set formula in grails domain class?

心不动则不痛 提交于 2019-12-22 13:03:06
问题 I am trying to write formula in my domain class which helps me in creating criteria. class MyClass { //some fields Date appointmentTime String ddmmyy int year int month int day static transients = [ 'ddmmyy', 'year', 'month', 'day' ] static mapping= { ddmmyy formula('DATE_FORMAT(appointmentTime)') year formula('YEAR(appointmentTime)') month formula('MONTH(appointmentTime)') day formula('DAYOFMONTH(appointmentTime)') } } Whenever I am trying to use this fields in my criteria it throws error i

How to know if a transactional method in a grails service was successful?

让人想犯罪 __ 提交于 2019-12-20 03:49:09
问题 I have something like this: class SomeService { static transactional = true def someMethod(){ ... a.save() .... b.save() .... c.save() .... etc... } } I want to know if the transactional method was successful or not, I don't want to check the error property in each domain object because the logic involve many domain classes and it would be difficult. 回答1: Use a.save(failOnError: true) b.save(failOnError: true) c.save(failOnError: true) d.save(failOnError: true) I'm assuming what you want is

Grails 3 - get asset path in service

别说谁变了你拦得住时间么 提交于 2019-12-12 03:27:00
问题 I need to get the path of a static resource located in assets/schemas/resource.json in a Grails 3 service. At the moment it is defined as private final String SCHEMA = 'grails-app/assets/schemas/resource.json', which is fine for development environment, but of course not for production (as it would be located in <app_root>/assets/resource.json . I tried to search how to exploit the Asset Pipeline in my case, but up to now I really have no idea :P Thanks in advance! 回答1: It is covered in the

How to set formula in grails domain class?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 07:06:53
I am trying to write formula in my domain class which helps me in creating criteria. class MyClass { //some fields Date appointmentTime String ddmmyy int year int month int day static transients = [ 'ddmmyy', 'year', 'month', 'day' ] static mapping= { ddmmyy formula('DATE_FORMAT(appointmentTime)') year formula('YEAR(appointmentTime)') month formula('MONTH(appointmentTime)') day formula('DAYOFMONTH(appointmentTime)') } } Whenever I am trying to use this fields in my criteria it throws error i.e. can not resolve property 'ddmmyy' of 'myClass'. MyCriteria is: Date myDate = Calender.instance.time

How to know if a transactional method in a grails service was successful?

烈酒焚心 提交于 2019-12-02 03:37:26
I have something like this: class SomeService { static transactional = true def someMethod(){ ... a.save() .... b.save() .... c.save() .... etc... } } I want to know if the transactional method was successful or not, I don't want to check the error property in each domain object because the logic involve many domain classes and it would be difficult. Use a.save(failOnError: true) b.save(failOnError: true) c.save(failOnError: true) d.save(failOnError: true) I'm assuming what you want is the service to throw exception on error of a single domain save, and rollback the transaction in such cases.