You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Gabi Kaltman <gk...@yahoo.com> on 2009/08/06 09:22:19 UTC

DataView/IDataProvider/Detach

Hi,

I'm very young on the Wicket planet, so please excuse my simple question related to DataView/IDataProvider

My configuration:
1. I use a DataView (MyDataView)
2. I added a PageNavigator to MyDataView
3. I defined a IDataProvider attached to  MyDataView (MyDataProvider)
4. MyDataProvider has a not-serializable field (MyField)
5. MyField is used in the method MyDataProvider.size()
6. I use Wicket 1.4.0

What I do:
1.  In the method MyDataProvider.detach() , I nullify MyField (MyField = null)

What happens:
1. When I navigate through pages, I get a NPE in MyDataProvider.size() as MyField became null

How I fixed it:
1. I overrode in MyDataView the method getDataProvider(). Didn't work. I noticed that this method is never invoked
2. I tested again null in MyDataProvider.size(). If MyField is null, I just reinitialize it. It works

My question is if this solution is the optimal one, or there is a better one?

Thanks,
kaltman 



      

Re: DataView/IDataProvider/Detach

Posted by Igor Vaynberg <ig...@gmail.com>.
detach() is used to detach any state at the end of request. this can
include memory related, serialization related tasks, whatever other
tasks the component needs.

if you mark the field as transient, then indeed you do not have to
null it out in ondetach - at least not for serialization reasons, but
you still have to keep the lazy load logic for that field because if
the component is loaded from storage the field will again be null.

-igor

On Fri, Aug 7, 2009 at 2:42 AM, Robin Sander<ro...@gmx.net> wrote:
>
> Hi,
>
> correct me if I'm wrong, Igor, but I thought detach() is used to keep the
> model memory footprint low
> *between requests* and Serialization is a total different story.
> If I mark a field as transient I don't have to nullify it in detach().
> For example using a IDataProvider for pagination:
> If I set a (transient) field to null after every request I have to
> initialize it before every request too,
> sounds inefficient to me. To re-initialize a transient field I would use
> readObject(ObjectInputStream in)
> instead.
> If I'm right the following comment in IDetachable is misleading:
>
>        /**
>         * Detaches model after use. This is generally used to null out
> transient references that can be
>         * re-attached later.
>         */
>        void detach();
>
> What am I missing?
>
> Robin.
>
>
>
> On 06.08.2009, at 21:45, Igor Vaynberg wrote:
>
>> yep, lazy init is the way to do things. also helps to mark those
>> fields as transient as an additional safeguard.
>>
>> -igor
>>
>> On Thu, Aug 6, 2009 at 12:22 AM, Gabi Kaltman<gk...@yahoo.com> wrote:
>>>
>>> Hi,
>>>
>>> I'm very young on the Wicket planet, so please excuse my simple question
>>> related to DataView/IDataProvider
>>>
>>> My configuration:
>>> 1. I use a DataView (MyDataView)
>>> 2. I added a PageNavigator to MyDataView
>>> 3. I defined a IDataProvider attached to  MyDataView (MyDataProvider)
>>> 4. MyDataProvider has a not-serializable field (MyField)
>>> 5. MyField is used in the method MyDataProvider.size()
>>> 6. I use Wicket 1.4.0
>>>
>>> What I do:
>>> 1.  In the method MyDataProvider.detach() , I nullify MyField (MyField =
>>> null)
>>>
>>> What happens:
>>> 1. When I navigate through pages, I get a NPE in MyDataProvider.size() as
>>> MyField became null
>>>
>>> How I fixed it:
>>> 1. I overrode in MyDataView the method getDataProvider(). Didn't work. I
>>> noticed that this method is never invoked
>>> 2. I tested again null in MyDataProvider.size(). If MyField is null, I
>>> just reinitialize it. It works
>>>
>>> My question is if this solution is the optimal one, or there is a better
>>> one?
>>>
>>> Thanks,
>>> kaltman
>>>
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: DataView/IDataProvider/Detach

Posted by Gabi Kaltman <gk...@yahoo.com>.
Hi Robin,

If I understood correctly, your question is: why nullifying in detach()
a transient field? The only answer I see is related to your
observation: memory footprint and serialization are 2 different
aspects. So, when one implements an IDataProvider , one should deal
with both aspects without making assumptions about the framework. Maybe
the framework decides to keep in memory the IDataProvider for a time t
and only then, to serialize it and store it. This means that for the
time t, your (possible large) object will stay in memory.



I'm not sure that my explanation is ok, but I do not have a better one. :)



About performance, some other posts suggest that the transient object should be cached, so, it can be retrieved fast.



Regards,

kaltman

--- On Fri, 8/7/09, Robin Sander <ro...@gmx.net> wrote:

From: Robin Sander <ro...@gmx.net>
Subject: Re: DataView/IDataProvider/Detach
To: users@wicket.apache.org
Date: Friday, August 7, 2009, 11:42 AM


Hi,

correct me if I'm wrong, Igor, but I thought detach() is used to keep the model memory footprint low
*between requests* and Serialization is a total different story.
If I mark a field as transient I don't have to nullify it in detach().
For example using a IDataProvider for pagination:
If I set a (transient) field to null after every request I have to initialize it before every request too,
sounds inefficient to me. To re-initialize a transient field I would use readObject(ObjectInputStream in)
instead.
If I'm right the following comment in IDetachable is misleading:

    /**
     * Detaches model after use. This is generally used to null out transient references that can be
     * re-attached later.
     */
    void detach();

