Friday, December 31, 2010

Wicket : Unable to hide/show the components through Ajax

Hi,

Just came across a problem, where I was not able to hide a text field on a DropDown Change event.

On the onChange event of the dropdown i was doing the following :

myDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
private static final long serialVersionUID = 1L;
@Override
protected void onUpdate(AjaxRequestTarget target) {
myTxtField.clearInput();
myTxtField.setModelObject("");
myTxtField.setEnabled(false);
myTxtField.setVisible(false);
target.addComponent(myTxtField);
}
});

Solution:
I added the following line in the onUpdate method and it worked:

myTxtField.setOutputMarkupPlaceholderTag(true);

The SetOutputMarkupPlaceholder() method helps to re-render the wicket components.

Thanks,
Sanjay Ingole

No comments:

Post a Comment