How to listen to the unselect of Listbox item in ZK Composer - zk

Currently I'm Listening in composer on the select event of the Listbox. Now I want to raise the event on unselect of the checkmark of the listbox item so as to know which item is deselected from the listbox.
Is there any Zk's functionality available for this or have to apply some custom logic?

This question is written before checking the Java Doc.
https://www.zkoss.org/javadoc/7.0.2/zk/org/zkoss/zk/ui/event/SelectEvent.html
Unselecting raise a selectevent, and guess, there is even a method what gives you the unselected items.

Related

GWT Deselect keyboard selection

When keyboard selecting a row in a GWT DataGrid, how do you deselect it?
When you select a row like this:
table.setKeyboardSelectedRow(rowInd, true);
You can unselect the row by clicking outside the grid. How do I make this same 'unselection' programmatically?
Selecting a row like this:
table.setKeyboardSelectedRow(rowInd, false);
Since the focus is not on this selection, it does not blur out like usual when you click outside the grid. I need to keep the focus on something else, but I wish to still deselect this row at a certain point. How do you deselect a keyboard selection programmatically?
Note: using the Selection Model's setSelection() with a false param does not deselect keyboard selection, only the selection made by the selection model. Using setKeyboardSelectedRow(-1) also does not work.
I find it baffling that GWT does not offer a way to unselect a keyboard selected row!

Why is setItem on JComboBox is called twice?

I have a JComboBox with a custom Editor.
Why I make a selection from the dropdown list, I find that setItem() method of the Editor is called twice with the same selected item from the drop list.
Why is that?
As explained here:
It fires twice because one item becomes DESELECTED and another becomes SELECTED. Event fires for both. You can check which one occured by calling e.getStateChange().

Auto complete a dropdown menu in a cq5 dialog based on input from a previous dialog field

My custom CQ5 component has a dialog which consists of 2 drop down menus. I would like to automatically set a default value to second menu depending on whatever is the value selected from the previous drop down.
How can I achieve this?
you can register handlers for different events triggered by the widgets. You can use the "selectionchanged" event to register a function that will read the new content from the dropdown and then use the setValue() method in the second dropdown to put whatever you want there.
To obtain the second dropdown from the first you can use the nextSibling() method.
The widget documentation will help you a lot. look for "selection"

GWT Datagrid selection

I would like to reject the selection of a row in a datagrid based on the state of a form. If the form has fields with changed data, I would like the row selection to rejected.
Is there an event I could trap (before selection) and cancel or do I have to implement the logic myself?
You can either use a SelectionChangeHandler on your SelectionModel (it gives you an object which was selected, and you can unselect it), or you can use the CellPreviewHandler on your DataGrid (it gives you a row which was clicked - event.getContext().getIndex() - and you can unselect it in your SelectionModel).
The choice depends on what you want to do after the event: you have to do something obvious in your UI so that users are not confused why clicking on one row selects it, while clicking on another row does not. For example, you can change the background color of unselectable rows as soon as you render your DataGrid, and then show an error message when the wrong row is selected.

GWT ListBox getSelectedIndex() not working as intended when hovered over list items

I have a GWT ListBox. My validation code inquires whether the ListBox's selected index is -1 (my ListBox's default state). If I do not touch the ListBox, the getSelectedIndex() returns -1, as expected. If I hover over the ListBox items but do not click on one (i.e. click outside), getSelectedIndex() returns a non-(-1) index. I want it to return -1 unless I click on a ListBox item and the ListBox updates itself to reflect that selection.
What should I do?
You won't be able to use the native <select> element for this in a nice way since the browsers determine what the selected element is, not GWT. In other words, this is just how <select> works.
You'll have to either create your own select widget (which might be preferred for styling reasons anyway) or get creative and kludge up something next to the existing widgets. You could add a click handler to the ListBox and "manually" set the selected index to -1, but you'll have to figure out if the user cancels his operation and restore the selection afterwards. You'll have to suppress selection events from your custom code because you probably don't want the rest of your app to react to your new -1 hack. Ugh! Probably easiest to handle this in a different way.