Textfield key press listener

Instead of using value change listener which is triggering the query for every 2-3 chars ( though using value change mode as LAZY) I’m using Keypress listener and only when ENTER key is pressed, I do the DB search. Is this the right way or any other better way is there to achieve the same ( trigger DB search only when ENTER key is pressed ) ?

And another problem I’ve with this KeyPress is, I’m unable to get the textfield value as there is no method available to get it. So, it works when the field is declared at the class level but not when dynamically textfield is created

This is a case with a 3rd party library. But this work TextField textField = (TextField) input.getComponent(); textField.addKeyDownListener(Key.ENTER, event -> filterChangeConsumer.accept(textField.getValue()));

Why you do not use?


Then value change is emitted on Enter or blur, isn’t that what you want?

This is working bit different. If user moves into a different field also, this is triggering event

how do I disable that?

I tried this withBlurListener(ComponentEvent::unregisterListener)

But I got this java.lang.IllegalStateException: unregisterListener can only be called inside the event listener

If user moves into a different field also, this is triggering event
There would be a lot of bad consequences if it would not.

ok. May be I’m over thinking. If this is the standard, I’ll go with that