grails,error-handling , Grails customised message not working

Grails customised message not working


Tag: grails,error-handling

Github source code

Customised message has been specified, unfortunately it doesn't work.

owner.firstName.blank=You must specify a first name

It shows error message "Property [firstName] of class [class org.grails.samples.Owner] cannot be null" instead of "You must specify a first name".

I have found the same issue in this screencast


The issue you are running into is that you aren't customizing the correct message code. If you read closely you will see it's violating the nullable constraint not the blank constraint.

You should use:

owner.firstName.nullable=You must specify a first name

This may be confusing because in recent versions of Grails the default behavior for handling blank values for Strings was changed to use null instead of blank. There is a configuration option available to control this in Config.groovy if you wish to change back to the old behavior.


How to declare javascript asset in the view to be rendered within the footer using Grails Asset Pipeline

Since there is no deferred option for: <asset:javascript src="custom_view_script.js"/> What else can be used, outside of resource plugin, to place view specific script right before the closing body tag and without declaring it globally in layout? I do know about: <asset:deferredScripts/> but that only handles on page script and not...

Grails: Carry forward params on hyperlink is clicked

How to carry forward the parameters when hyperlink is clicked? Here is my gsp code: <g:link class="grid_link" controller="user" action="delete" id="${}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure, want to delete?')}');">Delete</g:link> Here is my controller code: def delete() { try { def userInstance = User.get( //deleting the user //successful. redirect(action: "list",...

Batch script terminates in case of error when using pipe operator

I need to perferm error handling (check ERRORLEVEL) on an operation involving the pipe operator, but instead of the script continuing with a non-zero ERRORLEVEL, it terminates immediately. How can I avoid this behavior? Consider the following example. (Note that is a simplified constructed example to illustrate the problem -...

How to update a server side datatable on change a checkbox from outside of datatable

I am using data table with Grails. I have a check box outside the data table and on its event I want to load the table again with the check box value. Here are my attempts below : In my view where the check box is >> <g:checkBox id="wrapCheck" name="wrapCheck"/>...

File upload with grails and jquery

I have a form with multiple inputs plus a doc or pdf file upload. //Multiple input fields are here then upload -> <div class="controls"> <div class="fileupload ${ person?.attachment ? 'fileupload-exists' : 'fileupload-new' }" id="attachment" data-provides="fileupload" data-name="attachment"> <span class="btn btn-file"> <span class="fileupload-new">Add</span> <span class="fileupload-exists">Change</span> <input type="file" /> </span> <span class="fileupload-preview"></span>...

python argparse — customizing error messages

I want to generate custom error messages for particular usage errors in my command-line program that uses the argparse library. I know I can override the general presentation of the error by subclassing argparse.ArgumentParser: class HelpParser(argparse.ArgumentParser): def error(self, message): sys.stderr.write('error: %s\n' % message) sys.exit(2) parser = HelpParser(... ...) args =...

[B cannot be cast to java.sql.Blob

This is my domain class class TimesheetSubmission { Date submissionDate=new Date() String foreman String shift String jobId Date date byte[] xmlSubmission String xmlResponse static constraints = { submissionDate nullable: false foreman nullable: false shift nullable: false jobId nullable: false date nullable: false xmlSubmission nullable: true xmlResponse nullable: false } static...

Error when using angular with Grails

Here is my index.gsp <!DOCTYPE html> <html ng-app="myApp"> <head> <title>my app</title> </head> <body> <input type="text" data-ng-model="test"/> {{test}} </body> <script src="/js/angular.min.js"></script> </html> When I build an app, There is an error like this, Uncaught Error: [$injector:modulerr]$injector/modulerr?p0=myApp&p1=Error%3A%…20at%20d%20(http%3A%2F%2Flocalhost%3A8000%2Fjs%2Fangular.min.js%3A17%3A381)...

Grails 3.0 Searchable plugin

I've tried to use the searchable plugin in grails 3.0, but I am not sure wheather it is compatible or not. I've added compile "org.grails.plugins:searchable" to the dependencies. The build completes but yields a NotSearializableException: > Configuring > 1/1 projects > Resolving dependencies ':agent' > Resolving dependencies ': BUILD SUCCESSFUL...

Intellij IDEA long processing for grails app with warning “too much output to process”

I new to Intellij for Grails app while run the app it execute lot of thing with the warning "Too much output to process" & takes comparatively more time to start the server. Below is the log screen ( at at$1.getObject( at...

django: raise an error similar to EmailField

When using an email field, attempting to submit a form with an invalid email address raises and error like this: What I like about this: doesn't reload the page, rather doesn't submit at all and instead displays an error the look Here is what I am able to accomplish currently...

Encryption of strings using AES 128 in Java/grails

I would like to encrypt 3 strings using AES 128 in Java / Grails, and using the code below, but i get the error "An error occurred when encrypting", can someone tell me what is wrong with my code, how to fix it. thanks in advance and to Stackoverflow. String...

Groovy - timestamp from minutes

I have an array or times/values coming back to be in an array like: [0, 60] Which are times in minutes, 0 = 12:00 a.m, 60 = 1:00 a.m. I am wanting to store these in an oracle database as timestamps. How do I convert minutes into timestamps in groovy?...

Python Popen - wait vs communicate vs CalledProcessError

Continuing from my previous question I see that to get the error code of a process I spawned via Popen in python I have to call either wait() or communicate() (which can be used to access the Popen stdout and stderr attributes): app7z = '/path/to/7z.exe' command = [app7z, 'a', dstFile.temp,...

Grails: Do addTo* and removeFrom* require a call to save?

In the docs some examples have a call to save whereas some others do not. I'm assuming that addTo* needs the call to save whereas removeFrom* doesn't. Am I mistaken?

Error handling in Python-MySQL

I am running a little webservice based on python flask, where I want to execute a small MySQL Query. When I get a valid input for my SQL query, everything is working as expected and I get the right value back. However, if the value is not stored in the...

Decode base64 image in Grails [duplicate]

This question already has an answer here: Convert base64 string to image 3 answers I have a post api where I am sending a json string which contain the base64 encoded image.Below is the json string { "imageData":"base64encoded string", "status":"1" } where base64encode string is iVBORw0KGgoAAAANSUhEUgAAAHgAAACgCAIAAABIaz/HAAAAAXNSR0IArs4c6QAA\r\nABxpRE9UAAAAAgAAAAAAAABQAAAAKAAAAFAAAABQAABWL3xrAqoAAEAASURBVHgB\r\nlL2Fe1t7mueZme6uewNGMUu2LNkyySSjDJKZmZkSO8zM7CTmmJnZYbxUVbdgsKp7\r\nqqdrdp I cant post...

Grails 2.3.9 - Error: ClassNotFoundException: grails.plugin.spock.test.GrailsSpecTestType

Whenever I enter the grails command: test-app I get this error: Error executing script TestApp: java.lang.ClassNotFoundException: grails.plugin.spock.test.GrailsSpecTestType (Use --stacktrace to see the full trace) In my BuildConfig.groovy I have: grails.project.dependency.resolution = { ... plugins { ... test ":spock:0.7" } } I've tried replacing it with compile ":spock:0.7" . I've also...

Execute controller function in Grails via Ajax

I am a novice with ajax in Grails. I want to try to execute a controller method from gsp-code from ajax. This is part of my gsp-code: <g:select optionKey="id" name="" id="region" from="${region}" noSelection="[null:' ']" onchange="categoryChanged(this.value);" ></g:select> <div> <b>Sub-Category: </b> <span id="subContainer"></span> </div> <script> function categoryChanged(regionId) { $.ajax({type:'POST',data:'regionId='+regionId,...

Ajax / jQuery: How to communicate Ajax call error back to user

I am new to Ajax and hope someone can help me with this. I use the below Ajax call in an onclick event in jQuery in order to pass data to a PHP file which inserts it into a MySQL db. In the PHP file I echo one of the...

improve the exception handling,parsing,error-handling
Sooo... guys, I have a small trouble with the performance of the exception handling. I'm building... aaaaa... soooo...hmmm...a graph db? yeah something like this... with I'm building the parser, for handling the basic functions of the db(?) What happen? The user makes a research, the program tab them, and...

do try in beginSheetModalForWindow

In Swift 2.0, If I do the following: panel.beginSheetModalForWindow(self.view.window!) { (result) in switch result { // Save was selected case NSFileHandlingPanelOKButton: self.writeFile(fileString, fileURL: panel.URL!) // something else was selected default: break } } With a function as follows, it compiles and works. func writeFile(fileString: String, fileURL: NSURL) { do {...

Throwing general exception in Java

This is for an online tutorial in throwing exceptions I am trying to do something like this: int power(int n, int p){ try { return (int)Math.pow(n,p); } catch(Exception e) { throw new Exception("n and p should be non-negative"); } } But I get the error error: unreported exception Exception; must...

Log Grails Pre 3.0 startup time

In Grails 2.x.x is it somehow possible to log the startup time? We are currently trying to optimize the application startup and having the startup time logged would help tremendously.

Render a controller into a String

I can render a template or a view into a String, but how can I render a controller into a String ? I would like to perform this kind of operation: def myAction = { ... def html = renderToString(controller: 'myController', action: 'myAction', params: [what:'ever']) render modify(html) ... } ...

Redirect if ActiveRecord::RecordNotUnique error exists

I have the next code to save: Transaction.create(:status => params[:st], :transaction_id => params[:tx], :purchased_at =>! But how can I redirect to main root page if this ActiveRecord::RecordNotUnique error appears? Can I catch this error?...

Hibernate proxies - classes with unusual names

While doing some GORM research to better my understanding of GORM, I was using a practice Grails project where I had a Pet domain class. I came across a casting error where I noticed in the error message there was a class with a name like Pet_$$_javassist_3. Is this a...

grails DataSource.groovy refer bean for decoding password

Referring, we need to specify a class with static methods to decode the encrypted password in DataSource config. For passwordEncryptionCodec property, is it possible to refer to a bean defined in resources.xml or any other grails bean definition files? For ex: having a decrypted Properties bean in resoures.xml or...

passing backbone collection to view

I'm just starting out with backbone / grails and i've been struggling to figure out how to get everything to work. I'm building a pricing configurator where a user selects a product type from radio group A and radio group B containing the quantity / pricing / discount data will...

Why does this code catch block not execute?

The catch handler is not run. But why? If the thread t is started before the try block, the catch handler runs. If the catch block's type does not match the type thrown, the program exits explaining that the thread terminated with an uncaught exception, suggesting that the exception is...

empty JTextField and adding number

I have three JTextfields called vol1HH1,vol1HH2,vol1HH3 and fvol. The result of which is output after an actionPerformed event. A user may just input a numbers into vol1HH1 and vol1HH2 but not vol1HH3, how would i ensure that the two numbers were added and the result displayed into fvol without causing...

grails 3.0.1 scaffolded view does not show domain relationship

I am following the example in the book "Grails a Quick-Start Guide" using Grails 3.0.1 with following domains package com.tekdays class TekEvent { static constraints = { name() city() description maxSize:5000 organizer() venue() startDate() endDate() } String city String name TekUser organizer String venue Date startDate Date endDate String description...

Can the mysql_error() function be disabled in php?

I came across in a project of about 900 files with 3 millions lines of code, and my boss asked me to find a solution to prevent mysql_error() to show errors. This is the syntax mysql_query() OR die(mysql_error()) So, how can I disable the mysql_error() from showing errors?...

Swift Errors Thrown from here are not handled

I have had my code working in Xcode 6 but since I got Xcode 7 I cannot figure out how to fix this. The let jsonresult line has an error that says Error thrown from here are not handled. Code is below: func connectionDidFinishLoading(connection: NSURLConnection!) { let jsonresult:NSDictionary = try...

json_decode is returning a null value instead of an array [on hold]

I am trying to search the keyword email in the decoded data. But it is not able to get the array type from json_decode. Here is the code $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $url, CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML,...

Variable not resetting during loop creating misleading output

I have a script here that reads a list of desktops and changes the administrator password of those DTs. It works but I have a minor problem. Once the error shows up in Powershell, the value is never reset. So for example the second DT failed and the third and...

Is there any sdk to log exceptions, events and errors in production app?

I want to catch all the un expected/undesirable events in my app during production. I want something which can send a error log file to server and I can easily read it through a web application. Do you know anything of this sort ?

Grails logging auto inject

I use grails 3.0.2 and logback. How can I use this logger in my code, can I somehow autoinject it, like log.debug() in grails 2.x which was using org.apache.commons.logging.Log?

Grails 3.0.2 missing generate-views

I'm new to grails and I'm trying to get my first HelloWorld from it. I can generate it with the controller, but I can't create a view because it isn't listed in the Grails (3.0.2) list of command. Because any IDE support grails 3.*, I can't create it by that...

alert grails pagination current offset value

I am using Grails 2.4.2. I have a list which is using pagination. When I mouse hover a number or next page icon it shows current offset number as tool tip. Can I alert this offset number or get my list's current page offset number?

Grails: Carry forward params on g:actionSubmit is clicked

How to carry forward the parameters when g:actionSubmit button is clicked? Here is my gsp code: <g:checkBox name="msgCheck" checked="" value="${userInstance.emailId}"></g:checkBox> ... <g:actionSubmit class="update" action="delete" value="Delete" params="${params}"></g:actionSubmit> Here is my controller code: def delete() { try { def user_list = params.msgCheck //deleting the user //successful. redirect(action: "list", params: params) } catch...

Grails JAX-RS Calling a class in src/groovy giving error - Message: No signature of method: is applicable for argument types

While developing the rest api using jaxrs plugin I need to create some common class which I have created in "src/groovy". Below is the class class ValidateToken { String validate(String token){ println(token) return "test" } //... In resource file(jaxrs) this is what I am doing def instance=ValidateToken.validate("test") This throws error...

Permission denied in find: why do we need 2>&1?

I was recently searching for a way to filter out 'Permission denied' errors while searching for a file using the find command, and I found this link: How can I exclude all "permission denied" messages from "find"? Here's an the answer that worked for me from the link: find ....

Intercepting login calls with Spring-Security-Rest plugin in Grails

I am using the spring security rest plugin for Grails to provide a login mechanism for an AngularJS app. Login works fine, but I can't figure out how to intercept login calls, in order to store additional statistics on (invalid/valid) login attempts. As I am quite new to Spring Security...

Grails 2.4.4 spring security role doesn't apply to user

I have controller: class AdminController { def springSecurityService @Secured(['ROLE_ADMIN', 'ROLE_USER']) def index() { render "test"; } And user with role ROLE_ADMIN in the table: But, when I use: springSecurityService.getPrincipal().getAuthorities() There is only one role: ROLE_NO_ROLES Why? def loggedInUser = springSecurityService.currentUser; returns correct user. Config: ... grails.plugin.springsecurity.userLookup.userDomainClassName = '...' grails.plugin.springsecurity.userLookup.authorityJoinClassName =...

On Error Goto doesn't work inside EventHandler subs

Lets assume this code: Module1: Sub main() Dim cl As New Class2 On Error GoTo errorhandler1 cl.DoWork On Error GoTo 0 Exit Sub errorhandler1: MsgBox (Err.Description) End Sub Class1: Event MyEvent() Public Sub DoWork() RaiseEvent MyEvent End Sub Class2: Private WithEvents cl As Class1 Private Sub cl_MyEvent() Call Err.Raise(123, ,...

grails one to many with additional column

In my Grails project I need to have a 1:N relationship between two domain classes. So, I've created the following domain class: class Receipt_HealthService { Receipt receipt HealthService healthService int quantity = 1 static constraints = { } } and in Receipt I have the following: @NotNull static hasMany =...

Python internal error Handling

I'm having issues with my program just closing at random stages and am not sure why. At first, I thought it was because it was getting an error but I added an error handle. still for some reason it just closes after say a few days of running and no...

unable to resolve class in grails

I am developing a module in which some file need to be uploaded on a ftp server for that I have added the "commons-net-3.3.jar" in my grails app & while using it import import import import import It is throwing the error unable to resolve...

Use data-* attribute in grails generated in tagLib

Is there a way to use data- attributes in generated by a tagLib? I want to store some DOM info instead of using params in the which results in query parameters. Example: out << "calendar", action: "info", params: [id: cal_id], data-info: "abc") { "click me " }...