Binder writeBeanIfValid writes invalid values to the bean
See original GitHub issueSee example below, typing a number > 1000 or a number < -1000 in the field and pressing “validate” to store it, should NEVER store the invalid values in the bean.
The javadoc of setMax
also tells me:
Sets the maximum value of the field. Entering a value which is greater than code max invalidates the field.
Vaadin Version: 14.1.18 Browser: FF 74
@Route("bug-min-max")
public class IntegerFieldMinMax extends Composite<VerticalLayout> {
public IntegerFieldMinMax() {
IntegerField field = new IntegerField("Type here");
field.setMax(1000);
field.setMin(-1000);
field.addValueChangeListener(evt -> Notification.show("Changed value to: " + evt.getValue(), 3000, Position.TOP_START));
IntergerObject bean = new IntergerObject(1);
Binder<IntergerObject> binder = new Binder<>();
binder.forField(field).asRequired("Integer is required")
.bind(IntergerObject::getValue, IntergerObject::setValue);
binder.readBean(bean);
Button validate = new Button("Validate", evt -> {
if (binder.writeBeanIfValid(bean)) {
if(bean.getValue() > 1000) {
Notification.show("This is not valid - should NEVER been STORED. Field is configured with max = " + field.getMax()).addThemeVariants(NotificationVariant.LUMO_ERROR);
}else if(bean.getValue() < -1000) {
Notification.show("This is not valid - should NEVER been STORED. Field is configured with min = " + field.getMin()).addThemeVariants(NotificationVariant.LUMO_ERROR);
}
Notification.show("Stored valid value: " + bean.getValue(), 3000, Position.TOP_START);
}
});
getContent().add(field, validate);
}
@Data // Lombok Annotation
@AllArgsConstructor // Lombok Annotation
private static class IntergerObject {
private Integer value;
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
How to save data when vaadin binder has validation errors
binder.writeBeanIfValid(myBean) does only write the changes when no validation errors exist. And binder.writeBean(myBean) throws an exception, ...
Read more >Binder (vaadin-all 8.16.1 API)
Writes successfully converted and validated changes from the bound fields to the bean even if there are other fields with non-validated changes. Parameters: ......
Read more >com.vaadin.data.Binder.writeBeanIfValid java code examples
Writes changes from the bound fields to the given bean if all validators (binding and bean level) pass. If any field binding validator...
Read more >Example usage for com.vaadin.data Binder writeBeanIfValid
Writes changes from the bound fields to the given bean if all validators (binding and bean level) pass. Usage. From source file:org.jpos.qi.eeuser.UsersHelper.
Read more >DataBinder (Spring Framework 6.0.2 API)
Binder that allows for setting property values on a target object, ... Return the Validators to apply after data binding. void. initBeanPropertyAccess().
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a missing feature that should be ported from Vaadin 8: https://github.com/vaadin/flow/issues/6803
I’ve asked to transfer the issue or make that repository public but until something happens