Hello,
Consider my code underneath and following actions:
- Page has a form with a REQUIRED textfield and a button that updates that
textfield through ajax
- When clicking button the value in textfield is altered with 'hello' =>
Normal situation
- When clearing the textfield again, the onError action of the
AjaxFormComponentUpdatingBehavior is called,
because the value is empty and the field is required
- When clicking the button again the textfield is rewritten, but has an
empty value instead of 'hello' => ERROR situation
If my explanation isn't enough, please let me know and I try again.
Hope someone can test my code and tell me what I am doing wrong..
Many thanks, Marieke
TestPage.html
----------------------
<form wicket:id="webform">
<input type="text" wicket:id="acTest"/>
<input type="button" wicket:id="btnTest" value="set textfield
value"/>
</form>
TestPage.java
-----------------------
public class TestPage extends WebPage {
public TestPage(){
Form webform = new Form("webform", new CompoundPropertyModel(new
FormBean()));
add(webform);
final TextField acTest = new TextField("acTest");
webform.add(acTest);
acTest.setRequired(true);
acTest.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
System.out.println("onchange - onupdate");
}
@Override
protected void onError(AjaxRequestTarget target,
RuntimeException e){
System.out.println("onchange - onerror");
}
});
webform.add(new AjaxLink("btnTest") {
@Override
public void onClick(AjaxRequestTarget target) {
FormBean formBean =
(FormBean)getPage().get("webform").getDefaultModelObject();
formBean.setAcTest("hello");
target.addComponent(acTest);
}
});
}
public class FormBean implements Serializable{
private String acTest;
public FormBean(){
}
public String getAcTest() {
return acTest;
}
public void setAcTest(String acTest) {
this.acTest = acTest;
}
}
}
**** DISCLAIMER ****
<A HREF="http://www.tvh.be/newen/pages/emaildisclaimer.html">
http://www.tvh.be/newen/pages/emaildisclaimer.html </A>
"This message is delivered to all addressees subject to the conditions
set forth in the attached disclaimer, which is an integral part of this
message."