Validation error message are not shown

Hi,

using Binder on a form when you write the bean with writeBean(bean) all the fields with errors have to display their error message, right?

I am in a case where the error message is not shown on some fields even if validation fails. I know it’s a bit vague without an example, but if someone can suggest where to look at first.

Thanks for the help.

I am using v14

Java Bean Validation?

Support for that is only half baked, so the framework don’t for example understand any class level validators.

Only those it can map to a specific UI field…

Hi, not my case. I found the problem is a bit weird, I am investigating, it happens on ComboBox if I have a test validator like withValidator(v -> false, "foobar"). so it nevers validate when the error message appear once I change che value of the combobox, and I click the foobarmessage it disappear and it’s not shown again

But writeBean should raise an exception, or?

writeBean uses validate (false) on the fields and therefore does not show the errors on the fields.

the validation process works, the bean is not validated and as you said writeBean raise an exception, but the error message is not shown on fields after I click on the message on a combobox

in most of the cases writeBeans show the error message, I am a bit confused, it’s now the intended behaviour?

Not sure tbh, I always use setBean :grimacing:

I tried and the problem is still the same, I think I have to create a test case. The combox are the problem. if you click the error message above them it disappear

I’m personally not sure what you are exactly doing with your combo box so that it is interfering with the validation :sweat_smile:

imho it’s a bug, if I use a custome label with withStatusLabel(...) the label doesn’t disappear when I click on it

Try to create a reduced example and let’s see!

I created this test case, it’s just a view of my application but I hope it’s ok as test. You select b from the combobox, then the “not valid” label appears, you click on the “not valid” label and it disappear, then you submit and it doesn’te appear

@PageTitle("test page2")
@Route(value="test2", layout=MainLayout.class)
@Slf4j
public final class TestView2 extends Div {

    @Data
    public static class Product {

        private Item item;
    }

    @Value
    public static class Item {
        String value;
    }

    private final Binder<Product> binder = new Binder<>();
    private final ComboBox<Item> itemCbx = new ComboBox<>();
    private final List<Item> items = List.of(new Item("a"), new Item("b"), new Item("c"));
    private final Button submitBtn = new Button("Submit");

    public TestView2() {

        VerticalLayout layout = new VerticalLayout();
        itemCbx.setItemLabelGenerator(Item::getValue);
        itemCbx.setItems(items);
        layout.add(itemCbx);

        submitBtn.addClickListener(this::submit);
        layout.add(submitBtn);
        
        add(layout);

        setWidthFull();
    }

    @Override
    public void onAttach(AttachEvent attachEvent) {

        itemCbx.setValue(items.get(0));

        binder.forField(itemCbx).
                asRequired("required").
                withValidator(i -> i.getValue().equals("a"), "not valid").
                bind(Product::getItem, Product::setItem);

        Product product = new Product();
        product.setItem(items.get(0));

        binder.readBean(product);
    }

    private void submit(ClickEvent<Button> e) {

        Product p = new Product();

        try {
            binder.writeBean(p);
        } catch (ValidationException ex) {
            log.error("problem", ex);
        }
    }
}

I attach a video of the behaviour too

when I hit submit vallidation error is thrown, this is ok

A- for the test case. Took me a minute to get rid of lombok annotations :wink: