|
Hi,
This should be really simple - I am trying to do override a default validation error message. I have a domain class called Tree, with a property called name. It cannot be blank.
I have tried many different combinations: package.Tree.name.blank package.tree.name.blank package.tree.name.error Tree.name.blank
tree.name.blank tree.name.error package.Tree.name.blank.message package.tree.name.blank.message package.tree.name.error.message
Tree.name.blank.message tree.name.blank.message tree.name.error.message and probably some more, but the default message is all that is returned. What is more bizarre is when I delete the messages.properties file, or simply remove default.blank.message from it, the default message still appears! BTW, when I save changes to the messages.properties file, I see the running application copy a file to a folder down in ~/.grails/...
Restarting the appplication makes no difference. I'm surely doing something wrong - can anyone please tell me what it is? Kind regards,
Ian Briscoe
|
|
Possibly that some plugin also defines these values ? You could try to search your entire project for the code or the default message you are looking for.
<g:message code="${errorCode}" default="${errorCode}"/> should get you the code if not defined.
// Mohamed On Wed, Aug 24, 2011 at 11:15 AM, Ian Briscoe <[hidden email]> wrote: Hi, |
|
Thanks for the suggestion.
I should add that my application uses Grails largely to provide a RESTful web service. The error message is part of the errors collection returned when validation fails. I then return the message as part of the HTTP response, so there is no GSP rendering involved.
The plugins I have installed are: geb 0.6.0 hibernate 1.3.7 jdbc-pool 0.3 rendering 0.4.2 spock 0.5-groovy-1.7 spring-security-core 1.0.1
tomcat 1.3.7 I either need to know what is the code I should use for a blank field message to override default.blank.message for my domain class, because none in the original message work, or what steps I could try to resolve the issue, because I'm pretty stumped.
I can change the default message, but as I have another domain class which also needs a custom blank message, I can only put in the most generic error message, e.g. Cannot be blank. OK, it works, but it'd be nice to be able to put something a bit less blunt and more specific to the domain class.
Commenting out the customized default results in the original default being used instead, which I can only assume is built into the Grails code somewhere. Ian On 24 August 2011 11:53, Mohamed Seifeddine <[hidden email]> wrote: Possibly that some plugin also defines these values ? You could try to search your entire project for the code or the default message you are looking for. |
|
Each constraint have one or several error codes, defined by the following pat- tern: [DomainName].[PropertyName].[ConstraintCode] for example:
member.username.blank=Username cannot be empty. member.gender.not.inList=Please specify your sex. member.age.range.toosmall=Minimum age is 18. But I can see that you already tried that.
// Mohamed
On Wed, Aug 24, 2011 at 1:36 PM, Ian Briscoe <[hidden email]> wrote: Thanks for the suggestion. |
|
It does seem like I've tried everything, yet it still doesn't work...
How I'm rendering it isn't the issue, but that does make me wonder if I'm missing a step.
I'm using the Spring errors collection directly - do I need to call some other function to get it to resolve the correct message? When I log the errors collection, each error object has the field in error, the rejected value, a collection of codes and the default message.
Do I need to process the error somehow to get my overridden message? Ian On 24 August 2011 13:31, Mohamed Seifeddine <[hidden email]> wrote:
|
|
On 24/08/2011 13:51, Ian Briscoe wrote:
> It does seem like I've tried everything, yet it still doesn't work... > > How I'm rendering it isn't the issue, but that does make me wonder if > I'm missing a step. > > I'm using the Spring errors collection directly - do I need to call some > other function to get it to resolve the correct message? > > When I log the errors collection, each error object has the field in > error, the rejected value, a collection of codes and the default message. > > Do I need to process the error somehow to get my overridden message? Yes, using either the g.message tag call (if you're in a controller) or the messageSource Spring bean. http://johnrellis.blogspot.com/2010/02/retrieve-grails-domain-errors-from.html Ian -- Ian Roberts | Department of Computer Science [hidden email] | University of Sheffield, UK --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Hi Ian, Many thanks! Ian On 24 August 2011 13:55, Ian Roberts <[hidden email]> wrote:
|
| Powered by Nabble | Edit this page |
