question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Binder writeBeanIfValid writes invalid values to the bean

See original GitHub issue

See 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:open
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
Legiothcommented, Mar 10, 2020

This is a missing feature that should be ported from Vaadin 8: https://github.com/vaadin/flow/issues/6803

1reaction
plekucommented, Apr 1, 2021

I’ve asked to transfer the issue or make that repository public but until something happens

image

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found