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;

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);
}

};
add(clearLink);
}
@Override
protected void onSubmit() {

logger.info("OnSubmit");

}
}

Reply via email to