Closed glebfox closed 12 months ago
I've tried implement suggestions for JmixMultiSelectComboBox
using CallbackDataProvider.FetchCallback
similar to io.jmix.ui.component.TagField
:
protected Stream<UserDetails> onFieldFetchCallback(Query<UserDetails, String> query) {
int offset = query.getOffset(); // ignore value
int limit = query.getLimit(); // ignore value
String enteredValue = query.getFilter().orElse(null);
return StringUtils.isNotBlank(enteredValue)
? (Stream<UserDetails>) userRepository.getByUsernameLike(enteredValue).stream()
: Stream.empty();
}
But there is a problem with value conversion in JmixMultiSelectComboBox#onValueChange()
. Loaded options are empty due to calling fetch with empty Query
. So value conversion produces empty values.
Needs some improvements:
searchStringFormat
should be named inputString
fetchPlan
element. Or maybe add also nested query
element as in data loaders?Jmix version: 2.1.999-SNAPSHOT Jmix Studio plugin version: 2.1.SNAPSHOT5666-232 IntelliJ version: IntelliJ IDEA 2023.2.3 (Ultimate Edition) verified
Consider implementing com.vaadin.flow.data.provider.CallbackDataProvider instead of separate component
Solution
The
setItemsFetchCallback
method is added for the following components:ComboBox
EntityComboBox
MultiselectComboBox
MultiselectComboBoxPicker
XML
All components support an optional
itemsQuery
element that enables defining a query for selecting suggested values.The
itemsQuery
element for theEntityComboBox
has the following attributes:class
(required) - a full qualified name of an entity class.fetchPlan
- an optional attribute that specifies the fetch plan to be used for loading the queried entity.escapeValueForLike
- enables searching for the values that contain special symbols:%
,\
, etc. The default value isfalse
.searchStringFormat
- a string that contains a variable to be substituted with actual value byio.jmix.flowui.sys.substitutor.StringSubstitutor
. The default implementation delegates its work toorg.apache.commons.text.StringSubstitutor
.The
itemsQuery
element for theEntityComboBox
has the following nested elements:query
- an element that contains a JPQL queryfetchPlan
- an optional descriptor of inline fetch planThe
itemsQuery
element for theComboBox
has the following attributes:escapeValueForLike
- enables searching for the values that contain special symbols:%
,\
, etc. The default value isfalse
.searchStringFormat
- a string that contains a variable to be substituted with actual value byio.jmix.flowui.sys.substitutor.StringSubstitutor
. The default implementation delegates its work toorg.apache.commons.text.StringSubstitutor
.The
itemsQuery
element for theEntityComboBox
has the following nested element:query
- an element that contains a JPQL queryNote: there is no
entityClass
andfetchPlan
becauseComboBox
assumes that scalar values will be loaded. In case if entities useEntityComboBox
.The
itemsQuery
element for theMultiSelectComboBox
andMultiSelectComboBoxPicker
has the following attributes:class
(optional) - a full qualified name of an entity class.fetchPlan
- an optional attribute that specifies the fetch plan to be used for loading the queried entity.escapeValueForLike
- enables searching for the values that contain special symbols:%
,\
, etc. The default value isfalse
.searchStringFormat
- a string that contains a variable to be substituted with actual value byio.jmix.flowui.sys.substitutor.StringSubstitutor
. The default implementation delegates its work toorg.apache.commons.text.StringSubstitutor
.The
itemsQuery
element for theMultiSelectComboBox
andMultiSelectComboBoxPicker
has the following nested elements:query
- an element that contains a JPQL queryfetchPlan
- an optional descriptor of inline fetch planNote: Because both
MultiSelectComboBox
andMultiSelectComboBoxPicker
work with entities and scalar valuesitemsQuery
hasclass
attribute but its optional.View Controller
If
itemsQuery
is not defined, you should programmatically set the list of options usingsetItemsFetchCallback
.Note: Because the real work is delegated to
com.vaadin.flow.data.provider.HasLazyDataView#setItems(com.vaadin.flow.data.provider.CallbackDataProvider.FetchCallback<T,F>)
, theQueryTrace
instance is passed to thefetch
callback. As a result, there are several limitations:query.getOffset()
andquery.getLimit()
methods must be called, otherwise an exception is thrown.limit
value, otherwise an exception is thrown.