I'm working on grails 2.4.5.
I connect my project to oracle 11g.
In datasource, I add:
dataSource {
pooled = true
dialect = org.hibernate.dialect.Oracle10gDialect
driverClassName = 'oracle.jdbc.OracleDriver'
username = 'grails' // YOUR USERNAME AND PASS
password = 'grails'
url = 'jdbc:oracle:thin:localhost:1521:orcl'
dbCreate = 'update'
}
Then it connects and when I create new domain, new table in db creates.
However when I add new:
new Book(name:'The Strain').save(flush:true)
Then errors appear:
2015-07-29 17:10:30,036 [Thread-10] ERROR plugins.AbstractGrailsPluginManager - Plugin [controllers:2.4.5] could not reload changes to file [C:\Users\Thuc Tran\IdeaProjects\EmailTutorial\grails-app\controllers\emailtutorial\PlaceController.groovy]: Cannot invoke method getPropertyValue() on null object
Message: Cannot invoke method getPropertyValue() on null object
Line | Method
->> 120 | configureScaffoldingController in ScaffoldingGrailsPlugin
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
^ 105 | doCall in ScaffoldingGrailsPlugin$_closure3
Any solutions will be appreciated. Thanks.
I solved this problem. I post the solution for those who need it.
On oracle, create sequence, eg: BOOK_SEQ on my case. Make sure that on oracle, when you add new record, id will be auto increment.
Then on the domain class, static mapping quote, add:
static mapping = {
id generator:'sequence', params:[sequence:'BOOKS_SEQ']
}
So that's all.
If answer not clear, I feel free to answer.
Thanks.
Related
I have created a service NotifierService to send emails using grails mail plugin.
class NotifierService {
MailService mailService
def sendWarningEmail(String name, String email, Date blockingDate) {
try {
mailService.sendMail {
to email
from "noreply-myApp#domain.com"
subject "Status message: Warning"
body (view:"/email/warningEmail", model:[
name:name,
blockingDate:blockingDate
])
}
} catch (Exception e) {
e.printStackTrace()
}
}
}
I have created another service ApplicationUtilService in which I am trying to use the NotifierService.
class ApplicationUtilService{
def notifierService
def notifyUser(){
notifierService.sendWarningEmail("User name", "user#domain.com", new Date())
}
}
I am trying to call notifyUser() in a grails job UpdateJob
class UpdateJob{
def applicationUtilService
static triggers = {
// Scehduling parameters
}
def execute(){
applicationUtilityService.notifyUser()
}
}
I get the following error
Error 2014-12-05 12:04:53,550 [quartzScheduler_Worker-1] ERROR listeners.ExceptionPrinterJobListener - Exception occurred in job: Grails Job
Message: java.lang.NullPointerException: Cannot invoke method notifyUser() on null object
Line | Method
->> 111 | execute in grails.plugins.quartz.GrailsJobFactory$GrailsJob
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 202 | run in org.quartz.core.JobRunShell
^ 573 | run . . in org.quartz.simpl.SimpleThreadPool$WorkerThread ...`
It works when I instantiate as
ApplicationUtilService applicationUtilService = new ApplicationUtilService()
instead of using grails dependency injection. Again, the same problem with the notifierService in ApplicationUtilService and fixed by instantiating same as above.
Now, the real problem is with the mailService. The instantiation as above didn't work. How could I resolve it
The Null Pointer is occurring on UpdateJob.applicationUtilService, so it seems like applicationUtilService isn't being injected into UpdateJob correctly. Is UpdateJob in the right package?
A confused Grails newbie here. I am currently going through the tutorials in
a book (Smith, Ledbrook, "Grails in Action", Manning Publications, 1st Ed)
and am stumped in the first chapter! When browsing to localhost, I get the
error messages further below. The tutorial leads me through creating a
Random Quote of the Day application. As you might suspect, browsing to the
webpage gives a random quote (which were saved in the "Quote" domain class)
with each refresh.
I have made the controller, view, layout, domain class, all of which are
pretty simple. I would imagine that I'd get these errors if there were no
test data, but using the grails console shows me that there are. Despite
this, refreshes of the browser echo the errors in an open terminal.
The code for the Quote domain class and the controller are below as well. I
wanted to change the config file for the development environment to make it
persistent, so that entry is also down there. Let me know if you need to see
anything else...
Any ideas? (Using Grails version 2.4.0 installed on Ubuntu 14.04. Book uses
code for Grails 1.1)
Error:
URI: /qotd/quote/random
Class:java.lang.IllegalStateException
Message: Method on class [qotd.Quote] was used outside of a Grails
application. If running in the context of a test using the mocking API or
bootstrap Grails correctly.
Around line 8 of grails-app/controllers/qotd/QuoteController.groovy
6:
7: def random = {
8: def allQuotes = Quote.list()
9: /*def randomQuote
10: if (allQuotes.size() > 0 )
11: {
Trace
Line | Method
->> 9 | doCall in QuoteController.groovy
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 198 | doFilter in PageFragmentCachingFilter.java
| 63 | doFilter in AbstractFilter.java
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 744 | run in java.lang.Thread
Controller
package qotd
class QuoteController {
def index = { }
def random = {
def allQuotes = Quote.list()
/*
def randomQuote
if (allQuotes.size() > 0 )
{
def randomIdx = new Random().nextInt(allQuotes.size())
randomQuote = allQuotes[randomIdx]
} else {
randomQuote = new Quote(author: "Anonymous",
content: "Real Programmers Don't eat Quiche")
}
[quote : randomQuote ]
*/
}
}
Quote domain class
package qotd
class Quote {
String content
String author
Date created = new Date()
static constraints = {
}
}
Development Environment from DataSource.groovy
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update',
'validate', ''
url =
"jdbc:h2:file:~/h2db/quotedevdb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
}
}
Yep, as grantmcconnaughey comments, you don't want to declare your controller actions as closures with an '=' sign. It is now recommended to use methods. So you can do:
def random() {
def allQuotes = Quote.list()
}
or:
public random() {
def allQuotes = Quote.list()
}
See the online docs.
I've been trying to get this working for half a day now. I am trying to use password encryption in my grails app using the bcrypt plugin by Seymour Cakes and Burt Beckwith:
http://grails.org/plugin/bcrypt
I have put the appropriate dependency in my BuildConfig.groovy and in my controller I am trying to run a simple test:
def bcryptService
String goodpwd = "good"
String badpwd = "bad"
String encryptedpwd = goodpwd.encodeAsBcrypt()
println " "
println "Good Password: " + goodpwd
println "Bad Password: " + badpwd
println "Bcrypt Hash Of Good Password: " + encryptedpwd
println "Matching good password: " + (goodpwd.encodeAsBcrypt().equals(encryptedpwd))
println "Matching bad password: " + (badpwd.encodeAsBcrypt().equals(encryptedpwd))
println "Bcrypt Service's match result: " + bcryptservice.checkPassword(goodpwd, encryptedpwd)
but I get this:
Good Password: good
Bad Password: bad
Bcrypt Hash Of Good Password: $2a$10$KvQOvmA4QjH4.JEk4.V2/uXYf8UjKJaUccDijQWG3RkBgAA2LOndS
Matching good password: false
Matching bad password: false
Error |
2014-05-21 14:20:05,935 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver - MissingPropertyException occurred when processing request: [POST] /FatcaOne_0
No such property: bcryptservice for class: com.twc.fatcaone.AdminController. Stacktrace follows:
Message: No such property: bcryptservice for class: com.twc.fatcaone.AdminController
Line | Method
->> 71 | doCall in com.twc.fatcaone.AdminController$_closure5$$EOevDLMH
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sometimes it does that other times it complains that bcryptService is a null. I don't understand what I am doing wrong to not get this dependency injected. Any help greatly appreciated.
If your first chunk of code is inside a method, then make sure you take the
def bcryptService
line out of this block of code and place it at the class level in the controller.
I have a simple Grails application. I did not author the front end, only the business logic layer.
I checked out all the source from SVN and the app starts, but I cannot load the main url. It errors out with the messages below. I have tried refreshing dependencies, but to no avail.
I have spelunked every file I could think of to try to fix this. What gets my attention is the FORWARD slash in front of the css, while the other delimiters in the path are backslashes.
Does anyone have any idea where this is going wrong and how to fix it? Maybe the front end developer needs to check something in?
Error 2013-07-31 13:50:24,036 [http-bio-8080-exec-4] ERROR [/MyClientAppName].[grails-errorhandler] - Servlet.service() for servlet grails-errorhandler threw exception
Message: Error applying layout : main
Line | Method
->> 1110 | runWorker in \grails-app\views\layouts\main.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 603 | run in ''
^ 722 | run . . . in ''
Caused by GroovyPagesException: Error processing GroovyPageView: Error executing tag <r:layoutResources>: Module [bootstrap] depends on resource [/css\bootstrap\bootstrap-responsive.css] but the file cannot be found
->> 464 | runWorker in \grails-app\views\layouts\main.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Caused by GrailsTagException: Error executing tag <r:layoutResources>: Module [bootstrap] depends on resource [/css\bootstrap\bootstrap-responsive.css] but the file cannot be found
->> 8 | doCall in C:/workspaces/GGTS1/MyClientAppName/grails-app/views/layouts/main.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Caused by IllegalArgumentException: Module [bootstrap] depends on resource [/css\bootstrap\bootstrap-responsive.css] but the file cannot be found
->
i'm a bit new on the groovy grails technology and i'm having a problem with this one
i looked at this could not initialize proxy - no Session but the application don't get stale too long
I am trying to access the session object on my SecurityFilter placed on the config subfolder. I just wanted to do a check for every request on the controllers to verify if a user has the rights to do such actions.
class SecurityFilters {
def filters = {
userFilterList(controller:"user", action:"list") {
before = {
if (!session.user.accountType.equals("Admin")) {
redirect(uri: "/")
}
}
}
userFilterShow(controller:"user", action:"show") {
before = {
if (!session.user.accountType.equals("Admin")) {
redirect(uri: "/")
}
}
}
userFilterEdit(controller:"user", action:"edit") {
before = {
if (!session.user.accountType.equals("Admin")) {
redirect(uri: "/")
}
}
}
}
}
but I get this error
Message: could not initialize proxy - no Session
Line | Method
->> 6 | doCall in SecurityFilters$_closure1_closure2_closure5
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 186 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1110 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 603 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 636 | run in java.lang.Thread
before I get to this point I placed the user object on the session object right after doing the login instructions but I am not sure what happened that the session object became not available
some of the properties of the user object were not retrieved, so in the login when I put the user object in the on the session, I also had to manually transfer the property that I needed so I could retrieve again for later use
session.user = user //not enough
session.user.accountType = user.accountType
now I was able to retrieve the user object from the session object and get the property that I wanted to get