I was building a visibility behavior on Wicket that used Hamcrest Matcher (and some Lambdaj) to see if any of the given property models values match the given matcher and if so, then it would hide the component.
public class HiddenWhenValueMatchesBehavior<T> extends Behavior {
private static final long serialVersionUID = 1L;
Collection<IModel<T>> models;
Matcher<T> matcher;
public HiddenWhenValueMatchesBehavior(Matcher<T> matcher, IModel<T>... models) {
this.models = Arrays.<IModel<T>> asList(models);
this.matcher = matcher;
}
@Override
public void onConfigure(Component component) {
super.onConfigure(component);
component.setVisible(!hasItem(matcher).matches(extract(models, on(IModel.class).getObject())));
}
}
Only then I realized that Hamcrest Matchers are not serializable and according to their issue tracker they have no intention to ever be serializable.
Above is just an example, I could see several uses for passing Matchers to Behaviors and other Wicket stuff.
Any way around this?
Wrap the matcher in a model:
public HiddenWhenValueMatchesBehavior(IModel> matcher, IModel… models) {