Answer : need to specialize the AlaxCheckBox class.
Details :
Step #1 : consider these Wicket class attributes :
private static Boolean isAuto = false;
private static final String WICKET_CB = "autoCheck";
private IModel<Boolean> autoCheckModel = new Model<Boolean>(isAuto);
private AutoRefreshCheckBox autoCheck = new AutoRefreshCheckBox(WICKET_CB, autoCheckModel);
Step #2 : the customized AjaxCheckBox is added within the constructor of this same Wicket class :
add(autoCheck);
Step #3 : specialized AjaxCheckBox class body
private class AutoRefreshCheckBox extends AjaxCheckBox
{
public AutoRefreshCheckBox(final String id, IModel<Boolean> model)
{
super(id, model);
}
/**
* Says whether or not the "AutoRefresh" mode is enabled
*/
public Boolean isChecked()
{
final String value = getValue();
if (value != null)
{
try
{
return Strings.isTrue(value);
}
catch (StringValueConversionException e)
{
return false;
}
}
return false;
}
@Override
protected synchronized void onUpdate(AjaxRequestTarget target)
{
long period = 0L;
isAuto = isChecked();
autoCheckModel.setObject(isAuto);
target.addComponent(refreshBtn);
if (isAuto)
{
period = Long.valueOf(periodField.getValue()) * TO_MS;
// might be completed (e.g.: overall page refresh)
}
else
{
// might be completed (e.g.: period = PERIOD_MONITOR_OFF;)
}
// might be completed (e.g.: other components update)
}
}





No comments:
Post a Comment