Today in France, we celebrate ""
Posts
04/07/10 : Android sorting
16/06/10 : Flex XML parsing
15/06/10 : Android settings
14/06/10 : Pax daemon
10/06/10 : Bundle CPU %
04/06/10 : Wicket CheckBox
03/06/10 : Thread monitor

By tag
Ajax
Android
AspectJ
Flex
Java
JMX
OSGi
Shell
Wickets

Here are some lights and tips on various Object Oriented Programming aspects that I would have dealt with during my software development and architecture activities..., for sharing.

"Beauty is an inexhaustible source of happyness for the one who discovers it" (Alexis Carrel)



Thursday, 3 June 2010

Wicket AjaxCheckBox

Question : how to Ajax-ify a CheckBox in Wickets ?

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

Previous Post Next Post