Hi All,

I have a modal window with two fields and a confirm and cancel button.

The fields do not reset after submitting and the data from the previous use is 
still there.  I have tried several things.


1)      Refreshing the form on submit

2)      form.clearInput();  (also on submit)

3)      trying to set the input fields on construction of the form

Nothing is working.  Any advice is appreciated.  I'm posting my code below.

Thanks in advance for your help.


public abstract class NewMappingRulePanel extends Panel {

    private static final long   serialVersionUID = 1L;
    private static final Logger log              = 
LoggerFactory.getLogger(NewMappingRulePanel.class);
    private final List<DictModelBean> dictModelBeans;
    private       DictModelBean       dictModelBean;

    public NewMappingRulePanel(
        final String id, DictModelBean dictModelBean, final Class<? extends 
ConsolePage> backPage,
        List<DictModelBean> dictModelBeans
    ) {
        super(id, new Model<DictModelBean>());
        this.dictModelBean = dictModelBean;
        this.dictModelBeans = dictModelBeans;

        KnoaForm<Void> form = new KnoaForm<>("form");
        add(form);

        final KnoaFeedbackPanel feedbackPanel = new 
KnoaFeedbackPanel("feedbackPanel");
        form.add(feedbackPanel);

        form.<TextField<String>, String>addTextField(
            "starPattern", new PropertyModel<String>(dictModelBean, 
"starPattern"), 25, "dictionary.mapping.dictentry.starpattern.label"
        ).setRequired(true);

        form.add(new Label("dictLabel", 
ResourceKeyHelper.resourceValue("dictionary.mapping.dictentry.label")));
        final Select2ChoicePanel select2ChoicePanel = new 
Select2ChoicePanel("dictionaryEntry", new PropertyModel<String>(dictModelBean, 
"dictionaryEntry"),
            new DictTextChoiceProvider(dictModelBeans));

        form.add(select2ChoicePanel);
        AjaxFallbackButton button = new AjaxFallbackButton("confirm", new 
ResourceModel("confirm.label"), form) {
            private static final long serialVersionUID = 1L;
            ConfirmMessagePanel confirmMessagePanel;

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                NewMappingRulePanel.this.refreshPage(target);
                findParent(ModalWindow.class).close(target);
                KnoaPage.refreshComp(target,form);
            }
            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
                KnoaPage.refreshComp(target, feedbackPanel);
            }
        };
        //button.add(new AttributeModifier("onclick", 
"setDirty(true);"));//warn on exit
        button.setOutputMarkupId(true);
        form.add(button);

        button = new AjaxFallbackButton("cancel", new 
ResourceModel("cancel.label"), form) {
            private static final long serialVersionUID = 1L;

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
                if (target != null) {
                    (findParent(ModalWindow.class)).close(target);
                }
            }

            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
                onSubmit(target, form);
            }
        };
        button.setDefaultFormProcessing(false);
        form.add(button);
    }

    public DictModelBean getDictModelBean() {
        return dictModelBean;
    }

    public void setDictModelBean(DictModelBean dictModelBean) {
        this.dictModelBean = dictModelBean;
    }

    public abstract void refreshPage(AjaxRequestTarget target);
}




Reply via email to