javagwtgwt-bootstrap

How put a mask in a TextInputCell?


I have a TextInputCell in a Column, like this:

TextInputCell textCell = new TextInputCell();
    Column<EffortCost, String> hourColumn = new Column<EffortCost, String>(textCell) {  
        public String getValue(EffortCost object) {
            String formatted = NumberFormat.getFormat("0.00").format(object.getHours());

            return formatted;
        }
    };

My string returned: "1.00" if I wrote "1". I want the same result, but I don't wanna formated the string, I want my widget doing this in a moment I put the text in the TextInputCell, in other words, I want format the string automatically while I write the text in my TextInputCell. This would be like a "MaskedTextInputCell". How can I do this? Can I see some examples?

Thanks for attention.


Solution

  • You can add a FieldUpdater for your hourColumn. It has update() method which fires when value of a cell in this column changes. For example:

    hourColumn.setFieldUpdater(new FieldUpdater<EffortCost, String>() {
    @Override
    public void update(int index, EffortCost object, String value) {
        // do something when value changes
        // return NumberFormat.getFormat("0.00").format(object.getHours());
    }
    });
    

    every time when you enter numbers it will format and update.