jmix-projects / jmix-ui

DEPRECATED. Use https://github.com/jmix-framework/jmix
https://www.jmix.io
3 stars 7 forks source link

Exception if an image with click listener is used as a Table's generated column value #617

Closed glebfox closed 3 years ago

glebfox commented 3 years ago

Case:

  1. Add a generated column with an Image to a Table
  2. Add ClickListener to the Image
  3. Run the App > Open the screen > double click on the image
@UiController("User.browse")
@UiDescriptor("user-browse.xml")
@LookupComponent("usersTable")
@Route("users")
public class UserBrowse extends StandardLookup<User> {
    @Autowired
    private GroupTable<User> usersTable;
    @Autowired
    private UiComponents uiComponents;
    @Autowired
    private Notifications notifications;

    @Subscribe
    public void onInit(InitEvent event) {
        usersTable.addGeneratedColumn("imgSend", entity -> {
            Image<?> image = uiComponents.create(Image.class);
            image.setSource(ThemeResource.class)
                    .setPath("branding/app-icon-login.svg");

            image.setHeight("16px");
            image.setScaleMode(Image.ScaleMode.CONTAIN);

            image.addClickListener(clickEvent -> {
                notifications.create()
                        .withCaption("Image clicked")
                        .withDescription("isDoubleClick: " + clickEvent.isDoubleClick())
                        .withType(NotificationType.TRAY)
                        .show();
            });

            return image;
        });
    }
}

AR:

IllegalArgumentException: entity or id is null

Hint: alter com.vaadin.v7.ui.Table#handleClickEvent so that it ignores clickEvents with no clickedKey.