You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris <ch...@gmx.at> on 2015/05/02 19:38:09 UTC

handling non serializable objects

Hi all,

what is the best approach to handle non-serializable objects in Wicket pages? E.g. when an object has a DAO injected and this object is a field of a Wicket page?

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


Re: handling non serializable objects

Posted by Chris <ch...@gmx.at>.
Hi Martin,

thanks for your answer.
I am initializing 2 A’s and put them in a List.

In the code below, I query for the index of an A in the current List ( aList.indexOf(a)). I am getting an error as the index cannot be retrieved (-1) based on the proxies.
How can I retrieve the correct index (0 or 1) via the #indexOf method?

Chris

> Am 03.05.2015 um 21:24 schrieb Martin Grigorov <mg...@apache.org>:
> 
> You can wrap it in a proxy yourself:
> 
> A a = LazyInitProxyFactory.createProxy(A.class, new IProxyTargetLocator() {
>  @Override public Object locateProxyTarget() {return
> beanFactory.getBean("a", A.class)}
> });
> 
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
> 
> On Sun, May 3, 2015 at 1:17 PM, Chris <ch...@gmx.at> wrote:
> 
>> Hi Martin,
>> 
>> In another panel of the same page, I have injected a service class via
>> @Springbean and this service class implements „BeanFactoryAware“.
>> As soon as a specific button in this panel is clicked, a method of this
>> service class is called which creates A via beanFactory.getBean(„a",
>> A.class).
>> Via a broadcast event, a is then propagated to the panel (not page) as
>> shown below.
>> 
>> Thanks Chris
>> 
>> 
>>> Am 03.05.2015 um 08:56 schrieb Martin Grigorov <mg...@apache.org>:
>>> 
>>> Hi,
>>> 
>>> Please show us how A instance is being created.
>>> 
>>> Martin Grigorov
>>> Wicket Training and Consulting
>>> https://twitter.com/mtgrigorov
>>> 
>>> On Sat, May 2, 2015 at 11:32 PM, Chris <ch...@gmx.at> wrote:
>>> 
>>>> Hi Martin,
>>>> 
>>>> I have a page with a field of type A that is set over a broadcast event.
>>>> Class A has a dao which is injected via constructor.
>>>> The field dao cannot be serializable. How could I change this so a proxy
>>>> is injected?
>>>> 
>>>> Thanks!
>>>> 
>>>> Page {
>>>> 
>>>> A a;
>>>> 
>>>> public void onEvent(IEvent<?> event) {
>>>>       super.onEvent(event);
>>>> 
>>>>       if (event.getPayload() instanceof Item) {
>>>>              Item update = (Item) event.getPayload();
>>>>              a = update.getA();
>>>> 
>>>> }
>>>> 
>>>> A implements Serializable {
>>>> 
>>>> private Dao dao;
>>>> 
>>>> @Autowired
>>>> public A(Dao dao) {
>>>>         this.dao = dao;
>>>>     }
>>>> 
>>>> }
>>>> 
>>>> 
>>>>> Am 02.05.2015 um 21:28 schrieb Martin Grigorov <mg...@apache.org>:
>>>>> 
>>>>> Hi,
>>>>> 
>>>>> Injected how?
>>>>> wicket-spring and -guice inject serializable proxies so there is no
>> such
>>>>> issue with them
>>>>> On May 2, 2015 10:26 PM, "Chris" <ch...@gmx.at> wrote:
>>>>> 
>>>>>> Hi all,
>>>>>> 
>>>>>> what is the best approach to handle non-serializable objects in Wicket
>>>>>> pages? E.g. when an object has a DAO injected and this object is a
>>>> field of
>>>>>> a Wicket page?
>>>>>> 
>>>>>> Thanks a lot,
>>>>>> Chris
>>>>>> ---------------------------------------------------------------------
>>>>>> 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
>> 
>> 


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


Re: handling non serializable objects

Posted by Martin Grigorov <mg...@apache.org>.
You can wrap it in a proxy yourself:

A a = LazyInitProxyFactory.createProxy(A.class, new IProxyTargetLocator() {
  @Override public Object locateProxyTarget() {return
beanFactory.getBean("a", A.class)}
});

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

On Sun, May 3, 2015 at 1:17 PM, Chris <ch...@gmx.at> wrote:

> Hi Martin,
>
> In another panel of the same page, I have injected a service class via
> @Springbean and this service class implements „BeanFactoryAware“.
> As soon as a specific button in this panel is clicked, a method of this
> service class is called which creates A via beanFactory.getBean(„a",
> A.class).
> Via a broadcast event, a is then propagated to the panel (not page) as
> shown below.
>
> Thanks Chris
>
>
> > Am 03.05.2015 um 08:56 schrieb Martin Grigorov <mg...@apache.org>:
> >
> > Hi,
> >
> > Please show us how A instance is being created.
> >
> > Martin Grigorov
> > Wicket Training and Consulting
> > https://twitter.com/mtgrigorov
> >
> > On Sat, May 2, 2015 at 11:32 PM, Chris <ch...@gmx.at> wrote:
> >
> >> Hi Martin,
> >>
> >> I have a page with a field of type A that is set over a broadcast event.
> >> Class A has a dao which is injected via constructor.
> >> The field dao cannot be serializable. How could I change this so a proxy
> >> is injected?
> >>
> >> Thanks!
> >>
> >> Page {
> >>
> >> A a;
> >>
> >> public void onEvent(IEvent<?> event) {
> >>        super.onEvent(event);
> >>
> >>        if (event.getPayload() instanceof Item) {
> >>               Item update = (Item) event.getPayload();
> >>               a = update.getA();
> >>
> >> }
> >>
> >> A implements Serializable {
> >>
> >> private Dao dao;
> >>
> >> @Autowired
> >>  public A(Dao dao) {
> >>          this.dao = dao;
> >>      }
> >>
> >> }
> >>
> >>
> >>> Am 02.05.2015 um 21:28 schrieb Martin Grigorov <mg...@apache.org>:
> >>>
> >>> Hi,
> >>>
> >>> Injected how?
> >>> wicket-spring and -guice inject serializable proxies so there is no
> such
> >>> issue with them
> >>> On May 2, 2015 10:26 PM, "Chris" <ch...@gmx.at> wrote:
> >>>
> >>>> Hi all,
> >>>>
> >>>> what is the best approach to handle non-serializable objects in Wicket
> >>>> pages? E.g. when an object has a DAO injected and this object is a
> >> field of
> >>>> a Wicket page?
> >>>>
> >>>> Thanks a lot,
> >>>> Chris
> >>>> ---------------------------------------------------------------------
> >>>> 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: handling non serializable objects

Posted by Chris <ch...@gmx.at>.
Hi Martin,

In another panel of the same page, I have injected a service class via @Springbean and this service class implements „BeanFactoryAware“.
As soon as a specific button in this panel is clicked, a method of this service class is called which creates A via beanFactory.getBean(„a", A.class).
Via a broadcast event, a is then propagated to the panel (not page) as shown below.

Thanks Chris


> Am 03.05.2015 um 08:56 schrieb Martin Grigorov <mg...@apache.org>:
> 
> Hi,
> 
> Please show us how A instance is being created.
> 
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
> 
> On Sat, May 2, 2015 at 11:32 PM, Chris <ch...@gmx.at> wrote:
> 
>> Hi Martin,
>> 
>> I have a page with a field of type A that is set over a broadcast event.
>> Class A has a dao which is injected via constructor.
>> The field dao cannot be serializable. How could I change this so a proxy
>> is injected?
>> 
>> Thanks!
>> 
>> Page {
>> 
>> A a;
>> 
>> public void onEvent(IEvent<?> event) {
>>        super.onEvent(event);
>> 
>>        if (event.getPayload() instanceof Item) {
>>               Item update = (Item) event.getPayload();
>>               a = update.getA();
>> 
>> }
>> 
>> A implements Serializable {
>> 
>> private Dao dao;
>> 
>> @Autowired
>>  public A(Dao dao) {
>>          this.dao = dao;
>>      }
>> 
>> }
>> 
>> 
>>> Am 02.05.2015 um 21:28 schrieb Martin Grigorov <mg...@apache.org>:
>>> 
>>> Hi,
>>> 
>>> Injected how?
>>> wicket-spring and -guice inject serializable proxies so there is no such
>>> issue with them
>>> On May 2, 2015 10:26 PM, "Chris" <ch...@gmx.at> wrote:
>>> 
>>>> Hi all,
>>>> 
>>>> what is the best approach to handle non-serializable objects in Wicket
>>>> pages? E.g. when an object has a DAO injected and this object is a
>> field of
>>>> a Wicket page?
>>>> 
>>>> Thanks a lot,
>>>> Chris
>>>> ---------------------------------------------------------------------
>>>> 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: handling non serializable objects

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Please show us how A instance is being created.

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

On Sat, May 2, 2015 at 11:32 PM, Chris <ch...@gmx.at> wrote:

> Hi Martin,
>
> I have a page with a field of type A that is set over a broadcast event.
> Class A has a dao which is injected via constructor.
> The field dao cannot be serializable. How could I change this so a proxy
> is injected?
>
> Thanks!
>
> Page {
>
> A a;
>
>  public void onEvent(IEvent<?> event) {
>         super.onEvent(event);
>
>         if (event.getPayload() instanceof Item) {
>                Item update = (Item) event.getPayload();
>                a = update.getA();
>
> }
>
> A implements Serializable {
>
> private Dao dao;
>
>  @Autowired
>   public A(Dao dao) {
>           this.dao = dao;
>       }
>
> }
>
>
> > Am 02.05.2015 um 21:28 schrieb Martin Grigorov <mg...@apache.org>:
> >
> > Hi,
> >
> > Injected how?
> > wicket-spring and -guice inject serializable proxies so there is no such
> > issue with them
> > On May 2, 2015 10:26 PM, "Chris" <ch...@gmx.at> wrote:
> >
> >> Hi all,
> >>
> >> what is the best approach to handle non-serializable objects in Wicket
> >> pages? E.g. when an object has a DAO injected and this object is a
> field of
> >> a Wicket page?
> >>
> >> Thanks a lot,
> >> Chris
> >> ---------------------------------------------------------------------
> >> 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: handling non serializable objects

Posted by Chris <ch...@gmx.at>.
Hi Martin,

I have a page with a field of type A that is set over a broadcast event. Class A has a dao which is injected via constructor.
The field dao cannot be serializable. How could I change this so a proxy is injected?

Thanks!

Page {

A a;

 public void onEvent(IEvent<?> event) {
        super.onEvent(event);
     
   	if (event.getPayload() instanceof Item) {
               Item update = (Item) event.getPayload();
               a = update.getA();
		
}

A implements Serializable {

private Dao dao;

 @Autowired
  public A(Dao dao) {
          this.dao = dao;
      }

}


> Am 02.05.2015 um 21:28 schrieb Martin Grigorov <mg...@apache.org>:
> 
> Hi,
> 
> Injected how?
> wicket-spring and -guice inject serializable proxies so there is no such
> issue with them
> On May 2, 2015 10:26 PM, "Chris" <ch...@gmx.at> wrote:
> 
>> Hi all,
>> 
>> what is the best approach to handle non-serializable objects in Wicket
>> pages? E.g. when an object has a DAO injected and this object is a field of
>> a Wicket page?
>> 
>> Thanks a lot,
>> Chris
>> ---------------------------------------------------------------------
>> 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: handling non serializable objects

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Injected how?
wicket-spring and -guice inject serializable proxies so there is no such
issue with them
On May 2, 2015 10:26 PM, "Chris" <ch...@gmx.at> wrote:

> Hi all,
>
> what is the best approach to handle non-serializable objects in Wicket
> pages? E.g. when an object has a DAO injected and this object is a field of
> a Wicket page?
>
> Thanks a lot,
> Chris
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>