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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:16:45+00:00 2026-05-23T17:16:45+00:00

In a Wicket app, I have a decimal number text field: TextField<BigDecimal> f =

  • 0

In a Wicket app, I have a decimal number text field:

 TextField<BigDecimal> f = 
     new TextField<BigDecimal>("f", new PropertyModel<BigDecimal>(model, "share"));

I want it to always accept both . (dot) and , (comma) as decimal separator (regardless of browser’s locale settings).

For showing the value, session’s locale is used [which in our case is forced to be “fi” (-> comma)], but here I’m interested in what the field accepts as input.

My question is, do I have to change the field to TextField<String>, and convert to domain object’s type (BigDecimal) manually? Or is there some way to use TextField<BigDecimal> (which allows e.g. making use of Wicket’s MinimumValidator or RangeValidator), and still have it accept both decimal separators?

  • 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-05-23T17:16:46+00:00Added an answer on May 23, 2026 at 5:16 pm

    Thanks to @bert’s comment, and the Wicket in Action book, I found an approach that works. In the Application class specify a custom converter for BigDecimals:

    @Override
    protected IConverterLocator newConverterLocator() {
        ConverterLocator converterLocator = new ConverterLocator();
        converterLocator.set(BigDecimal.class, new CustomBigDecimalConverter());
        return converterLocator;
    }
    

    And in the custom converter, convertToObject needs to be overridden. NB: this is sufficient for our needs; think about your requirements and adapt as needed!

    public class CustomBigDecimalConverter extends BigDecimalConverter {
    
        @Override
        public BigDecimal convertToObject(String value, Locale locale) {
            // NB: this isn't universal & your mileage problably varies!
            // (Specifically, this breaks if '.' is used as thousands separator)
            if ("fi".equals(locale.getLanguage())) {
                value = value.replace('.', ',');
            }
            return super.convertToObject(value, locale);
        }
    }
    

    Edit: Offtopic, but I want to document this too. We needed our app to support a scale of 4 decimal places, and our custom BigDecimal converter nicely solves that problem too.

      @Override
        public String convertToString(Object value, Locale locale) {
            NumberFormat fmt = getNumberFormat(locale);
            fmt.setMaximumFractionDigits(4); // By default this is 3.
            return fmt.format(value);
        }
    

    After this customisation, a decimal number like 2.0005 will be shown as 2.0005 instead of 2.

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

Sidebar

Related Questions

I want to create a web app that will use wicket, hibernate and spring
I'm new to wicket and stuck with the following problem: I have a table
I have a small Wicket app that I can deploy to Glassfish v3 without
We have a Wicket app with a page that includes an embedded Youtube video.
I have a Wicket 1.4.17 app in a standalone app in embedded Jetty 6.1.26.
In my wicket app, I want to use my own converter for some textfields
In my Wicket app, I have a page with radio buttons and <label for=...>
I'm designing a new app based on JPA/Hibernate, Spring and Wicket. The distinction between
In a Wicket 1.4 app, I have some static CSS & JS resources under
in my wicket application I have 3 checkbox in form: add(new CheckBox(1).setOutputMarkupId(true)); add(new CheckBox(2).setOutputMarkupId(true));

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.