0

decimalbox with , and .

asked 2009-11-18 10:44:14 +0800

guisimon gravatar image guisimon
217 7
http://www.artsys.fr

Hi all

is there a way to enable the user to put , and . to set a number in a decimalbox ?

thanks

delete flag offensive retag edit

14 Replies

Sort by ยป oldest newest

answered 2009-11-24 00:19:26 +0800

henrichen gravatar image henrichen
3869 2
ZK Team

@guisimon,

It will need a special parser. Will need to distinguish 123,456,789 and 123,456.789, etc.

Until there is a clear spec. about the mixing of ',' and '.' in the number, it is hard to make this as an ZK generic solution...

In the mean time, you can use textbox and parse the input in the application...

link publish delete flag offensive edit

answered 2010-04-12 08:28:29 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2010-04-12 08:29:29 +0800

@YADA

Have you running codes for such an input box for us?

thx
Stephan

link publish delete flag offensive edit

answered 2017-01-10 08:41:47 +0800

digulla gravatar image digulla
506 5

updated 2017-01-10 08:53:13 +0800

There is no simple solution for this. The comma in the format pattern means "put the grouping symbol here"; it doesn't mean "use a comma".

Which symbol is used depends on the Locale or rather the DecimalFormatSymbols used in the DecimalFormat. You can specify your own; it you don't then the current locale will be used to determine the symbols.

That means the solution is to write your text input, install a converter and use that instead of Decimalbox. In the converter, create your own DecimalFormatSymbols and configure it with the symbols you want.

Note: This would be much easier if NumberInput.getRealSymbols() was protected...

link publish delete flag offensive edit

answered 2017-01-10 09:31:13 +0800

digulla gravatar image digulla
506 5

updated 2017-01-12 16:29:59 +0800

This code seems to work with ZK 8:

import java.text.DecimalFormatSymbols;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.zkoss.json.JSONValue;
import org.zkoss.zul.Decimalbox;

public class SymbolDecimalbox extends Decimalbox {

    private static final long serialVersionUID = 1L;

    private DecimalFormatSymbols symbols;
    private Locale locale;

    /** Hide the parent method to make sure org.zkoss.zul.impl.NumberInputElement.getRealSymbols() is never called. */
    @Override
    public void setLocale(Locale locale) {
        this.locale = locale;
    }

    /** Hide the parent method to make sure org.zkoss.zul.impl.NumberInputElement.getRealSymbols() is never called. */
    @Override
    public Locale getLocale() {
        return locale;
    }

    public void setSymbols(DecimalFormatSymbols symbols) {
        this.symbols = symbols;
    }

    public DecimalFormatSymbols getSymbols() {
        return symbols;
    }

    //super//
    @Override
    protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)
    throws java.io.IOException {
        super.renderProperties(renderer);

        // By overriding setLocale(), we make sure org.zkoss.zul.impl.NumberInputElement.getRealSymbols() is never called.
        renderer.render("localizedSymbols", getRealSymbols());
    }

    /** Send the specified symbols to the UI. */
    private String getRealSymbols() {
        if (symbols != null && locale != null) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("GROUPING",
                    String.valueOf(symbols.getGroupingSeparator()));
            map.put("DECIMAL",
                    String.valueOf(symbols.getDecimalSeparator()));
            map.put("PERCENT", String.valueOf(symbols.getPercent()));
            map.put("PER_MILL", String.valueOf(symbols.getPerMill()));
            map.put("MINUS", String.valueOf(symbols.getMinusSign()));

            final String localeName = locale.toString();
            return JSONValue.toJSONString(new Object[] { localeName, map });
        }
        return null;
    }
}
link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-11-18 10:44:14 +0800

Seen: 1,512 times

Last updated: Jan 12 '17

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More