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

  • Home
  • SEARCH
  • 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 8084647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:51:36+00:00 2026-06-05T17:51:36+00:00

In my database I have changed the type of a field from VARCHAR to

  • 0

In my database I have changed the type of a field from VARCHAR to DECIMAL. Therefore I have change the type in the java model class from String to BigDecimal.

In my previous XML validation file I have a requiredString fieldValidator. If I leave it, everytime I enter the value (a big decimal) in the form field, the requiredString fieldValidator fires. (maybe a problem with the param interceptor that should convert String to BigDecimal).

Anyway for the same field, I have another field validator which is a REGEX.

So I thought that if I dont use the requieredString, just the regex validator it would work, but not. If i dont fill the field up, no error fires.

So.. to sum up :

my action has a field from the Beneficiary class.
In the Beneficiairy class I have a BigDecimal field.
my xml validation file is like that for this field :

<field name="benef.nirBenef">
    <field-validator type="regex">
        <param name="expression"><![CDATA[^(1|2)\d{14}$]]></param>
        <message key="error.securityNumber"/>
    </field-validator>

when the field is empty, the validation says it is all right.

why ?

when if I use the requiredstring validator, the validation says it is wrong even though the value is good

Thank you

  • 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-05T17:51:37+00:00Added an answer on June 5, 2026 at 5:51 pm

    I found it…it is the same thing for any objects..

    */ Create a file saying what field(s) is/are complex
    Name of the file : name_of_the_action-conversion.properties

    for example my action class is BenefInfos.java, so my properties file is : BenefInfos-conversion.properties

    benef.nirBenef=model.BigDecimalConverter
    benef.nirAssure=model.BigDecimalConverter
    

    the value is the name of my converter class BigDecimalConverter in model package

    */ Create BigDecimalConverter.java

    public class BigDecimalConverter extends DefaultTypeConverter {
    
    @Override
    public Object convertValue(Map Context, Object values, Class classe) {
        BigDecimal field = null;
    
        if(classe == BigDecimal.class) {
            String value = ((String[]) values)[0];
            field = new BigDecimal(value);
        }
    
        return field;
    } 
    

    }

    */Now if you want to VALIDATE, you have to create your own validator. To do so :

    */ add validators.xml to declare your own validator :

    <validators>
        <validator name="socialsecurityformat" 
            class="validator.SocialSecurityValidator"
        />
    </validators>
    

    */Create the validator class (here it is SocialSecurityValidator)

    public class SocialSecurityValidator extends FieldValidatorSupport{
      public void validate(Object o) throws ValidationException {
        String fieldName = this.getFieldName();
    
        if(this.getFieldValue(fieldName, o) != null) {
            String value = ((BigDecimal)this.getFieldValue(fieldName, o)).toString();
            Pattern p = Pattern.compile("^(1|2|7)\\d{14}$");
            Matcher m = p.matcher(value);
    
            if(!m.matches()) {
                addFieldError(fieldName, o);
            }
        }
      }
    

    }

    */ and finally in the validation xml file you use your own validator.

    <field name="benef.nirBenef">
        <field-validator type="required">
            <message key="error.requiredField"/>
        </field-validator>
        <field-validator type="socialsecurityformat">
            <message key="error.securityNumber"/>
        </field-validator>
    </field>
    

    Hope this is helpful

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a field in my model that's of type DecimalField . Even though
I have problem extracting data of the Oracle custom type from the database. One
In rails 3, I have a database model that has a birthday field, of
I have recently changed my web app to create a database connection per command
I have database, and in one the tables I need change the values of
I have a database with Users. Users have Items. These Items can change actively.
I have the following SQL code that runs against a Change Request database. Each
I have Database with date field. I see the time like: 1900-01-01 13:38:00.000 How
I'm pulling data from a database and displaying it in a textarea(s). I have
I have this table in a mysql database: mysql> show columns from wifi_network_config_auth_algorithm; +------------------------+-------------+------+-----+---------+-------+

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.