Something is messed up with ui binder and browser session

hi…
given the following class:

I’m getting a strange behavior when i click on the add button, which the fields in the dialog are already populated with values even though i would expect them to be empty.
BUT, if I open chrome in incognito mode, clicking add does bring up a dialog with empty fields, why?

public class UserListView extends VerticalLayout {



    private final Grid<UserData> userDataGrid = new Grid<>(UserData.class, false);
    private static final Logger logger = LoggerFactory.getLogger(UserListView.class);;
    
    public UserListView() {
        userDataGrid.addColumn(UserData::getUserName).setHeader("User Name").setAutoWidth(true);
        userDataGrid.addColumn(UserData::getUserType).setHeader("User Type").setAutoWidth(true);
        userDataGrid.setSelectionMode(Grid.SelectionMode.SINGLE);
        final SingleSelect<Grid<UserData>, UserData> userSelect = userDataGrid.asSingleSelect();
        final HorizontalLayout buttons = getUserActions(userSelect);

        add(userDataGrid, buttons);

            final List<UserData> userData = userService.getUserData();
            userDataGrid.setItems(userData);

    }

    private HorizontalLayout getUserActions(SingleSelect<Grid<UserData>, UserData> userSelect) {
        final Button add = new Button("Add", (ComponentEventListener<ClickEvent<Button>>) event -> {
            final UserData userData1 = new UserData();
            createUserDialog(userData1);
        });
        final Button edit = new Button("Edit", (ComponentEventListener<ClickEvent<Button>>) event -> {
            createUserDialog(userSelect.getValue());
        });
        final Button delete = new Button("Delete", (ComponentEventListener<ClickEvent<Button>>) event -> {
            final ConfirmDialog dialog = new ConfirmDialog("Delete User", "Are you sure you want to permanently delete this user?", "Delete"
                 , new ComponentEventListener<ConfirmDialog.ConfirmEvent>() {
                @Override
                public void onComponentEvent(ConfirmDialog.ConfirmEvent event) {
                    logger.info("Delete user");
                }
            }, "Cancel", new ComponentEventListener<ConfirmDialog.CancelEvent>() {
                @Override
                public void onComponentEvent(ConfirmDialog.CancelEvent event) {
                    logger.info("Canceled Delete user");
                }
            });
            dialog.open();
        });
        final HorizontalLayout buttons = new HorizontalLayout(add, edit, delete);
        return buttons;
    }

    private void createUserDialog(UserData userData1) {
        final TextField userName = new TextField("User Name","");
        final PasswordField passwordField = new PasswordField("Password");
        final Binder<UserData> userDataBinder = new Binder<>();
        userDataBinder.forField(userName).bind(UserData::getUserName, UserData::setUserName);
        userDataBinder.forField(passwordField).bind(UserData::getPassword, UserData::setPassword);
        final Dialog userDataDialog = new Dialog("User Data");
        
        final Button ok = new Button("OK", (ComponentEventListener<ClickEvent<Button>>) event1 -> {

            try {
                userDataBinder.writeBean(userData1);
            } catch (ValidationException e) {
                throw new RuntimeException(e);
            }
            userDataDialog.close();
           
        });
        final Button cancel = new Button("Cancel", (ComponentEventListener<ClickEvent<Button>>) event -> userDataDialog.close());
        userDataDialog.getFooter().add(ok,cancel);
        final VerticalLayout verticalLayout = new VerticalLayout(userName, passwordField);
        verticalLayout.setPadding(false);
        verticalLayout.setSpacing(false);
        verticalLayout.setAlignItems(Alignment.STRETCH);
        userDataDialog.add(verticalLayout);
        userDataDialog.setModal(true);
        userDataBinder.readBean(userData1);
        userDataDialog.open();
    }

}

If you are talking about chrome pre-filling your username / password - the most obvious thing to be pre-filled; you are correct, chrome does that. Incognito mode won’t.

1 Like

OH lol it worked way too smoothly to even suspect that, is there a way to prevent auto-fill from doing that in that particular form? cause it doesn’t make sense when adding a NEW user. .

well i’ve placed autoComplete off, but it’s still pops up the form with default value as before.

You not gonna like that answer. Chrome is special :slightly_smiling_face:

thanks, you might wanna add some notes to vaadin’s javadocs about it…