What am I missing?

Robin.



On 06.08.2009, at 21:45, Igor Vaynberg wrote:

> yep, lazy init is the way to do things. also helps to mark those
> fields as transient as an additional safeguard.
> 
> -igor
> 
> On Thu, Aug 6, 2009 at 12:22 AM, Gabi Kaltman<gk...@yahoo.com> wrote:
>> Hi,
>> 
>> I'm very young on the Wicket planet, so please excuse my simple question related to DataView/IDataProvider
>> 
>> My configuration:
>> 1. I use a DataView (MyDataView)
>> 2. I added a PageNavigator to MyDataView
>> 3. I defined a IDataProvider attached to  MyDataView (MyDataProvider)
>> 4. MyDataProvider has a not-serializable field (MyField)
>> 5. MyField is used in the method MyDataProvider.size()
>> 6. I use Wicket 1.4.0
>> 
>> What I do:
>> 1.  In the method MyDataProvider.detach() , I nullify MyField (MyField = null)
>> 
>> What happens:
>> 1. When I navigate through pages, I get a NPE in MyDataProvider.size() as MyField became null
>> 
>> How I fixed it:
>> 1. I overrode in MyDataView the method getDataProvider(). Didn't work. I noticed that this method is never invoked
>> 2. I tested again null in MyDataProvider.size(). If MyField is null, I just reinitialize it. It works
>> 
>> My question is if this solution is the optimal one, or there is a better one?
>> 
>> Thanks,
>> kaltman
>> 
>> 
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org


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




      

Re: DataView/IDataProvider/Detach

Posted by Robin Sander <ro...@gmx.net>.
Hi,

correct me if I'm wrong, Igor, but I thought detach() is used to keep  
the model memory footprint low
*between requests* and Serialization is a total different story.
If I mark a field as transient I don't have to nullify it in detach().
For example using a IDataProvider for pagination:
If I set a (transient) field to null after every request I have to  
initialize it before every request too,
sounds inefficient to me. To re-initialize a transient field I would  
use readObject(ObjectInputStream in)
instead.
If I'm right the following comment in IDetachable is misleading:

	/**
	 * Detaches model after use. This is generally used to null out  
transient references that can be
	 * re-attached later.
	 */
	void detach();

What am I missing?

Robin.



On 06.08.2009, at 21:45, Igor Vaynberg wrote:

> yep, lazy init is the way to do things. also helps to mark those
> fields as transient as an additional safeguard.
>
> -igor
>
> On Thu, Aug 6, 2009 at 12:22 AM, Gabi Kaltman<gk...@yahoo.com>  
> wrote:
>> Hi,
>>
>> I'm very young on the Wicket planet, so please excuse my simple  
>> question related to DataView/IDataProvider
>>
>> My configuration:
>> 1. I use a DataView (MyDataView)
>> 2. I added a PageNavigator to MyDataView
>> 3. I defined a IDataProvider attached to  MyDataView (MyDataProvider)
>> 4. MyDataProvider has a not-serializable field (MyField)
>> 5. MyField is used in the method MyDataProvider.size()
>> 6. I use Wicket 1.4.0
>>
>> What I do:
>> 1.  In the method MyDataProvider.detach() , I nullify MyField  
>> (MyField = null)
>>
>> What happens:
>> 1. When I navigate through pages, I get a NPE in  
>> MyDataProvider.size() as MyField became null
>>
>> How I fixed it:
>> 1. I overrode in MyDataView the method getDataProvider(). Didn't  
>> work. I noticed that this method is never invoked
>> 2. I tested again null in MyDataProvider.size(). If MyField is  
>> null, I just reinitialize it. It works
>>
>> My question is if this solution is the optimal one, or there is a  
>> better one?
>>
>> Thanks,
>> kaltman
>>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org


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


Re: DataView/IDataProvider/Detach

Posted by Igor Vaynberg <ig...@gmail.com>.
yep, lazy init is the way to do things. also helps to mark those
fields as transient as an additional safeguard.

-igor

On Thu, Aug 6, 2009 at 12:22 AM, Gabi Kaltman<gk...@yahoo.com> wrote:
> Hi,
>
> I'm very young on the Wicket planet, so please excuse my simple question related to DataView/IDataProvider
>
> My configuration:
> 1. I use a DataView (MyDataView)
> 2. I added a PageNavigator to MyDataView
> 3. I defined a IDataProvider attached to  MyDataView (MyDataProvider)
> 4. MyDataProvider has a not-serializable field (MyField)
> 5. MyField is used in the method MyDataProvider.size()
> 6. I use Wicket 1.4.0
>
> What I do:
> 1.  In the method MyDataProvider.detach() , I nullify MyField (MyField = null)
>
> What happens:
> 1. When I navigate through pages, I get a NPE in MyDataProvider.size() as MyField became null
>
> How I fixed it:
> 1. I overrode in MyDataView the method getDataProvider(). Didn't work. I noticed that this method is never invoked
> 2. I tested again null in MyDataProvider.size(). If MyField is null, I just reinitialize it. It works
>
> My question is if this solution is the optimal one, or there is a better one?
>
> Thanks,
> kaltman
>
>
>
>

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