Best way to work with the iterator of IDataProvider

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Best way to work with the iterator of IDataProvider

Charles Moulliard
Hi,

I would like to know what is the best way to work with the method
iterator of DataProvider.

I have created a class implementing IDataProvider. Depending of a
parameter, the DAO service called is not the same inside in the
iterator method. For some DAO services, a list is returned but for one
service, an object is returned instead of a list.

If I try to create a ArrayList inside the iterator, the following
error is generated :

org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
Unable to serialize class: java.util.AbstractList$Itr
Field hierarchy is:
  0 [class=com.xpectis.x3s.fundbox.web.RequestPage, path=0]
    private java.lang.Object
org.apache.wicket.MarkupContainer.children [class=[Ljava.lang.Object;]
      java.lang.Object org.apache.wicket.Component.data[3]
[class=com.xpectis.x3s.fundbox.web.RequestPage$1, path=0:requestList]
        private final
org.apache.wicket.markup.repeater.data.IDataProvider
org.apache.wicket.markup.repeater.data.DataViewBase.dataProvider
[class=com.xpectis.x3s.fundbox.web.data.RequestProvider]
          private java.util.Iterator
com.xpectis.x3s.fundbox.web.data.RequestProvider.it
[class=java.util.AbstractList$Itr] <----- field that is not
serializable
        at org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:346)

How can I avoid this issue ?

Here is my code :

public class RequestProvider implements IDataProvider {

...

