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.
>
> <form wicket:id="testForm">
> <table class="contenidoform"  cellpadding=1 cellspacing=0 border="0"
> width="100%">
> <tr>
> <th>Name:</th>
> <th colspan="3">
> <input wicket:id="txtName" size="80"/>
> </th>
> </tr>
> <tr>
> <th>
> <span><a href="#" wicket:id="clearLink"><img src="images/img.gif"
> name="btnClear" /></a></span>
> </th>
> </tr>
> </table>
> </form>
>
>
>
> public TestPage(IModel<TestBean> 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<TestBean> {
> /**
> *
> */
> private static final long serialVersionUID = 1L;
>
>
> public TestForm(String id, IModel<TestBean> model) {
> super(id, model);
> TextField<String> txtName = new TextField<String>("txtName", new
> PropertyModel<String>(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<TestBean> clearLink = new AjaxLink<TestBean>("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");
>
> }
> }
>

Reply via email to