isChecked() returns 'false' after CheckBox is marked in LayoutClickEvent listener

Hello,
we have a checkBox which is being created programatically based on some logic and added to a screen.
The checkbox is not added to a descriptor as we would like to have multiple rows with checkboxes created one after another, and the row count could be different every time.
We would like to have the value of the checkBox verified upon click so we can use its value as a condition for another component that needs to be displayed.
We are trying to get the checkBox value using vbox LayoutClickEvent, but we are getting ‘false’ on Boolean isChecked = ((CheckBox)event.getClickedComponent()).isChecked(); when we mark the checkBox
and ‘true’, when we unmark it (I presume this is because LayoutClickEvent is executed before CheckBox ValueChangeEvent).
Could you please advise if this is an expected behavour and what would be the appropriate approach for the case I described above?

I’m attaching a demo application which would help you to reproduce the behavior as well as to get familiar with the base structure that we are using for the described steps.

Kind regards,
Dimitar
ClearDataContextDemo.zip (416.2 KB)

Hello!

Thank you for the demo project! Yes, the LayoutClickEvent is fired before the ValueChangeEvent of CheckBox.

Could you clarify the reason of listening LayoutClickEvent? Doesn’t ValueChangeEvent that contains old and new values suit you? Value of the CheckBox you can validate before the sensitive part of the code.

Hello,
sorry for the late response. We use LayoutClickEvent, because we actually draw the elements runtime as their count will be depending on user input and we couldn’t figure out a way to subscribe to ValueChangeEvent for items that we don’t know if they would exist or not
.
The way we managed to solve this is by adding valueChangeEventListener programatically once a checkBox has been drawn and then clicked. The listener calls specific method which handles the logic.

Thanks again for looking into this and please accept my apologies for the late response.

Kind regards,
Dimitar

1 Like