Skip to content

Commit

Permalink
Added support for LocalDateTime type & better support for basic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
mstahv committed Apr 2, 2024
1 parent 4633fa5 commit 0177f3a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,21 +265,12 @@ protected void bindField(HasValue field, String property, Class<?> propertyType,
if(configuration.getConverters().containsKey(property)) {
bindingBuilder = bindingBuilder.withConverter(configuration.getConverters().get(property));

} else if (Double.class.isAssignableFrom(propertyType) || double.class.isAssignableFrom(propertyType)) {
bindingBuilder = bindingBuilder.withConverter(new StringToDoubleConverter(null, "Must be a number"));

} else if (Long.class.isAssignableFrom(propertyType) || long.class.isAssignableFrom(propertyType)) {
bindingBuilder = bindingBuilder.withConverter(new StringToLongConverter(null, "Must be a number"));

} else if (BigDecimal.class.isAssignableFrom(propertyType)) {
bindingBuilder = bindingBuilder.withConverter(new StringToBigDecimalConverter(null, "Must be a number"));

} else if (BigInteger.class.isAssignableFrom(propertyType)) {
bindingBuilder = bindingBuilder.withConverter(new StringToBigIntegerConverter(null, "Must be a number"));

} else if (Integer.class.isAssignableFrom(propertyType) || int.class.isAssignableFrom(propertyType)) {
bindingBuilder = bindingBuilder.withConverter(new StringToIntegerConverter(null, "Must be a number"));

} else if (Byte.class.isAssignableFrom(propertyType) || byte.class.isAssignableFrom(propertyType)) {
bindingBuilder = bindingBuilder.withConverter(new StringToByteConverter(null, "Must be a number"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
import com.vaadin.flow.component.checkbox.Checkbox;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.datepicker.DatePicker;
import com.vaadin.flow.component.datetimepicker.DateTimePicker;
import com.vaadin.flow.component.textfield.BigDecimalField;
import com.vaadin.flow.component.textfield.IntegerField;
import com.vaadin.flow.component.textfield.NumberField;
import com.vaadin.flow.component.textfield.TextField;
import org.vaadin.crudui.form.FieldProvider;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;

Expand All @@ -32,6 +38,22 @@ public HasValueAndElement buildField(Object t) {
return new DatePicker();
}

if (LocalDateTime.class.isAssignableFrom(type)) {
return new DateTimePicker();
}

if (Double.class.isAssignableFrom(type) || type == double.class) {
return new NumberField();
}

if (Integer.class.isAssignableFrom(type) || type == int.class) {
return new IntegerField();
}

if (BigDecimal.class.isAssignableFrom(type)) {
return new BigDecimalField();
}

if (Enum.class.isAssignableFrom(type)) {
Object[] values = type.getEnumConstants();
ComboBox comboBox = new ComboBox<>();
Expand Down

0 comments on commit 0177f3a

Please sign in to comment.