views:

65

answers:

3

Hi,

I have domain with constraints like min value must greater than 0

I have no idea how to change the message if the constraints are not passed.

which file i need to edit to do that ?

I also need to display the values some properties as well .. like

"you cannot make any transaction because your balance is less than 100. Your current balance is ${currentBalance} after deducted. Your previous balance is ${previousBalance} and amount that need to be deducted ${deductedValue}"

note my class:

class Transaction
BigDecimal previousBalance
BigDecimal currentBalance
BigDecimal deductedValue ; 

constraints currentBalance(min:100)

beforeUpdate => currentBalance = previousBalance - deductedValue 
A: 

Edit your messages.properties file in your grails-app/i18n folder with the messages corresponding with the constraint that was violated. For a plug-in that can help you generate the messages to go along with your constraints see this.

Jared
I need to display another properties as well .. so that the error become clear to user
nightingale2k1
A: 

under grails-app/i18n use messages.properties to add your string (or any other locale you're working with).

If you're domain class is called "user" and the field you have is called "balance" class User{ static constraints = { balance(min:100) } BigDecimal balance; }

, then you'd add:

user.balance.min.error.User.balance= you cannot make any transaction because your balance is less than [{3}].Your current balance is [{2}]

DannyM
I need to display another fields from the same class as well. like deductedValue so that user can be informed why the balance become less than minimum required.
nightingale2k1
Then the Domain contraints might not be the best place to put the message in. You should put the logic in your controller and use the flash.message to display the message. http://www.grails.org/Tag+-+message
DannyM
+1  A: 

The docs give you an understanding of the correct Grails approach to validation error messages.

http://grails.org/doc/1.3.1/guide/7.%20Validation.html#7.4%20Validation%20and%20Internationalization

Also, check out this free ebook, a good introduction to the Grails fundamentals

http://www.infoq.com/minibooks/grails-getting-started

Specifically p28

tinny