Finding the focused control

Hello!
Is it possible to detect the focused (clicked last) control element on the screen
from a button click event handler?

This discussion suggests it’s not possible, so maybe there’s an alternative solution to my problem, which is this -

I have four options lists populated with names of IoT devices, so when a user clicks
one of them and then clicks a certain button on the page I want to be able to show them
this device’s history.

While I do handle option lists’ HasValue.ValueChangeEvent events, they are not fired
when the user clicks the same options list item that was previously selected in that
options list.

To illustrate the problem, imagine having two options lists, A and B.
A is populated with the following strings: 0001 and 0002.
B is populated with 0003 and 0004.

The user fist clicks 0004 in B, then 0001 in A and finally clicks 0004 in B
again. This last click is not going to fire HasValue.ValueChangeEvent for B,
because 0004 was previously selected in B, hence no value change for that
option list.
In this case, if the user clicks on the button, intending view 0004, the system
will show 0001, since the last HasValue.ValueChangeEvent was fired for A.

Hello @a.kireev,

The optionsList does not support the functionality you want.

In platform version 7.2.0. you can use the Table component and Table.Column.ClickEventListener. You can create the table with one column and this will repeat your case with OptionsList component.

@Subscribe("customersTable.name")
public void onCustomersTableNameClick(Table.Column.ClickEvent<Customer> event) {
// This event will fired with every click on a Table item.
}

In previous versions, the behavior described above will not always work, because the click listener only works on a click on the text, and not on a click in the whole cell - the details are in the issue.

Regards,
Gleb

1 Like

Thank you, this worked (with CUBA 7.20).