Re: Clear input form values
Please create a quickstart and share it somewhere. Martin Grigorov Wicket Training and Consulting https://twitter.com/mtgrigorov On Sat, Oct 15, 2016 at 1:02 PM, ganea iulia wrote: > Hello, > > Do you have any new advise on this? > Thank you. > > On Fri, Oct 14, 2016 at 11:02 AM, ganea iulia > wrote: > > > Hello, > > But that was it. > > The code contained both the > > txtName.setOutputMarkupId(true) and the > > txtName.add(new AjaxFormComponentUpdatingBehavior("change") { ... > > > > > > I will paste all the code again (I have now only added the > > txtLink.setOutputMarkupId(true) and the TestForm.setOutputMarkupId( > true); > > ) > > Thank you > > > > ==HTML code== > > > > > width="100%"> > > > > Name: > > > > > > > > > > > > > > > name="btnClear" /> > > > > > > > > > > > > ==JAVA CODE== > > > > public class TestPage extends WebPage { > > > > private static final long serialVersionUID = 311508940740808005L; > > private static final Logger logger = LogManager.getLogger(TestPage. > class); > > > > public TestPage(IModel model) { > > super(model); > > > > TestForm tst = new TestForm("testForm", model); > > tst.setOutputMarkupId(true); > > add(tst); > > > > } > > > > class TestForm extends Form { > > /** > > * > > */ > > private static final long serialVersionUID = 1L; > > > > public TestForm(String id, IModel model) { > > super(id, model); > > > > TextField txtName = new TextField("txtName", new > > PropertyModel(getModelObject(), "name")); > > add(txtName); > > txtName.setOutputMarkupId(true); > > txtName.add(new AjaxFormComponentUpdatingBehavior("change") { > > private static final long serialVersionUID = 1654345477970524731L; > > > > @Override > > protected void onUpdate(AjaxRequestTarget target) { > > target.add(txtName); > > } > > > > }); > > > > AjaxLink clearLink = new AjaxLink("clearLink", > model) > > { > > /** > > * > > */ > > private static final long serialVersionUID = 1L; > > > > @Override > > public void onClick(AjaxRequestTarget target) { > > model.setObject(new TestBean()); > > TestForm.this.clearInput(); > > target.add(TestForm.this); > > > > } > > > > }; > > clearLink.setOutputMarkupId(true); > > add(clearLink); > > } > > > > @Override > > protected void onSubmit() { > > > > logger.info("OnSubmit"); > > > > } > > } > > > > > > } > > > > > > ==THE BEAN== > > > > import java.io.Serializable; > > > > public class TestBean implements Serializable{ > > > > /** > > * > > */ > > private static final long serialVersionUID = 1L; > > private String name; > > private String code; > > private Integer id; > > public String getName() { > > return name; > > } > > public void setName(String name) { > > this.name = name; > > } > > public String getCode() { > > return code; > > } > > public void setCode(String code) { > > this.code = code; > > } > > public Integer getId() { > > return id; > > } > > public void setId(Integer id) { > > this.id = id; > > } > > > > } > > > > > > > > On Fri, Oct 14, 2016 at 10:43 AM, Martin Grigorov > > wrote: > > > >> We can only advise on the code that you give us. > >> Your real code may not work for many other reasons but since you give us > >> some incomplete copies of it we have no idea what is wrong. > >> > >> Martin Grigorov > >> Wicket Training and Consulting > >> https://twitter.com/mtgrigorov > >> > >> On Fri, Oct 14, 2016 at 9:33 AM, ganea iulia > >> wrote: > >> > >> > Hello, > >> > > >> > The txtName field has the .setOutputMarkupId(true). > >> > I have also added it to the form. > >> > But it doesn't work howevere. > >> > I have event tested adding it to the txtLink, but still no change. > >> > > >> > However, the issue appears to come from the > >> > txtName.add(new AjaxFormComponentUpdatingBehavior("change") {...} > >> > > >> > If I comment out this part, the clear is done. > >> > But I need to have this behaviour kept. > >> > > >> > Could you please advise? > >> > Thank you > >> > > >> > > >> > On Fri, Oct 14, 2016 at 10:10 AM, Martin Grigorov < > mgrigo...@apache.org > >> > > >> > wrote: > >> > > >> > > On Fri, Oct 14, 2016 at 9:01 AM, ganea iulia < > superbiss...@gmail.com> > >> > > wrote: > >> > > > >> > > > Hello, > >> > > > > >> > > > I'm using Wicket 7. > >> > > > > >> > > > Please help me with the following. > >> > > > > >> > > > I have a test form, with only one input text field on it. > >> > > > When pressing on a link, I need to have the values in the form > >> cleared > >> > > out. > >> > > > > >> > > > This is the html and java code, but I could not make it work, the > >> input > >> > > > field just won't clear. > >> > > > > >> > > > > >> > > > border="0" > >> > > > width="100%"> > >> > > > > >> > > > Name: > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > >> > > > name="btnClear" /> > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > > >> > > > public TestPage(IModel model, final ReturnObjectPage > >> > > returnPage) > >> > > > { > >> > > > super(model); > >> > >
Re: Clear input form values
Hello, Do you have any new advise on this? Thank you. On Fri, Oct 14, 2016 at 11:02 AM, ganea iulia wrote: > Hello, > But that was it. > The code contained both the > txtName.setOutputMarkupId(true) and the > txtName.add(new AjaxFormComponentUpdatingBehavior("change") { ... > > > I will paste all the code again (I have now only added the > txtLink.setOutputMarkupId(true) and the TestForm.setOutputMarkupId(true); > ) > Thank you > > ==HTML code== > > width="100%"> > > Name: > > > > > > > name="btnClear" /> > > > > > > ==JAVA CODE== > > public class TestPage extends WebPage { > > private static final long serialVersionUID = 311508940740808005L; > private static final Logger logger = LogManager.getLogger(TestPage.class); > > public TestPage(IModel model) { > super(model); > > TestForm tst = new TestForm("testForm", model); > tst.setOutputMarkupId(true); > add(tst); > > } > > class TestForm extends Form { > /** > * > */ > private static final long serialVersionUID = 1L; > > public TestForm(String id, IModel model) { > super(id, model); > > TextField txtName = new TextField("txtName", new > PropertyModel(getModelObject(), "name")); > add(txtName); > txtName.setOutputMarkupId(true); > txtName.add(new AjaxFormComponentUpdatingBehavior("change") { > private static final long serialVersionUID = 1654345477970524731L; > > @Override > protected void onUpdate(AjaxRequestTarget target) { > target.add(txtName); > } > > }); > > AjaxLink clearLink = new AjaxLink("clearLink", model) > { > /** > * > */ > private static final long serialVersionUID = 1L; > > @Override > public void onClick(AjaxRequestTarget target) { > model.setObject(new TestBean()); > TestForm.this.clearInput(); > target.add(TestForm.this); > > } > > }; > clearLink.setOutputMarkupId(true); > add(clearLink); > } > > @Override > protected void onSubmit() { > > logger.info("OnSubmit"); > > } > } > > > } > > > ==THE BEAN== > > import java.io.Serializable; > > public class TestBean implements Serializable{ > > /** > * > */ > private static final long serialVersionUID = 1L; > private String name; > private String code; > private Integer id; > public String getName() { > return name; > } > public void setName(String name) { > this.name = name; > } > public String getCode() { > return code; > } > public void setCode(String code) { > this.code = code; > } > public Integer getId() { > return id; > } > public void setId(Integer id) { > this.id = id; > } > > } > > > > On Fri, Oct 14, 2016 at 10:43 AM, Martin Grigorov > wrote: > >> We can only advise on the code that you give us. >> Your real code may not work for many other reasons but since you give us >> some incomplete copies of it we have no idea what is wrong. >> >> Martin Grigorov >> Wicket Training and Consulting >> https://twitter.com/mtgrigorov >> >> On Fri, Oct 14, 2016 at 9:33 AM, ganea iulia >> wrote: >> >> > Hello, >> > >> > The txtName field has the .setOutputMarkupId(true). >> > I have also added it to the form. >> > But it doesn't work howevere. >> > I have event tested adding it to the txtLink, but still no change. >> > >> > However, the issue appears to come from the >> > txtName.add(new AjaxFormComponentUpdatingBehavior("change") {...} >> > >> > If I comment out this part, the clear is done. >> > But I need to have this behaviour kept. >> > >> > Could you please advise? >> > Thank you >> > >> > >> > On Fri, Oct 14, 2016 at 10:10 AM, Martin Grigorov > > >> > wrote: >> > >> > > On Fri, Oct 14, 2016 at 9:01 AM, ganea iulia >> > > wrote: >> > > >> > > > Hello, >> > > > >> > > > I'm using Wicket 7. >> > > > >> > > > Please help me with the following. >> > > > >> > > > I have a test form, with only one input text field on it. >> > > > When pressing on a link, I need to have the values in the form >> cleared >> > > out. >> > > > >> > > > This is the html and java code, but I could not make it work, the >> input >> > > > field just won't clear. >> > > > >> > > > >> > > > > > > > width="100%"> >> > > > >> > > > Name: >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > > > > > name="btnClear" /> >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > public TestPage(IModel model, final ReturnObjectPage >> > > returnPage) >> > > > { >> > > > super(model); >> > > > this.returnPage = returnPage; >> > > > >> > > >> > > Don't keep references to other pages. >> > > Use PageReference instead. >> > > >> > > >> > > > >> > > > add(new TestForm("testForm", model)); >> > > > >> > > > } >> > > > >> > > > class TestForm extends Form { >> > > > /** >> > > > * >> > > > */ >> > > > private static final long serialVersionUID = 1L; >> > > > >> > > > >> > > > public TestForm(String id, IModel model) { >> > > > super(id, model); >> > > > TextField txtName = new TextField("txtName", new >> > > > PropertyModel(getModelObject(), "name")); >> > > > add(txtName); >> > > > txtName.add(new AjaxFormComponentUpdatingBehavior("change") { >> > > > private static final long serialVers
Re: Clear input form values
Hello, But that was it. The code contained both the txtName.setOutputMarkupId(true) and the txtName.add(new AjaxFormComponentUpdatingBehavior("change") { ... I will paste all the code again (I have now only added the txtLink.setOutputMarkupId(true) and the TestForm.setOutputMarkupId(true); ) Thank you ==HTML code== Name: ==JAVA CODE== public class TestPage extends WebPage { private static final long serialVersionUID = 311508940740808005L; private static final Logger logger = LogManager.getLogger(TestPage.class); public TestPage(IModel model) { super(model); TestForm tst = new TestForm("testForm", model); tst.setOutputMarkupId(true); add(tst); } class TestForm extends Form { /** * */ private static final long serialVersionUID = 1L; public TestForm(String id, IModel model) { super(id, model); TextField txtName = new TextField("txtName", new PropertyModel(getModelObject(), "name")); add(txtName); txtName.setOutputMarkupId(true); txtName.add(new AjaxFormComponentUpdatingBehavior("change") { private static final long serialVersionUID = 1654345477970524731L; @Override protected void onUpdate(AjaxRequestTarget target) { target.add(txtName); } }); AjaxLink clearLink = new AjaxLink("clearLink", model) { /** * */ private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { model.setObject(new TestBean()); TestForm.this.clearInput(); target.add(TestForm.this); } }; clearLink.setOutputMarkupId(true); add(clearLink); } @Override protected void onSubmit() { logger.info("OnSubmit"); } } } ==THE BEAN== import java.io.Serializable; public class TestBean implements Serializable{ /** * */ private static final long serialVersionUID = 1L; private String name; private String code; private Integer id; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } } On Fri, Oct 14, 2016 at 10:43 AM, Martin Grigorov wrote: > We can only advise on the code that you give us. > Your real code may not work for many other reasons but since you give us > some incomplete copies of it we have no idea what is wrong. > > Martin Grigorov > Wicket Training and Consulting > https://twitter.com/mtgrigorov > > On Fri, Oct 14, 2016 at 9:33 AM, ganea iulia > wrote: > > > Hello, > > > > The txtName field has the .setOutputMarkupId(true). > > I have also added it to the form. > > But it doesn't work howevere. > > I have event tested adding it to the txtLink, but still no change. > > > > However, the issue appears to come from the > > txtName.add(new AjaxFormComponentUpdatingBehavior("change") {...} > > > > If I comment out this part, the clear is done. > > But I need to have this behaviour kept. > > > > Could you please advise? > > Thank you > > > > > > On Fri, Oct 14, 2016 at 10:10 AM, Martin Grigorov > > wrote: > > > > > On Fri, Oct 14, 2016 at 9:01 AM, ganea iulia > > > wrote: > > > > > > > Hello, > > > > > > > > I'm using Wicket 7. > > > > > > > > Please help me with the following. > > > > > > > > I have a test form, with only one input text field on it. > > > > When pressing on a link, I need to have the values in the form > cleared > > > out. > > > > > > > > This is the html and java code, but I could not make it work, the > input > > > > field just won't clear. > > > > > > > > > > > > > > > width="100%"> > > > > > > > > Name: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > name="btnClear" /> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > public TestPage(IModel model, final ReturnObjectPage > > > returnPage) > > > > { > > > > super(model); > > > > this.returnPage = returnPage; > > > > > > > > > > Don't keep references to other pages. > > > Use PageReference instead. > > > > > > > > > > > > > > add(new TestForm("testForm", model)); > > > > > > > > } > > > > > > > > class TestForm extends Form { > > > > /** > > > > * > > > > */ > > > > private static final long serialVersionUID = 1L; > > > > > > > > > > > > public TestForm(String id, IModel model) { > > > > super(id, model); > > > > TextField txtName = new TextField("txtName", new > > > > PropertyModel(getModelObject(), "name")); > > > > add(txtName); > > > > txtName.add(new AjaxFormComponentUpdatingBehavior("change") { > > > > private static final long serialVersionUID = 1654345477970524731L; > > > > > > > > @Override > > > > protected void onUpdate(AjaxRequestTarget target) { > > > > target.add(txtName); > > > > } > > > > > > > > }); > > > > txtName.setOutputMarkupId(true); > > > > AjaxLink clearLink = new AjaxLink("clearLink", > > > model) > > > > { > > > > /** > > > > * > > > > */ > > > > private static final long serialVersionUID = 1L; > > > > > > > > @Override > > > > public void onClick(AjaxRequestTarget target) { > > > > model.setObject(
Re: Clear input form values
We can only advise on the code that you give us. Your real code may not work for many other reasons but since you give us some incomplete copies of it we have no idea what is wrong. Martin Grigorov Wicket Training and Consulting https://twitter.com/mtgrigorov On Fri, Oct 14, 2016 at 9:33 AM, ganea iulia wrote: > Hello, > > The txtName field has the .setOutputMarkupId(true). > I have also added it to the form. > But it doesn't work howevere. > I have event tested adding it to the txtLink, but still no change. > > However, the issue appears to come from the > txtName.add(new AjaxFormComponentUpdatingBehavior("change") {...} > > If I comment out this part, the clear is done. > But I need to have this behaviour kept. > > Could you please advise? > Thank you > > > On Fri, Oct 14, 2016 at 10:10 AM, Martin Grigorov > wrote: > > > On Fri, Oct 14, 2016 at 9:01 AM, ganea iulia > > wrote: > > > > > Hello, > > > > > > I'm using Wicket 7. > > > > > > Please help me with the following. > > > > > > I have a test form, with only one input text field on it. > > > When pressing on a link, I need to have the values in the form cleared > > out. > > > > > > This is the html and java code, but I could not make it work, the input > > > field just won't clear. > > > > > > > > > > > width="100%"> > > > > > > Name: > > > > > > > > > > > > > > > > > > > > > > > name="btnClear" /> > > > > > > > > > > > > > > > > > > > > > > > > public TestPage(IModel model, final ReturnObjectPage > > returnPage) > > > { > > > super(model); > > > this.returnPage = returnPage; > > > > > > > Don't keep references to other pages. > > Use PageReference instead. > > > > > > > > > > add(new TestForm("testForm", model)); > > > > > > } > > > > > > class TestForm extends Form { > > > /** > > > * > > > */ > > > private static final long serialVersionUID = 1L; > > > > > > > > > public TestForm(String id, IModel model) { > > > super(id, model); > > > TextField txtName = new TextField("txtName", new > > > PropertyModel(getModelObject(), "name")); > > > add(txtName); > > > txtName.add(new AjaxFormComponentUpdatingBehavior("change") { > > > private static final long serialVersionUID = 1654345477970524731L; > > > > > > @Override > > > protected void onUpdate(AjaxRequestTarget target) { > > > target.add(txtName); > > > } > > > > > > }); > > > txtName.setOutputMarkupId(true); > > > AjaxLink clearLink = new AjaxLink("clearLink", > > model) > > > { > > > /** > > > * > > > */ > > > private static final long serialVersionUID = 1L; > > > > > > @Override > > > public void onClick(AjaxRequestTarget target) { > > > model.setObject(new TestBean()); > > > TestForm.this.clearInput(); > > > target.add(TestForm.this); > > > target.add(txtName); > > > > > > > 1. There is no need to add 'txtName' to the target because its parent > > (TestForm) is added > > 2. Neither of them have .setOutputMarkupId(true), so Wicket won't be able > > to update them in the DOM. It should even complain about this. > > > > > > > } > > > > > > }; > > > add(clearLink); > > > } > > > @Override > > > protected void onSubmit() { > > > > > > logger.info("OnSubmit"); > > > > > > } > > > } > > > > > >
Re: Clear input form values
Hello, The txtName field has the .setOutputMarkupId(true). I have also added it to the form. But it doesn't work howevere. I have event tested adding it to the txtLink, but still no change. However, the issue appears to come from the txtName.add(new AjaxFormComponentUpdatingBehavior("change") {...} If I comment out this part, the clear is done. But I need to have this behaviour kept. Could you please advise? Thank you On Fri, Oct 14, 2016 at 10:10 AM, Martin Grigorov wrote: > On Fri, Oct 14, 2016 at 9:01 AM, ganea iulia > wrote: > > > Hello, > > > > I'm using Wicket 7. > > > > Please help me with the following. > > > > I have a test form, with only one input text field on it. > > When pressing on a link, I need to have the values in the form cleared > out. > > > > This is the html and java code, but I could not make it work, the input > > field just won't clear. > > > > > > > width="100%"> > > > > Name: > > > > > > > > > > > > > > > name="btnClear" /> > > > > > > > > > > > > > > > > public TestPage(IModel model, final ReturnObjectPage > returnPage) > > { > > super(model); > > this.returnPage = returnPage; > > > > Don't keep references to other pages. > Use PageReference instead. > > > > > > add(new TestForm("testForm", model)); > > > > } > > > > class TestForm extends Form { > > /** > > * > > */ > > private static final long serialVersionUID = 1L; > > > > > > public TestForm(String id, IModel model) { > > super(id, model); > > TextField txtName = new TextField("txtName", new > > PropertyModel(getModelObject(), "name")); > > add(txtName); > > txtName.add(new AjaxFormComponentUpdatingBehavior("change") { > > private static final long serialVersionUID = 1654345477970524731L; > > > > @Override > > protected void onUpdate(AjaxRequestTarget target) { > > target.add(txtName); > > } > > > > }); > > txtName.setOutputMarkupId(true); > > AjaxLink clearLink = new AjaxLink("clearLink", > model) > > { > > /** > > * > > */ > > private static final long serialVersionUID = 1L; > > > > @Override > > public void onClick(AjaxRequestTarget target) { > > model.setObject(new TestBean()); > > TestForm.this.clearInput(); > > target.add(TestForm.this); > > target.add(txtName); > > > > 1. There is no need to add 'txtName' to the target because its parent > (TestForm) is added > 2. Neither of them have .setOutputMarkupId(true), so Wicket won't be able > to update them in the DOM. It should even complain about this. > > > > } > > > > }; > > add(clearLink); > > } > > @Override > > protected void onSubmit() { > > > > logger.info("OnSubmit"); > > > > } > > } > > >
Re: Clear input form values
On Fri, Oct 14, 2016 at 9:01 AM, ganea iulia wrote: > Hello, > > I'm using Wicket 7. > > Please help me with the following. > > I have a test form, with only one input text field on it. > When pressing on a link, I need to have the values in the form cleared out. > > This is the html and java code, but I could not make it work, the input > field just won't clear. > > > width="100%"> > > Name: > > > > > > > name="btnClear" /> > > > > > > > > public TestPage(IModel model, final ReturnObjectPage returnPage) > { > super(model); > this.returnPage = returnPage; > Don't keep references to other pages. Use PageReference instead. > > add(new TestForm("testForm", model)); > > } > > class TestForm extends Form { > /** > * > */ > private static final long serialVersionUID = 1L; > > > public TestForm(String id, IModel model) { > super(id, model); > TextField txtName = new TextField("txtName", new > PropertyModel(getModelObject(), "name")); > add(txtName); > txtName.add(new AjaxFormComponentUpdatingBehavior("change") { > private static final long serialVersionUID = 1654345477970524731L; > > @Override > protected void onUpdate(AjaxRequestTarget target) { > target.add(txtName); > } > > }); > txtName.setOutputMarkupId(true); > AjaxLink clearLink = new AjaxLink("clearLink", model) > { > /** > * > */ > private static final long serialVersionUID = 1L; > > @Override > public void onClick(AjaxRequestTarget target) { > model.setObject(new TestBean()); > TestForm.this.clearInput(); > target.add(TestForm.this); > target.add(txtName); > 1. There is no need to add 'txtName' to the target because its parent (TestForm) is added 2. Neither of them have .setOutputMarkupId(true), so Wicket won't be able to update them in the DOM. It should even complain about this. > } > > }; > add(clearLink); > } > @Override > protected void onSubmit() { > > logger.info("OnSubmit"); > > } > } >