1. #1
    Ext User
    Join Date
    Apr 2010
    Posts
    34
    Vote Rating
    0
    Kirua007 is on a distinguished road

      0  

    Question Personnal composite for currency field

    Personnal composite for currency field


    Hi,

    I try to make a personnal composite for currency field with one label

    I create a Java Class extended Composite.
    I try to use a afteredit listener for formatting text in the field. But, the event is never called

    Code:
    public class ComplexAmountField extends Composite {
        
        
        ElementType myElement;
        int size;
        String label;
        TextField textField ;
        Html libelle;
        
        public ComplexAmountField(ElementType element,int size,String htmlLabel)
        {
            myElement=element;
            textField = new TextField<String>();
            textField.addListener(Events.AfterEdit, new Listener<BaseEvent>() {
    
                @Override
                public void handleEvent(BaseEvent be) {
                    be.getClass();
                    be.getSource();
                }
                
            });
            textField.addListener(Events.StartEdit, new Listener<BaseEvent>() {
    
                @Override
                public void handleEvent(BaseEvent be) {
                    be.getClass();
                    be.getSource();
                }
                
            });
            textField.setWidth(size);
            
            libelle = new Html(htmlLabel);
            libelle.setWidth(150);
            label = htmlLabel;
            HorizontalPanel horizontalPanel = new HorizontalPanel();
            horizontalPanel.setSpacing(10);
            horizontalPanel.add(libelle);
            horizontalPanel.add(textField);
            this.size=size;
            initWidget(horizontalPanel);
        }
    Anyone can help me please ?
    Thank you

  2. #2
    Ext User
    Join Date
    Apr 2010
    Posts
    34
    Vote Rating
    0
    Kirua007 is on a distinguished road

      0  

    Default


    Solved !

    Code:
    textField = new TextField<String>();
            textField.addListener(Events.Change, new Listener<BaseEvent>() {
    
                @Override
                public void handleEvent(BaseEvent be) {
                    try {
                        Double d = Double.parseDouble((String)textField.getValue());
                        NumberFormat format = NumberFormat.getCurrencyFormat();
                        String outVal = format.format(d);
                        textField.setValue(outVal);
                    } catch (NumberFormatException e) {
                        //
                    }
                    
                    
                }
    });