Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
2 doubts abour Grid editable
I create one grid and set editable, but now I have 2 doubts
1 - When I edit the String field, show 'null' , can I remove this word?
2 - Can I before init edit (when user 2x click in row) I verify if can I edit this row or not? something like one beforeEditListener
tks
1. If it says null, there is nothing to remove. Or do you mean by this question that you want in the view mode the null presentation value to be something else than "null", e.g. empty string?
2. There is no easy building blocks for this kind of conditional edit row. We have possibility to set columns not editable though. There is no cross field validation in row editor either, so that is tricky too. One workaround could be to use edit form in DetailsGenerator instead, since that gives more freedom. Ofcourse it would look different though.
1 - When I 2x click to enter em edit mode in grid, the field that are null (for sample on String property) show the word null in grid, so I need to select that word and change them
2 - Tks
1. I think the easiest way would be just to set the default values of the bean to empty string if that is possible instead of null.
My solution is a bit complicated and not really elegant, but resolves both your problems.
- custom bean field group:
public class MyBeanFieldGroup<P> extends BeanFieldGroup<P> {
private Map<Object, Validator> validators = new HashMap<>();
public MyBeanFieldGroup(Class<P> beanType, Map<Object, Validator> validators) {
super(beanType);
this.validators = validators;
}
@Override
public <T extends Field> T buildAndBind(String caption, Object propertyId, Class<T> fieldType) throws BindException {
T field = super(caption, propertyId, fieldType);
if (String.class.isAssignableFrom(fieldType)){
((AbstractTextField) field).setNullRepresentation("");
}
if (validators.containsKey(propertyId)) {
field.addValidator(validators.get(propertyId));
return field;
}
}
grid.setEditorFieldGroup(new MyBeanFieldGroup<>(dtoCls, validators));
validators.put(Skupina.FNAZEV, object -> {
Objec id = table.getEditedItemId();
if (notEditableId.equals(id)) {
throw new InvalidValueException("This object cannot be edited");
}
This causes that one of the colums is red, editor shows error message and it can't be saved.