Re: Annotation for detachable field

2016-12-06 Thread Peter Henderson
On 6 December 2016 at 10:05, Martin Grigorov  wrote:

> http://markmail.org/message/qttwc5kunubl6ieo



Oh I'm glad auto detach was not included way back when I started learning
Wicket.
Coming from a legacy swing app which spoon fed components what to display
and how/when to display it,
I found wickets model approach really odd. I took, what seems, ages to
fully grok the idea. Property Models really muddied my water, to such an
extent I never use them.

I've many many panels which can either being displaying data or editing it.
When editing onDetach does not detach the underlying LoadableDetachableModel
When displaying detaching works as expected.

This way I can load and detach an entity from JPA and store it in a LDM.


Peter.


Re: Annotation for detachable field

2016-12-06 Thread Martin Grigorov
http://markmail.org/message/qttwc5kunubl6ieo

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Mon, Dec 5, 2016 at 4:46 PM, Martijn Dashorst  wrote:

> 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 
> 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 userModel;
> >
> > @Override
> > public void onDetach() {
> > super.onDetach();
> > if (userModel != null)
> > userModel.detach();
> > }
> >
> > I would like to be able to write simply:
> >
> > @Detach
> > private IModel userModel;
> >
> > Has anyone tried this?
> >
> > Boris
> >
>
>
>
> --
> Become a Wicket expert, learn from the best: http://wicketinaction.com
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>


Re: Annotation for detachable field

2016-12-05 Thread Martijn Dashorst
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  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 userModel;
>
> @Override
> public void onDetach() {
> super.onDetach();
> if (userModel != null)
> userModel.detach();
> }
>
> I would like to be able to write simply:
>
> @Detach
> private IModel userModel;
>
> Has anyone tried this?
>
> Boris
>



-- 
Become a Wicket expert, learn from the best: http://wicketinaction.com

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Annotation for detachable field

2016-12-05 Thread Boris Goldowsky
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 userModel;

@Override
public void onDetach() {
super.onDetach();
if (userModel != null)
userModel.detach();
}

I would like to be able to write simply:

@Detach
private IModel userModel;

Has anyone tried this?

Boris