Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8613497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:53:30+00:00 2026-06-12T04:53:30+00:00

Environment: Grails 2.0.4, Java 1.6.0 I’d like to put a constraint on a Domain

  • 0

Environment: Grails 2.0.4, Java 1.6.0

I’d like to put a constraint on a Domain Object value requiring an integer value to prevent a decimal value from being entered. Entering 3.3 in the view results in the object being created with a value of 3. I was hoping for a validation error that would be kicked back to the user indicating only integer values are valid.

class ADomainObject {
    Integer    anInteger
}

Controller

def save() {
   // Note: params["anInteger"] = "3.3"

   ADomainObject aDomainObject = new ADomainObject(params)
   aDomainObject.save flush:true
}

Result in the persistence of aDomainObject.anInteger = 3

What type of constraint would be needed to cause a failure? I’ve tried using a range constraint, [0..1000], to no avail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T04:53:32+00:00Added an answer on June 12, 2026 at 4:53 am

    You can register a custom property editor for Integers to only allow strictly Integer values. The following will apply to binding all Integers.

    class IntegerEditor extends java.beans.PropertyEditorSupport {
        void setAsText(String text) {
            value = Integer.parseInt(text)
        }
    }
    
    class CustomPropertyEditorRegistrar implements org.springframework.beans.PropertyEditorRegistrar {
        void registerCustomEditors(org.springframework.beans.PropertyEditorRegistry registry) {
            registry.registerCustomEditor(Integer, new IntegerEditor())
        }
    }
    

    and then in resources.groovy:

    beans = {
        customPropertyEditorRegistrar(CustomPropertyEditorRegistrar)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Environment: Mac osx lion Grails version: 2.1.0 Java: 1.7.0_08-ea If I start up vertx
Afer upgrading a grails application from 1.3.7 to 2.0, a java NullPointerException is being
ENVIRONMENT: C# I have a table of equivalent values, like this: CHEVR = CHEVROLET
Environment: hudson/sonar/maven2 in ubuntu locally with default parameters And I got the log from
Environment: Windows XP, SpringSource Tool Suite 2.3.2, Roo 1.0.2.Release, Java 1.6.0_10, tc Server 6.0
Environment Grails 1.2.2 Ubuntu 9.10 IntelliJ 9.0.3 Everything works fine in IntelliJ. When I
In a unix environment, I want the .grails folder to go somewhere other than
I'm just getting started with Groovy/Grails. I added a new domain controller to my
Every time that I start up my grails application, using the production environment on
I just upgraded to grails 2.1.. the latest release available, from grails 1.3.7, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.