Hi, ModalWindow is an Ajax component, so it makes the page stateful. That means Wicket will render the page with its current state. When submitting the Form the request parameters are used to feed the form components (the input fields). The submitted data is stored in FormComponent's model.
To reset the form you should null-ify both the FormComponents' input and model, i.e. Form.clearInput() + formComponent.setModelObject(null), or whatever is appropriate instead of null as default/initial value. Martin Grigorov Freelancer. Available for hire! Wicket Training and Consulting https://twitter.com/mtgrigorov On Tue, Jul 7, 2015 at 4:50 PM, Lois GreeneHernandez < [email protected]> wrote: > 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); > } > > > > >
