This would not be any more efficient than scanning for fields that
implement IDetachable. Which is: rather inefficient for when you have
component hierarchies of 100-1000s of components.
We have created a utility method at $$$ job that removes the need for
the null check, and takes into account arrays and lists:
protected void onDetach() {
detachQuietly(model1);
detachQuietly(model2);
}
public static void detachQuietly(Object detachable)
{
if (detachable instanceof Component)
{
((Component) detachable).detach();
}
else if (detachable instanceof IDetachable)
{
((IDetachable) detachable).detach();
}
else if (detachable instanceof Map)
{
for (Map.Entry< ? , ? > entry : ((Map< ? , ? >) detachable).entrySet())
{
detachQuietly(entry.getKey());
detachQuietly(entry.getValue());
}
}
else if (detachable instanceof Iterable)
{
Iterator< ? > iter = ((Iterable< ? >) detachable).iterator();
while (iter.hasNext())
{
detachQuietly(iter.next());
}
}
else if (detachable instanceof Object[])
{
Object[] array = (Object[]) detachable;
for (Object curObj : array)
{
detachQuietly(curObj);
}
}
}
On Mon, Dec 5, 2016 at 4:34 PM, Boris Goldowsky <[email protected]> wrote:
> Is there any way to create an annotation that would mark a field’s value as
> something that ought to be detached? That is, instead of:
>
> private IModel<User> userModel;
>
> @Override
> public void onDetach() {
> super.onDetach();
> if (userModel != null)
> userModel.detach();
> }
>
> I would like to be able to write simply:
>
> @Detach
> private IModel<User> userModel;
>
> Has anyone tried this?
>
> Boris
>
--
Become a Wicket expert, learn from the best: http://wicketinaction.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]