1. #1
    Ext User
    Join Date
    Oct 2008
    Posts
    22
    Vote Rating
    0
    hbrands is on a distinguished road

      0  

    Default issue with NumberField and form binding

    issue with NumberField and form binding


    Attached is a sample which should demonstrate the issue:
    We have run this with a german locale where the groupingSeparator is '.'
    and the decimalSeparator is ','.
    When you start the app you will see a panel with an amount number field containing
    an initial value of "123.456,45".
    Now, when you delete the last three characters with backspace (with "123.456" remaining) and go to the next field, the amount turns into "123,46".
    It should be "123.456,00", shoudn't it?

    Holger

    Code:
    public class NumberFieldBug implements EntryPoint {
    
        private static NumberConstants NUMBER_CONSTANTS;
    
        private final LayoutContainer contentContainerPanel = new LayoutContainer();
        private Widget content;
        private final Viewport viewport = new Viewport();
    
        public void onModuleLoad() {
            ThemeManager.register(Slate.SLATE);
            contentContainerPanel.setLayout(new FitLayout());
            viewport.setLayout(new BorderLayout());
            final BorderLayoutData westLayoutData = new BorderLayoutData(LayoutRegion.WEST, 200);
            westLayoutData.setMargins(new Margins(5));
            westLayoutData.setSplit(true);
            westLayoutData.setCollapsible(true);
            final BorderLayoutData centerLayoutData = new BorderLayoutData(LayoutRegion.CENTER);
            centerLayoutData.setMargins(new Margins(5, 5, 5, 0));
            viewport.add(contentContainerPanel, centerLayoutData);
            final BorderLayoutData northLayoutData = new BorderLayoutData(LayoutRegion.NORTH, 33);
            northLayoutData.setMargins(new Margins());
            RootPanel.get().add(viewport);
            NUMBER_CONSTANTS = (NumberConstants) GWT.create(NumberConstants.class);
            final Widget initialContent = createInitialContent();
            setContent(initialContent);
            GWT.log("groupingSeparator=" + NUMBER_CONSTANTS.groupingSeparator(), null);
            GWT.log("decimalSeparator=" + NUMBER_CONSTANTS.decimalSeparator(), null);
        }
    
        private Widget createInitialContent() {
            BeanModelFactory factory = BeanModelLookup.get().getFactory(MyBean.class);
            final MyBean data = new MyBean();
            data.setAmount(123456.45d);
            data.setComment("Test");
            BeanModel beanModel = factory.createModel(data);
            final FormPanel result = new FormPanel();
            result.setFrame(true);
            result.setHeaderVisible(false);
            result.setBodyBorder(false);
            result.setBorders(false);
            result.setLabelWidth(120);
            result.setLabelAlign(LabelAlign.TOP);
            result.setSize(250, 450);
    
            final String decimalPattern = "#,##0.00";
            final NumberField amountField = new NumberField();
            amountField.setAllowBlank(false);
            amountField.setAutoValidate(true);
    //        amountField.setFormat(NumberFormat.getFormat("#0.##"));
            amountField.setDecimalSeparator(NUMBER_CONSTANTS.decimalSeparator());
            final NumberFormat format = NumberFormat.getFormat(decimalPattern);
            amountField.setFormat(format);
            amountField.setName("amount");
            amountField.setFieldLabel("Amount");
            result.add(amountField);
            final TextField<String> commentField = new TextField<String>();
            commentField.setSelectOnFocus(true);
            commentField.setAutoValidate(true);
            commentField.setName("comment");
            commentField.setFieldLabel("Comment");
            result.add(commentField);
            final FormBinding binding = new FormBinding(result, true);
            binding.bind(beanModel);
            return result;
        }
    
        private void setContent(Widget newContent) {
            if (content != null) {
                contentContainerPanel.remove(content);
                content = null;
            }
            contentContainerPanel.add(newContent);
            content = newContent;
            contentContainerPanel.layout();
            contentContainerPanel.show();
        }
    
    
        public static class MyBean implements BeanModelTag, Serializable {
            private Double amount;
            private String comment;
            public Double getAmount() {
                return amount;
            }
            public void setAmount(Double amount) {
                this.amount = amount;
            }
            public String getComment() {
                return comment;
            }
            public void setComment(String comment) {
                this.comment = comment;
            }
        }
    }

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Try to dont setup a own numberformat etc. Let the locale handle it.

  3. #3
    Ext User
    Join Date
    Oct 2008
    Posts
    22
    Vote Rating
    0
    hbrands is on a distinguished road

      0  

    Default


    Sorry, I don't understand.
    It should be possible to use a custom number format.
    I think the problem is in method
    Code:
    public Number convertStringValue(String value);
    of class
    Code:
    com.extjs.gxt.ui.client.widget.form.NumberPropertyEditor
    It tries to convert the string value to a number without considering the format first.
    Obviously, "123.456" can be parsed directly into a double, but that's the wrong thing
    to do in this case. It should delegate to the format to parse the value.

    WDYT?

    Holger

  4. #4
    Ext User
    Join Date
    Oct 2008
    Posts
    22
    Vote Rating
    0
    hbrands is on a distinguished road

      0  

    Default


    Do you agree that there is a problem in method
    Code:
    NumberPropertyEditor.convertStringValue
    if you use
    - form binding with a Double bean property
    - use a NumberFormat with a grouping separator '.'
    - and edit the field value as I described above?

    In my opinion, it's problematic to first try to parse the Double directly.
    I think, if a format is set, it should be used to parse the value.

    Thoughts?

  5. #5
    Ext User
    Join Date
    Oct 2008
    Posts
    22
    Vote Rating
    0
    hbrands is on a distinguished road

      0  

    Default


    Any info about the status of this issue?
    Do you intend to do something about it?

    Thanks,
    Holger

  6. #6
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    It is on the list.

  7. #7
    Ext GWT Premium Member
    Join Date
    Oct 2009
    Posts
    66
    Vote Rating
    0
    bogusky is on a distinguished road

      0  

    Default


    hi,

    we have encountered the same problem. When this bug is going to be fixed ?

Thread Participants: 2

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi