alejandro-du / crudui

Automatically generate CRUD-like Vaadin views for any Java Bean
https://vaadin.com/directory#!addon/crud-ui-add-on
Apache License 2.0
86 stars 54 forks source link

Change label text of TextField #103

Closed Koboo closed 2 years ago

Koboo commented 2 years ago

Hello, I have tried to change the labels of some TextFields. I tried this by creating a FieldProvider for the specific fields of the entity. Unfortunately, the changed labels are not applied or are overwritten. Since the "required" attribute of the FieldProvider is set successfully, I am faced with an unexplainable puzzle.

My Entity:


public class Institution {

  private String institutionId;
  private String name;
  private String street;
  private String postalCode;
  private String city;

  // getter, setter, constructor stuff
}

My constructor of the View:

public InstitutionView() {
    GridCrud<Institution> grid = new GridCrud<>(Institution.class, service);

    grid.getGrid().removeAllColumns();
    grid.getGrid().addColumn(Institution::getName).setHeader("Name").setKey("name");
    grid.getGrid().addColumn(Institution::getStreet).setHeader("Adresse").setKey("street");
    grid.getGrid().addColumn(i -> i.getPostalCode() + " " + i.getCity()).setHeader("Ort").setKey("city");

    CrudFormFactory<Institution> factory = grid.getCrudFormFactory();

    factory.setDisabledProperties("institutionId");

    // Some other FieldProviders before,
    // But all are changed in the same way.
    factory.setFieldProvider("city", () -> {
      TextField field = new TextField();
      field.setLabel("Stadt");
      field.setRequired(true);
      return field;
    });

    add(grid);
    setSizeFull();
}

Is this an error of the addon or just incorrect use on my part?

Thanks for any help and a big respect to the developers of the addon!

alejandro-du commented 2 years ago

Hey, thanks for the feedback. Have you tried this?

formFactory.setFieldCreationListener("city", field -> ... your own logic here ...);
Koboo commented 2 years ago

Hey, no I have not tried this method yet. With this it seems to work now! Thanks for the answer!