Setting TextFieldData based on valueChangeEvent- stackOverFlow Error

Hi Team,
I am working on 2 text fields in vaading table.means i have one vaadin table and in that have one row defined with 2 text fields, based on one text filed value change i wanted to set the another text field value with + symbol(currency debit and credit).



please find the screen shot.


if user enter value in first text filed as D then user enters some currency value in another text field,then for second field change event i need to add + symbol, but value change event is going infinite loop and application is crashing.

code snippet for the same.

[color=#0000FF]
amountTextField.addValueChangeListener(new com.vaadin.data.Property.ValueChangeListener() {
private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
            if(debitCreditTextField.getValue().equalsIgnoreCase("C")){
                
                
            }
            if(debitCreditTextField.getValue().equalsIgnoreCase("D")){
                String str=event.getProperty().getValue().toString();
                amountTextField.setValue("+" +str);;
            
            }        
        }
    });
    amountTextField.setReadOnly(false);
    amountTextField.setImmediate(true);

[/color]

please let me know where i am doing wrong.
13537.png

error stack trace :

Caused by: com.vaadin.event.ListenerMethod$MethodException: Invocation of method valueChange in com.example.vaadinaddontest.VaadinaddontestUI$1 failed.
… 1024 more
Caused by: com.vaadin.event.ListenerMethod$MethodException: Invocation of method valueChange in com.example.vaadinaddontest.VaadinaddontestUI$1 failed.
… 1024 more
Caused by: java.lang.StackOverflowError
at java.util.logging.LogManager.readPrimordialConfiguration(LogManager.java:280)
at java.util.logging.LogManager.getLogManager(LogManager.java:274)
at java.util.logging.Logger.demandLogger(Logger.java:336)
at java.util.logging.Logger.getLogger(Logger.java:390)
at com.vaadin.ui.ConnectorTracker.getLogger(ConnectorTracker.java:91)
at com.vaadin.ui.ConnectorTracker.markDirty(ConnectorTracker.java:401)
at com.vaadin.server.AbstractClientConnector.markAsDirty(AbstractClientConnector.java:138)
at com.vaadin.server.Page.addNotification(Page.java:1083)
at com.vaadin.server.Page.showNotification(Page.java:1098)
at com.vaadin.ui.Notification.show(Notification.java:357)
at com.vaadin.ui.Notification.show(Notification.java:373)
at com.example.vaadinaddontest.VaadinaddontestUI$1.valueChange(VaadinaddontestUI.java:118)
at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969)
at com.vaadin.ui.AbstractField.fireValueChange(AbstractField.java:1127)
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:542)
at com.vaadin.ui.AbstractField.setValue(AbstractField.java:445)
at com.vaadin.ui.AbstractTextField.setValue(AbstractTextField.java:432)
at com.example.vaadinaddontest.VaadinaddontestUI$1.valueChange(VaadinaddontestUI.java:120)
at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:508)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:198)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:161)
at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:969)
at com.vaadin.ui.AbstractField.fireValueChange(AbstractField.java:1127)

Hello Satyanaraya,

This is an intended behaviour for the logic you have coded!


amountTextField
value change listener gets triggered when ever you chage a value in the text box!
The user enters some value in the
amountTextField
and hence value change event is triggered, in the value change listener attached to
amountTextField
you are programatically chaging the value again which triggers value change listener again this happens recursively and hence the stack overflow error.

In order to avoid this scenario make the following changes to your value change listener code -

[code]
@Override
public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
//Inorder to avoid recursive action
if(“ProgramaticallyChanged”.equals(amountTextField.getData())){
amountTextField.setData(null);
return;
}
if(debitCreditTextField.getValue().equalsIgnoreCase(“C”)){

    }
    if(debitCreditTextField.getValue().equalsIgnoreCase("D")){
        //Let the text field know that you have changed the value
        //programatically and preventive action
        amountTextField.setData("ProgramaticallyChanged");
        String str=event.getProperty().getValue().toString();
        amountTextField.setValue("+" +str);;
            
    }        
}

});
[/code]Hope this helps.

Thanks,
Krishna

Hi Krishna,

thank you soo much its working… really took more time on this, any way nice that finally with your help i got resolved this.

can i have your gmail Id, if some thing i stuck i can mail you, because i am new to vaadin .

i am workign vaadin + spring + Hibernate…
as of now everything going fine…

Krishna Kotari:
Hello Satyanaraya,

This is an intended behaviour for the logic you have coded!

amountTextField value change listener gets triggered when ever you chage a value in the text box!
The user enters some value in the amountTextField and hence value change event is triggered, in the value change listener attached to amountTextField you are programatically chaging the value again which triggers value change listener again this happens recursively and hence the stack overflow error.

In order to avoid this scenario make the following changes to your value change listener code -

@Override
public void valueChange(com.vaadin.data.Property.ValueChangeEvent event) {
        //Inorder to avoid recursive action
        if("ProgramaticallyChanged".equals(amountTextField.getData())){
            amountTextField.setData(null);
            return;
        }
        if(debitCreditTextField.getValue().equalsIgnoreCase("C")){
                    
                    
        }
        if(debitCreditTextField.getValue().equalsIgnoreCase("D")){
            //Let the text field know that you have changed the value
            //programatically and preventive action
            amountTextField.setData("ProgramaticallyChanged");
            String str=event.getProperty().getValue().toString();
            amountTextField.setValue("+" +str);;
                
        }        
    }
});

Hope this helps.

Thanks,
Krishna

I’m trying to use ValueChangeLister of the package mentioned in above code. But compilation error, saying that interface is not available. Is there a place when I can get the right JAR file for this? As i’m not using MAVEN project, manually adding all the required Vaadin jar files. Please suggest or point me to the page from which I can download the requred Vaadin jar files.