        public Iterator iterator(int first, int count) {
               
                result = new ArrayList<PlatformDTO>();

                if (requestFormModel != null) {
                       
                        if (requestFormModel.getId() != null) {
                                request = requestService.getRequest(requestFormModel.getId());
                                result.add(request);
                                it = result.iterator();
                               
                        } else if (requestFormModel.getFileName() != null) {
                                it = requestService.findRequestByFileName(requestFormModel.getFileName()).iterator();
                               
                        }

Regards,


Charles Moulliard
Senior Enterprise Architect
Apache Camel Committer

*****************************
blog : http://cmoulliard.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Best way to work with the iterator of IDataProvider

T Ames
I see several undefined objects:

result
requestFormModel
it

If these are defined at the class level, they must be serializable.

If you have Logging set at Info, Wicket will give you the actual field that
is not serializable, although from the error it looks like something to do
with AbstractList

Iterator objects are not serializable.  I would look at how you are defining
the "it" variable.



On Mon, Sep 28, 2009 at 7:25 AM, Charles Moulliard <[hidden email]>wrote:

> Hi,
>
> I would like to know what is the best way to work with the method
> iterator of DataProvider.
>
> I have created a class implementing IDataProvider. Depending of a
> parameter, the DAO service called is not the same inside in the
> iterator method. For some DAO services, a list is returned but for one
> service, an object is returned instead of a list.
>
> If I try to create a ArrayList inside the iterator, the following
> error is generated :
>
>
> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
> Unable to serialize class: java.util.AbstractList$Itr
> Field hierarchy is:
>  0 [class=com.xpectis.x3s.fundbox.web.RequestPage, path=0]
>    private java.lang.Object
> org.apache.wicket.MarkupContainer.children [class=[Ljava.lang.Object;]
>      java.lang.Object org.apache.wicket.Component.data[3]
> [class=com.xpectis.x3s.fundbox.web.RequestPage$1, path=0:requestList]
>        private final
> org.apache.wicket.markup.repeater.data.IDataProvider
> org.apache.wicket.markup.repeater.data.DataViewBase.dataProvider
> [class=com.xpectis.x3s.fundbox.web.data.RequestProvider]
>          private java.util.Iterator
> com.xpectis.x3s.fundbox.web.data.RequestProvider.it
> [class=java.util.AbstractList$Itr] <----- field that is not
> serializable
>        at
> org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:346)
>
> How can I avoid this issue ?
>
> Here is my code :
>
> public class RequestProvider implements IDataProvider {
>
> ...
>
>        public Iterator iterator(int first, int count) {
>
>                result = new ArrayList<PlatformDTO>();
>
>                if (requestFormModel != null) {
>
>                        if (requestFormModel.getId() != null) {
>                                request =
> requestService.getRequest(requestFormModel.getId());
>                                result.add(request);
>                                it = result.iterator();
>
>                        } else if (requestFormModel.getFileName() != null) {
>                                it =
> requestService.findRequestByFileName(requestFormModel.getFileName()).iterator();
>
>                        }
>
> Regards,
>
>
> Charles Moulliard
> Senior Enterprise Architect
> Apache Camel Committer
>
> *****************************
> blog : http://cmoulliard.blogspot.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Best way to work with the iterator of IDataProvider

T Ames
Further, you don't really need to define the Iterator, just return them.


       public Iterator iterator(int first, int count) {

               result = new ArrayList<PlatformDTO>();

               if (requestFormModel != null) {

                       if (requestFormModel.getId() != null) {
                               request =
requestService.getRequest(requestFormModel.getId());

>                                result.add(request);
>                                return result.iterator();
>
>                        } else if (requestFormModel.getFileName() != null) {
>                                return
> requestService.findRequestByFileName(requestFormModel.getFileName()).iterator();
>



On Mon, Sep 28, 2009 at 9:08 AM, T Ames <[hidden email]> wrote:

> I see several undefined objects:
>
> result
> requestFormModel
> it
>
> If these are defined at the class level, they must be serializable.
>
> If you have Logging set at Info, Wicket will give you the actual field that
> is not serializable, although from the error it looks like something to do
> with AbstractList
>
> Iterator objects are not serializable.  I would look at how you are
> defining the "it" variable.
>
>
>
>
> On Mon, Sep 28, 2009 at 7:25 AM, Charles Moulliard <[hidden email]>wrote:
>
>> Hi,
>>
>> I would like to know what is the best way to work with the method
>> iterator of DataProvider.
>>
>> I have created a class implementing IDataProvider. Depending of a
>> parameter, the DAO service called is not the same inside in the
>> iterator method. For some DAO services, a list is returned but for one
>> service, an object is returned instead of a list.
>>
>> If I try to create a ArrayList inside the iterator, the following
>> error is generated :
>>
>>
>> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
>> Unable to serialize class: java.util.AbstractList$Itr
>> Field hierarchy is:
>>  0 [class=com.xpectis.x3s.fundbox.web.RequestPage, path=0]
>>    private java.lang.Object
>> org.apache.wicket.MarkupContainer.children [class=[Ljava.lang.Object;]
>>      java.lang.Object org.apache.wicket.Component.data[3]
>> [class=com.xpectis.x3s.fundbox.web.RequestPage$1, path=0:requestList]
>>        private final
>> org.apache.wicket.markup.repeater.data.IDataProvider
>> org.apache.wicket.markup.repeater.data.DataViewBase.dataProvider
>> [class=com.xpectis.x3s.fundbox.web.data.RequestProvider]
>>          private java.util.Iterator
>> com.xpectis.x3s.fundbox.web.data.RequestProvider.it
>> [class=java.util.AbstractList$Itr] <----- field that is not
>> serializable
>>        at
>> org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:346)
>>
>> How can I avoid this issue ?
>>
>> Here is my code :
>>
>> public class RequestProvider implements IDataProvider {
>>
>> ...
>>
>>        public Iterator iterator(int first, int count) {
>>
>>                result = new ArrayList<PlatformDTO>();
>>
>>                if (requestFormModel != null) {
>>
>>                        if (requestFormModel.getId() != null) {
>>                                request =
>> requestService.getRequest(requestFormModel.getId());
>>                                result.add(request);
>>                                it = result.iterator();
>>
>>                        } else if (requestFormModel.getFileName() != null)
>> {
>>                                it =
>> requestService.findRequestByFileName(requestFormModel.getFileName()).iterator();
>>
>>                        }
>>
>> Regards,
>>
>>
>> Charles Moulliard
>> Senior Enterprise Architect
>> Apache Camel Committer
>>
>> *****************************
>> blog : http://cmoulliard.blogspot.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
Reply | Threaded
Open this post in threaded view
|

Re: Best way to work with the iterator of IDataProvider

vineetsemwal
Iterator is not serializable,
wicket will try to serialize it if it's at class level
so either move it inside iterator method
or make it transient ,
In your case,you can easily move it inside method ;)

--
regards,
Vineet Semwal

On Mon, Sep 28, 2009 at 6:42 PM, T Ames <[hidden email]> wrote:

> Further, you don't really need to define the Iterator, just return them.
>
>
>       public Iterator iterator(int first, int count) {
>
>               result = new ArrayList<PlatformDTO>();
>
>               if (requestFormModel != null) {
>
>                       if (requestFormModel.getId() != null) {
>                               request =
> requestService.getRequest(requestFormModel.getId());
>
> >                                result.add(request);
> >                                return result.iterator();
> >
> >                        } else if (requestFormModel.getFileName() != null)
> {
> >                                return
> >
> requestService.findRequestByFileName(requestFormModel.getFileName()).iterator();
> >
>
>
>
> On Mon, Sep 28, 2009 at 9:08 AM, T Ames <[hidden email]> wrote:
>
> > I see several undefined objects:
> >
> > result
> > requestFormModel
> > it
> >
> > If these are defined at the class level, they must be serializable.
> >
> > If you have Logging set at Info, Wicket will give you the actual field
> that
> > is not serializable, although from the error it looks like something to
> do
> > with AbstractList
> >
> > Iterator objects are not serializable.  I would look at how you are
> > defining the "it" variable.
> >
> >
> >
> >
> > On Mon, Sep 28, 2009 at 7:25 AM, Charles Moulliard <[hidden email]
> >wrote:
> >
> >> Hi,
> >>
> >> I would like to know what is the best way to work with the method
> >> iterator of DataProvider.
> >>
> >> I have created a class implementing IDataProvider. Depending of a
> >> parameter, the DAO service called is not the same inside in the
> >> iterator method. For some DAO services, a list is returned but for one
> >> service, an object is returned instead of a list.
> >>
> >> If I try to create a ArrayList inside the iterator, the following
> >> error is generated :
> >>
> >>
> >>
> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
> >> Unable to serialize class: java.util.AbstractList$Itr
> >> Field hierarchy is:
> >>  0 [class=com.xpectis.x3s.fundbox.web.RequestPage, path=0]
> >>    private java.lang.Object
> >> org.apache.wicket.MarkupContainer.children [class=[Ljava.lang.Object;]
> >>      java.lang.Object org.apache.wicket.Component.data[3]
> >> [class=com.xpectis.x3s.fundbox.web.RequestPage$1, path=0:requestList]
> >>        private final
> >> org.apache.wicket.markup.repeater.data.IDataProvider
> >> org.apache.wicket.markup.repeater.data.DataViewBase.dataProvider
> >> [class=com.xpectis.x3s.fundbox.web.data.RequestProvider]
> >>          private java.util.Iterator
> >> com.xpectis.x3s.fundbox.web.data.RequestProvider.it
> >> [class=java.util.AbstractList$Itr] <----- field that is not
> >> serializable
> >>        at
> >>
> org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:346)
> >>
> >> How can I avoid this issue ?
> >>
> >> Here is my code :
> >>
> >> public class RequestProvider implements IDataProvider {
> >>
> >> ...
> >>
> >>        public Iterator iterator(int first, int count) {
> >>
> >>                result = new ArrayList<PlatformDTO>();
> >>
> >>                if (requestFormModel != null) {
> >>
> >>                        if (requestFormModel.getId() != null) {
> >>                                request =
> >> requestService.getRequest(requestFormModel.getId());
> >>                                result.add(request);
> >>                                it = result.iterator();
> >>
> >>                        } else if (requestFormModel.getFileName() !=
> null)
> >> {
> >>                                it =
> >>
> requestService.findRequestByFileName(requestFormModel.getFileName()).iterator();
> >>
> >>                        }
> >>
> >> Regards,
> >>
> >>
> >> Charles Moulliard
> >> Senior Enterprise Architect
> >> Apache Camel Committer
> >>
> >> *****************************
> >> blog : http://cmoulliard.blogspot.com
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >>
> >>
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Best way to work with the iterator of IDataProvider

Charles Moulliard
In reply to this post by T Ames
I have found the error.

List Result = new ArrayList<PlatformDTO>(); must be defined outside of the iterator method

and also the answer to my question.

When the result is empty or null, then I must return a null iterator


T Ames wrote
I see several undefined objects:

result
requestFormModel
it

If these are defined at the class level, they must be serializable.

If you have Logging set at Info, Wicket will give you the actual field that
is not serializable, although from the error it looks like something to do
with AbstractList

Iterator objects are not serializable.  I would look at how you are defining
the "it" variable.



On Mon, Sep 28, 2009 at 7:25 AM, Charles Moulliard <cmoulliard@gmail.com>wrote:

> Hi,
>
> I would like to know what is the best way to work with the method
> iterator of DataProvider.
>
> I have created a class implementing IDataProvider. Depending of a
> parameter, the DAO service called is not the same inside in the
> iterator method. For some DAO services, a list is returned but for one
> service, an object is returned instead of a list.
>
> If I try to create a ArrayList inside the iterator, the following
> error is generated :
>
>
> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
> Unable to serialize class: java.util.AbstractList$Itr
> Field hierarchy is:
>  0 [class=com.xpectis.x3s.fundbox.web.RequestPage, path=0]
>    private java.lang.Object
> org.apache.wicket.MarkupContainer.children [class=[Ljava.lang.Object;]
>      java.lang.Object org.apache.wicket.Component.data[3]
> [class=com.xpectis.x3s.fundbox.web.RequestPage$1, path=0:requestList]
>        private final
> org.apache.wicket.markup.repeater.data.IDataProvider
> org.apache.wicket.markup.repeater.data.DataViewBase.dataProvider
> [class=com.xpectis.x3s.fundbox.web.data.RequestProvider]
>          private java.util.Iterator
> com.xpectis.x3s.fundbox.web.data.RequestProvider.it
> [class=java.util.AbstractList$Itr] <----- field that is not
> serializable
>        at
> org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:346)
>
> How can I avoid this issue ?
>
> Here is my code :
>
> public class RequestProvider implements IDataProvider {
>
> ...
>
>        public Iterator iterator(int first, int count) {
>
>                result = new ArrayList<PlatformDTO>();
>
>                if (requestFormModel != null) {
>
>                        if (requestFormModel.getId() != null) {
>                                request =
> requestService.getRequest(requestFormModel.getId());
>                                result.add(request);
>                                it = result.iterator();
>
>                        } else if (requestFormModel.getFileName() != null) {
>                                it =
> requestService.findRequestByFileName(requestFormModel.getFileName()).iterator();
>
>                        }
>
> Regards,
>
>
> Charles Moulliard
> Senior Enterprise Architect
> Apache Camel Committer
>
> *****************************
> blog : http://cmoulliard.blogspot.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>