Use of beanvalidation

I’m trying to implement beanvalidation at the UI level, in my specific entity the following


@NotNull(message = "{msg://com.iis.izzy.entity.common/identification.validationMsg}")
@Column(name = "IDENTIFICATION", nullable = false, unique = true, length = 6)
private String identification;

identificationField.getValidators().stream()
		.filter(validator -> validator instanceof BeanValidator).forEach(validator -> {
	((BeanValidator) validator).setValidationGroups(new Class[] {UiComponentChecks.class});
});

Now I need that message to be seen in the user interface, but I can not get it to show it, I followed the guide , but I still can not make it work.

What can I be omitting?

Hi,

If you use @NotNull constraint then UI component will become required and requiredMessage will be set using message from @NotNull if it is connected to a datasource with that property.

Why do you call setValidationGroups for BeanValidator? It passes {Default, UiComponentChecks} groups to Validator by default.

Could you clarify what do you want to achieve?

What I want is that if the user does not enter data in the fields marked as required in the UI, then he will be shown the message that these fields are missing to fill when he tries to save the information, even though he has the fields marked as Required, try to save and I get an exception error by trying to save records in the table without information being required fields.

Selección_001

Selección_002

If you use standard Editor then standard validation will be triggered automatically on editor close / commit. Do you use standalone editor or Master-Details template?

Could you attach a small demo that illustrates the issue?

Attached classes and views.

department.zip (9.1K)

Hi, thank your for this topic. We have found an issue in our Entity Browser/Editor template - this template does not generate validateAll call in save method. Now you can use a workaround, just add condition to your save method:


public void save() {
    if (validateAll()) {
        getDsContext().commit();

        Client editedItem = clientDs.getItem();
        if (creating) {
            clientsDs.includeItem(editedItem);
        } else {
            clientsDs.updateItem(editedItem);
        }
        clientsTable.setSelected(editedItem);

        disableEditControls();
    }
}

It will automatically perform all necessary validations and show validation errors in a Tray notification.

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/STUDIO-3380