Hi all,

I found a workaround for this. Since Modal doesn't expose any API to remove
footer buttons, I used reflection to access the private buttons list and
clear it before adding the buttons for the new content.

public void setContent(ModalContent content)
{
    modalContainer.replace((Component) content);

    IModel<String> header = content.getHeader();
    if (header != null) {
        header(header);
    }

    clearButtons();


  addCloseButton(Model.of(getString("cancel")));

    Button button = content.getSaveButton(Modal.BUTTON_MARKUP_ID);
    if (button != null) {
        addButton(button);
    }
}

void clearButtons()
{
    try {
        Field field = Modal.class.getDeclaredField("buttons");
        field.setAccessible(true);

        List<Component> buttons = (List<Component>) field.get(this);

        buttons.clear();
    } catch (Exception ex) {
        log.error("Unable to clear buttons", ex);
    }
}

This works for my use case when reusing a single Modal instance with
different content panels. The only caveat is that it clears *all* footer
buttons, including any default Close/Cancel button, so those need to be
re-added after calling clearButtons().

Reply via email to