本文整理汇总了Java中com.vaadin.data.converter.LocalDateToDateConverter类的典型用法代码示例。如果您正苦于以下问题:Java LocalDateToDateConverter类的具体用法?Java LocalDateToDateConverter怎么用?Java LocalDateToDateConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LocalDateToDateConverter类属于com.vaadin.data.converter包,在下文中一共展示了LocalDateToDateConverter类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ConverterRegistry
import com.vaadin.data.converter.LocalDateToDateConverter; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private ConverterRegistry() {
registerConverter(String.class, int.class, new StringLengthConverterValidator("Must be a number", 1, null)
.chain(new StringToIntegerConverter("Must be a number")));
registerConverter(String.class, Integer.class,
new NullConverter<String>("").chain(new StringToIntegerConverter("Must be a number")));
registerConverter(String.class, long.class, new StringLengthConverterValidator("Must be a number", 1, null)
.chain(new StringToLongConverter("Must be a number")));
registerConverter(String.class, Long.class,
new NullConverter<String>("").chain(new StringToLongConverter("Must be a number")));
registerConverter(String.class, float.class, new StringLengthConverterValidator("Must be a number", 1, null)
.chain(new StringToFloatConverter("Must be a number")));
registerConverter(String.class, Float.class,
new NullConverter<String>("").chain(new StringToFloatConverter("Must be a number")));
registerConverter(String.class, double.class, new StringLengthConverterValidator("Must be a number", 1, null)
.chain(new StringToDoubleConverter("Must be a number")));
registerConverter(String.class, Double.class,
new NullConverter<String>("").chain(new StringToDoubleConverter("Must be a number")));
registerConverter(String.class, boolean.class,
new StringLengthConverterValidator("Must be true or false", 1, null)
.chain(new StringToBooleanConverter("Must be true or false")));
registerConverter(String.class, Boolean.class,
new NullConverter<String>("").chain(new StringToBooleanConverter("Must be true or false")));
registerConverter(String.class, BigInteger.class,
new NullConverter<String>("").chain(new StringToBigIntegerConverter("Must be a number")));
registerConverter(String.class, BigDecimal.class,
new NullConverter<String>("").chain(new StringToBigDecimalConverter("Must be a number")));
registerConverter(String.class, BigInteger.class,
new NullConverter<String>("").chain(new StringToBigIntegerConverter("Must be a number")));
Converter<String, Character> stringToCharConverter = Converter
.from(e -> e == null ? Result.ok(null) : Result.ok(e.charAt(0)), f -> f == null ? null : "" + f);
registerConverter(String.class, char.class,
new StringLengthConverterValidator("Must be 1 character", 1, 1).chain(stringToCharConverter));
registerConverter(String.class, Character.class, new NullConverter<String>("")
.chain(new StringLengthConverterValidator("Must be 1 character", 1, 1)).chain(stringToCharConverter));
registerConverter(LocalDateTime.class, Date.class, new LocalDateTimeToDateConverter(ZoneId.systemDefault()));
registerConverter(LocalDate.class, Date.class, new LocalDateToDateConverter());
registerConverter(Set.class, EnumSet.class, Converter.from(e -> e.isEmpty() ? Result.ok(null) : Result.ok(EnumSet.copyOf(e)), e -> e == null ? new HashSet<Object>() : e));
}
示例2: setup
import com.vaadin.data.converter.LocalDateToDateConverter; //导入依赖的package包/类
@BeforeClass
public static void setup() {
RequiredFieldConfigurator MIN = annotation -> annotation.annotationType().equals(Min.class)
&& ((Min) annotation).value() > 0;
binder.setRequiredConfigurator(MIN.chain(RequiredFieldConfigurator.DEFAULT));
Converter<String, Integer> c = Converter.from(e -> {
if (e.length() == 0) {
return Result.error("Must be a number");
}
try {
return Result.ok(Integer.parseInt(e));
} catch (NumberFormatException ex) {
return Result.error("Must be a number");
}
}, e -> Integer.toString(e));
binder.forField(form.airline).bind("flightId.airline");
binder.forField(form.flightNumber).withConverter(c).bind("flightId.flightNumber");
binder.forField(form.flightSuffix)
.withConverter(Converter.from(
e -> e.length() == 0 ? Result.ok(null)
: (e.length() == 1 ? Result.ok(e.charAt(0)) : Result.error("Must be 1 character")),
f -> f == null ? "" : "" + f))
.bind("flightId.flightSuffix");
binder.forField(form.date).withConverter(new LocalDateToDateConverter()).bind("flightId.date");
binder.forField(form.legType).bind("flightId.legType");
binder.forField(form.sbt).withConverter(new LocalDateTimeToDateConverter(ZoneId.systemDefault())).bind("sbt");
binder.forField(form.ebt).withConverter(new LocalDateTimeToDateConverter(ZoneId.systemDefault())).bind("ebt");
binder.forField(form.abt).withConverter(new LocalDateTimeToDateConverter(ZoneId.systemDefault())).bind("abt");
Binder.Binding<Flight, String> scheduledDependingBinding = binder.forField(form.gate).withNullRepresentation("")
.withValidator(e -> form.sbt.getValue() == null ? true : e != null, "Gate should be set when scheduled")
.bind(Flight::getGate, Flight::setGate);
form.sbt.addValueChangeListener(e -> scheduledDependingBinding.validate());
binder.bindInstanceFields(form);
binder.withValidator(e -> new FlightValidator().isValid(e, null), FlightValid.MESSAGE);
form.flightNumber.setRequiredIndicatorVisible(true);
}