What is the replacement for ListSelect in Vaadin 22? - vaadin

I'm trying to update an application from Vaadin 7/8 to Vaadin 22.
ListSelect is gone, so I need a new widget field that satisfies these requirements:
Allows choosing multiple items
Suitable for use in FormLayout with value bound using Binder
Scrolls automatically when there are more than a handful of choices
None of the widgets in Vaadin 22 seem to qualify:
Select and ComboBox only choose one item
ListBox says ...designed to be used as a lightweight scrollable selection list rather than a form input field
Grid does not implement HasValue so can't be used with Binder
CheckBoxGroup doesn't look like it will scroll (requirement #3) (I haven't actually tried yet though)
What am I missing here?? What is the new equivalent of the old ListSelect?

If your Grid is set to multiselect mode, you can use grid.asMultiSelect() to return a MultiSelect object that does implement HasValue and can be used with Binder. Similarly, in single-select mode, grid.asSingleSelect() returns a bindable SingleSelect object.

Related

Set maxLength attribute on ComboBox

I want to add a maxLength to the custom value on the ComboBox but when I do
getElement().setAttribute("maxLength","30");
Vaadin add it to the wrapping vaadin-combo-box element. How can I access from Java the underlying highlighted input element as show in the picture?
Applying a max-length on the client-side does not guarantee that the value on the server-side is secured.
Instead of mingling with the inner workings of the ComboBox's field, I would suggest to apply this validation on the server-side. In the ComboBox::addCustomValueSetListener or by using a StringLengthValidator on the Binder you have attached to the form/field.
Vaadin ComboBox doesn't support setting a max length to custom values (although TextField does).
You could create a feature request ticket about it here: https://github.com/vaadin/web-components/issues/new?assignees=&labels=&template=feature-request.yml
I found out that you can executejs on client side through element API. I solved using this snippet:
element.executeJs("this.childNodes.item(0).maxLength = 30")
"childNodes.item(0)" is the underlying input element of combobox

IBM BPM: Is it possible to hide a column of a table dynamically based on user choice?

Since I'm new to this technology (Coach UI) I wanted to know an information, is it possible to delete a column based on the user's choice?
That is, I have a modal that contains the column fields and if I choose to hide a column it hides it dynamically.
Thank you in advance for the reply, I have been on this problem for 2 days :(
Configurations of Controls in BPM can be either provided with values or bound to a variable.
Binding configuration item to a variable will give you the ability to change it dynamically, by changing the value of that variable.
For your request, you can click on the purple icon next to Columns (image bellow) to switch to binding mode, then select a varible of type TableColumn (This BO is available in the UI Toolkit itself, open the BO to check the documentation).

ComboBox with hidden keys

Is it possible in vaadin 12 to have comboboxes such that it displays a user-friendly value but behind the scenes it stores a hidden code? I found this example from 5 years ago but it doesn't apply to Vaadin 12 comboboxes: https://vaadin.com/forum/thread/7821327/combo-box-hidden-values
(If there's a good, reasonably clean way to do it, please point me in the right direction! I would think this is a common sought-after feature)
Items are assigned to ComboBox either directly using setItems or indirectly through setDataProvider.
The item itself is not sent to the browser and shown in the dropdown. Instead, for each item ComboBox generates a string label that is shown in the UI and an internal id that is used on the server for mapping back to the original item instance when the user makes a selection.
The generated id is internal to ComboBox and has no external meaning. In particular, it's not based on any value in the item itself such as the item's primary key in the application's database.
The label is by default based on doing toString() for each item. You can customize how the label is created by assigning an item label generator callback that receives an item instance and returns the label string to use for that item.
If you for example have a combo box for selecting persons, then you could configure it in e.g. this way:
ComboBox<Person> personSelector = new ComboBox<>();
personSelector.setItems(allPersons);
personSelector.setItemLabelGenerator(person ->
person.getFirstName() + " " + person.getLastName());
If I understand you correctly, there is built-in feature in ComboBox for this, the method is called setItemLabelGenerator(..), which allows to define e.g. lambda expression that returns String which is used for ComboBox items instead of the property from underlying data object.
The linked Forum discussion you found is about similar thing in our previous generation of the framework, there has been some renaming of the API here.

Columns order in ListGrid Smartgwt

How can I programmatically change the order of columns in ListGrid? I have search for an appropriate method in javadoc but found nothing. Is it possible?
Check out setViewState method and this example that saves and restores grid preferences (including column order). So in short, you are interested in getting viewState string from ListGrid data and using it. Remember to redraw grid after setting new viewState.

How do I preserve Telerik MVC grid column order and sizes when paging?

I have a Telerik ASP.NET MVC grid that uses server data binding and has column resizing and reordering enabled. If I manually re-order or re-size the columns and then use the grid pager to jump to another page of the grid, the column sizes and order revert back to the default settings. What is the best way to preserve user changes to the column size and order when paging?
On the Telerik demos site I found an example that uses hidden form fields with AJAX data binding, but as far as I know that won't work for the server binding HTTP GETs. I started down the path of using cookies instead of hidden form fields, but it started getting messy and I was looking for feedback on alternative approaches.
You could pass the column widths down to the grid either as part of your model or with ViewBag (or ViewData if you're using MVC 2)
You can then set your column widths using:
.Width((int)ViewBag.col1Width);
- or -
.Width((int)model.col1Width);
You can then update the values using a callback via the OnColumnResize event (this is raised when a grid column is resized by the user)
If you're using session state, you could also store the values in session variables if they are to persist throughout the user's session.

Resources