@Override protected Collection<V> convertToModel(Set<V> componentRawValue) throws ConversionException { if (valueBinding != null) { Class<?> targetType = valueBinding.getSource().getType(); if (List.class.isAssignableFrom(targetType)) { return new ArrayList<>(componentRawValue != null ? componentRawValue : Collections.emptyList()); } else if (Set.class.isAssignableFrom(targetType)) { return new LinkedHashSet<>(componentRawValue != null ? componentRawValue : Collections.emptySet()); } } return new LinkedHashSet<>(componentRawValue != null ? componentRawValue : Collections.emptySet()); }
@Override protected Collection<V> convertToModel(Set<V> componentRawValue) throws ConversionException { Stream<V> items = optionsBinding == null ? Stream.empty() : optionsBinding.getSource().getOptions().filter(componentRawValue::contains); if (valueBinding != null) { Class<?> targetType = valueBinding.getSource().getType(); if (List.class.isAssignableFrom(targetType)) { return items.collect(Collectors.toList()); } else if (Set.class.isAssignableFrom(targetType)) { return items.collect(Collectors.toCollection(LinkedHashSet::new)); } } return items.collect(Collectors.toCollection(LinkedHashSet::new)); }
@SuppressWarnings("unchecked") @Override protected V convertToModel(Object componentRawValue) { if (isMultiSelect()) { Set collectionValue = (Set) componentRawValue; List<I> itemIds = getCurrentItems(); Stream<I> selectedItemsStream = itemIds.stream() .filter(collectionValue::contains); if (valueBinding != null) { Class<V> targetType = valueBinding.getSource().getType(); if (List.class.isAssignableFrom(targetType)) { return (V) selectedItemsStream.collect(Collectors.toList()); } if (Set.class.isAssignableFrom(targetType)) { return (V) selectedItemsStream.collect(Collectors.toCollection(LinkedHashSet::new)); } } return (V) selectedItemsStream.collect(Collectors.toCollection(LinkedHashSet::new)); } return super.convertToModel(componentRawValue); }
@SuppressWarnings("unchecked") @Override protected V convertToModel(Object componentRawValue) { if (isMultiSelect()) { Set collectionValue = (Set) componentRawValue; List<I> itemIds = getCurrentItems(); Stream<I> selectedItemsStream = itemIds.stream() .filter(collectionValue::contains); if (valueBinding != null) { Class<V> targetType = valueBinding.getSource().getType(); if (List.class.isAssignableFrom(targetType)) { return (V) selectedItemsStream.collect(Collectors.toList()); } if (Set.class.isAssignableFrom(targetType)) { return (V) selectedItemsStream.collect(Collectors.toCollection(LinkedHashSet::new)); } } return (V) selectedItemsStream.collect(Collectors.toCollection(LinkedHashSet::new)); } return super.convertToModel(componentRawValue); }