Hello Wicket Wizards,

I am experiencing this strange behavior with the *CompoundPropertyModel
form, a required text field, and the OnChangeBehavior added to the text
field*.

*Apache Wicket Version: 8.12.0 *

Here is the situation:

//Page/Class level variable
int charCount = 0;

//Inside Page constructor
Form<CriteriaTO> criteriaForm = new Form<CriteriaTO> ("searchCriteria",
 new CompoundPropertyModel< CriteriaTO >(criteriaObject));

TextField<String> txtFirstName = new TextField<String>
("firstName");//firstName is bean property
*txtFirstName.setRequired(true); //This seems to be preventing the change
event when removing the last remaining character*
txtFirstName.setOutputMarkupId(true);
txtFirstName.setMarkupId("firstNmId");

//Now, add onChange behavior to capture the change event
txtFirstName .add(new OnChangeAjaxBehavior() {

/**
*
*/
private static final long serialVersionUID = 1L;

@Override
protected void onUpdate(AjaxRequestTarget target) {

System.out.println("Change counter:" + ++counter);

}

});

criteriaForm.add(txtFirstName);

Test: Enter a then b then c then d and then e in first Name. Following is
the output for each change event.
 [stdout] (default task-21) Change counter:1
 [stdout] (default task-22) Change counter:2
 [stdout] (default task-20) Change counter:3
 [stdout] (default task-23) Change counter:4
 [stdout] (default task-24) Change counter:5

When removing each letter at a time, the change event seems to be* not
fired when the last letter is left*. Following is the output when I start
removing one letter at a time from the end.
 [stdout] (default task-25) Change counter:6
 [stdout] (default task-26) Change counter:7
 [stdout] (default task-28) Change counter:8
 [stdout] (default task-27) Change counter:9

Here, Change counter:10 did not get printed when removing 'a' from the
page. Additionally, the bean firstName field had one letter left i.e. 'a'
even though the UI has all letters removed from the screen.

When I remove the txtFirstName.setRequired(true) line the OnChangeBehavior
works just fine, printing the Change Counter:10  and also removing the last
character from the bean property.

Any suggestions?

Thank you,
-Mihir.

Reply via email to