Reputation: 1583
I have this piece of code:
final WebMarkupContainer container = new WebMarkupContainer("container");
container.setVisible(aBooleanValue);
container.setOutputMarkupId(true);
container.setOutputMarkupPlaceholderTag(true);
add(container);
final CheckBox hideContainer = new CheckBox("hideContainer", new PropertyModel<Boolean>(getModel(), "hideContainer"));
container.add(hideContainer);
hideContainer.add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
if (Boolean.TRUE.equals(getModelObject().getHideContainer())) {
container.setVisible(false);
} else {
container.setVisible(true);
}
target.addComponent(MyForm.this.get("container"));
}
});
Which creates a WebMarkupContainer and a Checkbox, if the checkbox is checked then the container should be hidden, if the checkbox is not checked, then the container should be visible.
But this doesn't work... what am I doing wrong?
Upvotes: 0
Views: 1480
Reputation: 312
A best wicket practice is to configure wicket components to pull data rather than pushing data to them. Instead of setting the visibility of the component can you please try to override the isVisible method of the component.
final WebMarkupContainer container = new WebMarkupContainer("container"){
public boolean isVisible(){
return showContainer;//showContainer is a boolean instance variable
}
};
And in the onchange event change the showContainer value and add the component to target.
Upvotes: 1
Reputation: 1251
You could try using AjaxCheckBox. Override onUpdate(AjaxRequestTarget)
method and move code from behavior, as it should work correctly on all browsers.
Upvotes: 2