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 8311161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:43:14+00:00 2026-06-08T19:43:14+00:00

I am trying to add a custom validator for the String state, which should

  • 0

I am trying to add a custom validator for the String state, which should check if the string country is “usa”, then the state should be “Other”. If country is not “usa” and state is “other” then it should throw an error.

Also, I would like to add a custom validator for country to do the same.

Please find the code for my domain class below.

package symcadminidp

import java.sql.Timestamp

import groovy.transform.ToString

@ToString
class Account {

static auditable = [ignore:['dateCreated','lastUpdated']]

String organization
String organizationUnit 
String status
String address1
String address2
String zipcode
String state
String country

Timestamp dateCreated
Timestamp lastUpdated

Account(){
    status = "ENABLED"
}


static hasMany = [samlInfo: SAMLInfo, contacts: Contact]
static mapping = {
    table 'sidp_account_t'
    id column: 'account_id', generator:'sequence', params:[sequence:'sidp_seq']
    contacts cascade:'all'
    accountId generator:'assigned'

    organization column:'org'
    organizationUnit column:'org_unit'
    zipcode column:'zip'
    dateCreated column:'date_created'
    lastUpdated column:'date_updated'
}
static constraints = {
    organization size: 1..100, blank: false
    organizationUnit size: 1..100, blank: false, unique: ['organization']
    //The organizationUnit must be unique in one organization 
    //but there might be organizationUnits with same name in different organizations, 
    //i.e. the organizationUnit isn't unique by itself.
    address1 blank:false
    zipcode size: 1..15, blank: false
    contacts nullable: false, cascade: true
    status blank:false
    //state ( validator: {val, obj ->  if (obj.params.country.compareTocompareToIgnoreCase("usa")) return (! obj.params.state.compareToIgnoreCase("other"))})
        //it.country.compareToIgnoreCase("usa")) return (!state.compareToIgnoreCase("other"))}
}
}

When I tried adding the above commented out code, I got the following error:

URI: /symcadminidp/account/index
Class: groovy.lang.MissingPropertyException
Message: No such property: params for class: symcadminidp.Account

I am new to grails and groovy and would appreciate any help with this issue.

  • 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-08T19:43:15+00:00Added an answer on June 8, 2026 at 7:43 pm

    The second value to your validator ( obj ) is the Account domain class.

    A custom validator is implemented by a Closure that takes up to three
    parameters. If the Closure accepts zero or one parameter, the
    parameter value will be the one being validated (“it” in the case of a
    zero-parameter Closure). If it accepts two parameters the first is the
    value and the second is the domain class instance being validated.

    http://grails.org/doc/latest/ref/Constraints/validator.html

    Your validator should be something like

    state validator: { val, obj -> 
        return ( obj.country.toLowerCase() == 'usa' ) ?
               ( val.toLowerCase() != 'other' ) : 
               ( val.toLowerCase() == 'other' ) 
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add a custom validator to a field. It should take into
I'm trying to add a custom HTTP Validator as shown here . I want
I have a very basic entity model which I'm trying to add custom validation
I am trying to add custom icons to a Shared Add-in for Microsoft Word.
I'm creating a custom WP theme and trying to add custom menus to the
I'm trying to add a custom class to the jQuery Mobile theme. The CSS
I am trying to add a custom log handler to my java application. I
I am trying to add a custom field to the user form in the
I'm trying to add a custom catalog index based on the recommendation here: http://collective-docs.readthedocs.org/en/latest/searching_and_indexing/indexing.html#custom-index-methods
I am trying to add a custom UIBarButtonItem to my navigationItem. This button will

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.