Re: guice-injection on page vs. components

2009-06-29 Thread Aaron Dixon
Figured this one out, thanks Igor.

Our pages extended from a base page that was manually injecting
services -- I'm not sure why -- so the components were getting the
proxy and pages were getting the direct instance. I fixed this and
things work perfectly now.

Thanks for your help.

On Fri, Jun 26, 2009 at 12:39 PM, Igor Vaynberg wrote:
> it is wicket-guice module that wraps the service that is retrieved
> from guice with a serializable proxy, not guice itself.
>
> this module treats pages and components exactly the same way because
> page IS A component. i am not sure why pages work differently for you
> if you use the same @Inject annotation and letting the module do the
> injection for you rather then guice itself.
>
> if you take the service that is causing a problem on a page and inject
> that into a component it works fine? can you verify that the thing
> being injected into a page is the wicket serializable proxy rather
> then the direct instance?
>
> -igor
>
> On Fri, Jun 26, 2009 at 10:20 AM, Aaron Dixon wrote:
>> But the nice thing about Guice/Wicket is that you don't have to
>> concern yourself with the serialization problem. And for my non-page
>> components, injection works perfectly. (This is because Guice injects
>> a *serializable* proxy not an actual instance of the service itself.
>> On detach/serialization, the proxy is serialized and on
>> deserializaiton/rehydration, Guice/Wicket will inject the
>> proxy/service again.)
>>
>> So, to reiterate, my problem is that all of this works perfectly for
>> me for any non-page components, but when I @Inject on a Page, the
>> service that is injected is not a proxy and therefore not
>> serializable... and therefore I get the serialization exceptions.
>>
>> Technically Guice IS injecting my service at the page level, it's just
>> injecting the instance itself and not wrapping it a proxy, whereas it
>> IS injecting serializable proxies for non-page components. Why?
>>
>>
>> On Thu, Jun 25, 2009 at 2:04 PM, Mauro Ciancio wrote:
>>> On Wed, Jun 24, 2009 at 1:38 PM, Aaron Dixon  wrote:
>>>

 org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
 Unable to serialize class:
 com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94
 Field hierarchy is:
  2 [class=com.mycompany.pages.MyPage, path=2]
    private com.mycompany.dao.MyDao

 com.mycompany.pages.MyPage.myDao[class=com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94]
 <- field that is not serializable
    at

 org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:342)
    at

 org.apache.wicket.util.io.SerializableChecker.checkFields(SerializableChecker.java:610)
 ...
 

 Has anyone else noticed this?

>>>
>>>  Yes, it happens because the injected class isn't Serializable and when
>>> your page
>>> is serialized the exception is thrown.
>>>  You could use for example a
>>> LoadableDetachableModelto
>>> detach your DAO when
>>> your page is serialized.
>>>  Guice also comes with an interface named Provider. This could helps
>>> because it
>>> dont hold a reference to your un-serializable object.
>>>
>>> Example:
>>>
>>> class MyPage extends Page {
>>>  LoadableDetachableModel daoModel = new loadable() {
>>>    object get() {
>>>          return new dao();
>>>     }
>>>  };
>>>
>>>  void something() {
>>>     mydao = daoModel.getObject();
>>>     //stuff
>>>  }
>>>
>>>  void ondetach() {
>>>    super.ondetach()
>>>     daomodel.detach();
>>>   }
>>>  }
>>>
>>> HTH
>>> Cheers!
>>> --
>>> Mauro Ciancio
>>>
>>
>> -
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>>
>>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

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



Re: guice-injection on page vs. components

2009-06-28 Thread Luther Baker
I'm not sure this will help - but thought I'd post how I'm configuring
Guice. I've *not* had a serialization problem in my pages.

There are several ways to configure Guice and Wicket, I am configuring Guice
as a Module. I've tried to build up the example from xml configuration to
Guice Module to Dao to Service to Page ...

It's quite straightforward and the @Inject directives should be obvious but
maybe there is something else you might notice that will help.

-Luther



*web.xml*


wicket

org.apache.wicket.protocol.http.WicketFilter

  applicationFactoryClassName

org.apache.wicket.guice.GuiceWebApplicationFactory


module

org.effectiveprogramming.effprog.web.MainGuiceModule


configuration

development




*MainGuiceModule.java*

public class MainGuiceModule extends AbstractModule
{
/**
 * @see com.google.inject.AbstractModule#configure()
 */
@Override
protected void configure()
{
bind(WebApplication.class).to(MainApplication.class);

// archive
bind(ArchiveDao.class).to(ArchiveDaoImpl.class);
bind(ArchiveService.class).to(ArchiveServiceImpl.class);

// authentication
bind(UserDao.class).to(UserDaoImpl.class);
bind(UserService.class).to(UserServiceImpl.class);
bind(EncryptionService.class).to(EncryptionServiceImpl.class);

// cleanup
bind(TagCleanupStrategy.class).to(SimpleTagCleanupStrategy.class);

// category
bind(CategoryDao.class).to(CategoryDaoImpl.class);
bind(CategoryService.class).to(CategoryServiceImpl.class);

// post
bind(PostDao.class).to(PostDaoImpl.class);
bind(PostService.class).to(PostServiceImpl.class);

// profile
bind(ProfileDao.class).to(ProfileDaoImpl.class);
bind(ProfileService.class).to(ProfileServiceImpl.class);

// tag
bind(TagDao.class).to(TagDaoImpl.class);
bind(TagService.class).to(TagServiceImpl.class);
}
}


*PostDaoImpl.java*

@SuppressWarnings("unchecked")
public class PostDaoImpl implements PostDao
{
@Inject
private DaoHelper $;

/**
 * @see
org.effectiveprogramming.effprog.service.persistence.dao.PostDao#delete(org.effectiveprogramming.effprog.entity.Post)
 */
public void delete(final Post post)
{
$.delete(post);
}


*PostServiceImpl.java*

public class PostServiceImpl implements PostService
{
@Inject
private ArchiveDao archiveDao;

@Inject
private CategoryDao categoryDao;

@Inject
private PostDao postDao;

@Inject
private TagDao tagDao;


*PostEditorPage.java*

public class PostEditorPage extends BasicLayout implements
IHeaderContributor
{
public PostEditorPage()
{
super(new ResourceModel("head-title"));

// panel
final Panel feebackPanel = new FeedbackPanel("feedback-panel");
feebackPanel.setOutputMarkupPlaceholderTag(true);
feebackPanel.setOutputMarkupId(true);
add(feebackPanel);

// post
final Post post = new Post();
final PostForm form = new PostForm("new-post", post, feebackPanel);
add(form);
}

public PostEditorPage(final Post post)
{
super(new ResourceModel("head-title"));

// panel
final Panel feebackPanel = new FeedbackPanel("feedback-panel");
feebackPanel.setOutputMarkupPlaceholderTag(true);
feebackPanel.setOutputMarkupId(true);
add(feebackPanel);

// post
final PostForm form = new PostForm("new-post", post, feebackPanel);
add(form);
}

private static class PostForm extends StatelessForm
{
private static final long serialVersionUID = 1L;

private static final List EMPTY_LIST =
Collections.emptyList();

@Inject
private CategoryService categoryService;

@Inject
private PostService postService;

@Inject
private TagService tagService;

@Inject
private TagCleanupStrategy tagCleanupStrategy;


*UnpublishedPostsPage.java*

public class UnpublishedPostsPage extends BasicLayout implements
IHeaderContributor
{
@Inject
private PostService postService;

public UnpublishedPostsPage()
{
super(new ResourceModel("head-title"));

// Who am I anyway?
final UserSession sess = (UserSession) Session.get();
final User user = sess.getUser();

// display posts in a panel
final Panel panel = new PostsPanel("posts-panel", new
UnpublishedPostsModel(postService, user), PublishedFlag.UNPUBLISHED);
add(panel);
}


On Fri, Jun 26, 2009 at 12:39 PM, Igor Vaynberg wrote:

> it is wicket-guice module that wraps the service that is retrieved
> from guice with a serializable proxy, not guice itself.
>
> this module treats pages and components exactly the same way becaus

Re: guice-injection on page vs. components

2009-06-26 Thread Igor Vaynberg
it is wicket-guice module that wraps the service that is retrieved
from guice with a serializable proxy, not guice itself.

this module treats pages and components exactly the same way because
page IS A component. i am not sure why pages work differently for you
if you use the same @Inject annotation and letting the module do the
injection for you rather then guice itself.

if you take the service that is causing a problem on a page and inject
that into a component it works fine? can you verify that the thing
being injected into a page is the wicket serializable proxy rather
then the direct instance?

-igor

On Fri, Jun 26, 2009 at 10:20 AM, Aaron Dixon wrote:
> But the nice thing about Guice/Wicket is that you don't have to
> concern yourself with the serialization problem. And for my non-page
> components, injection works perfectly. (This is because Guice injects
> a *serializable* proxy not an actual instance of the service itself.
> On detach/serialization, the proxy is serialized and on
> deserializaiton/rehydration, Guice/Wicket will inject the
> proxy/service again.)
>
> So, to reiterate, my problem is that all of this works perfectly for
> me for any non-page components, but when I @Inject on a Page, the
> service that is injected is not a proxy and therefore not
> serializable... and therefore I get the serialization exceptions.
>
> Technically Guice IS injecting my service at the page level, it's just
> injecting the instance itself and not wrapping it a proxy, whereas it
> IS injecting serializable proxies for non-page components. Why?
>
>
> On Thu, Jun 25, 2009 at 2:04 PM, Mauro Ciancio wrote:
>> On Wed, Jun 24, 2009 at 1:38 PM, Aaron Dixon  wrote:
>>
>>>
>>> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
>>> Unable to serialize class:
>>> com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94
>>> Field hierarchy is:
>>>  2 [class=com.mycompany.pages.MyPage, path=2]
>>>    private com.mycompany.dao.MyDao
>>>
>>> com.mycompany.pages.MyPage.myDao[class=com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94]
>>> <- field that is not serializable
>>>    at
>>>
>>> org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:342)
>>>    at
>>>
>>> org.apache.wicket.util.io.SerializableChecker.checkFields(SerializableChecker.java:610)
>>> ...
>>> 
>>>
>>> Has anyone else noticed this?
>>>
>>
>>  Yes, it happens because the injected class isn't Serializable and when
>> your page
>> is serialized the exception is thrown.
>>  You could use for example a
>> LoadableDetachableModelto
>> detach your DAO when
>> your page is serialized.
>>  Guice also comes with an interface named Provider. This could helps
>> because it
>> dont hold a reference to your un-serializable object.
>>
>> Example:
>>
>> class MyPage extends Page {
>>  LoadableDetachableModel daoModel = new loadable() {
>>    object get() {
>>          return new dao();
>>     }
>>  };
>>
>>  void something() {
>>     mydao = daoModel.getObject();
>>     //stuff
>>  }
>>
>>  void ondetach() {
>>    super.ondetach()
>>     daomodel.detach();
>>   }
>>  }
>>
>> HTH
>> Cheers!
>> --
>> Mauro Ciancio
>>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

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



Re: guice-injection on page vs. components

2009-06-26 Thread Aaron Dixon
But the nice thing about Guice/Wicket is that you don't have to
concern yourself with the serialization problem. And for my non-page
components, injection works perfectly. (This is because Guice injects
a *serializable* proxy not an actual instance of the service itself.
On detach/serialization, the proxy is serialized and on
deserializaiton/rehydration, Guice/Wicket will inject the
proxy/service again.)

So, to reiterate, my problem is that all of this works perfectly for
me for any non-page components, but when I @Inject on a Page, the
service that is injected is not a proxy and therefore not
serializable... and therefore I get the serialization exceptions.

Technically Guice IS injecting my service at the page level, it's just
injecting the instance itself and not wrapping it a proxy, whereas it
IS injecting serializable proxies for non-page components. Why?


On Thu, Jun 25, 2009 at 2:04 PM, Mauro Ciancio wrote:
> On Wed, Jun 24, 2009 at 1:38 PM, Aaron Dixon  wrote:
>
>>
>> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
>> Unable to serialize class:
>> com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94
>> Field hierarchy is:
>>  2 [class=com.mycompany.pages.MyPage, path=2]
>>    private com.mycompany.dao.MyDao
>>
>> com.mycompany.pages.MyPage.myDao[class=com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94]
>> <- field that is not serializable
>>    at
>>
>> org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:342)
>>    at
>>
>> org.apache.wicket.util.io.SerializableChecker.checkFields(SerializableChecker.java:610)
>> ...
>> 
>>
>> Has anyone else noticed this?
>>
>
>  Yes, it happens because the injected class isn't Serializable and when
> your page
> is serialized the exception is thrown.
>  You could use for example a
> LoadableDetachableModelto
> detach your DAO when
> your page is serialized.
>  Guice also comes with an interface named Provider. This could helps
> because it
> dont hold a reference to your un-serializable object.
>
> Example:
>
> class MyPage extends Page {
>  LoadableDetachableModel daoModel = new loadable() {
>    object get() {
>          return new dao();
>     }
>  };
>
>  void something() {
>     mydao = daoModel.getObject();
>     //stuff
>  }
>
>  void ondetach() {
>    super.ondetach()
>     daomodel.detach();
>   }
>  }
>
> HTH
> Cheers!
> --
> Mauro Ciancio
>

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



Re: guice-injection on page vs. components

2009-06-25 Thread Douglas Ferguson
If this is the case then why aren't components effected?

D/


On 6/25/09 2:04 PM, "Mauro Ciancio"  wrote:

On Wed, Jun 24, 2009 at 1:38 PM, Aaron Dixon  wrote:

>
> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
> Unable to serialize class:
> com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94
> Field hierarchy is:
>  2 [class=com.mycompany.pages.MyPage, path=2]
>private com.mycompany.dao.MyDao
>
> com.mycompany.pages.MyPage.myDao[class=com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94]
> <- field that is not serializable
>at
>
> org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:342)
>at
>
> org.apache.wicket.util.io.SerializableChecker.checkFields(SerializableChecker.java:610)
> ...
> 
>
> Has anyone else noticed this?
>

  Yes, it happens because the injected class isn't Serializable and when
your page
is serialized the exception is thrown.
  You could use for example a
LoadableDetachableModelto
detach your DAO when
your page is serialized.
  Guice also comes with an interface named Provider. This could helps
because it
dont hold a reference to your un-serializable object.

Example:

class MyPage extends Page {
  LoadableDetachableModel daoModel = new loadable() {
object get() {
  return new dao();
 }
  };

  void something() {
 mydao = daoModel.getObject();
 //stuff
  }

  void ondetach() {
super.ondetach()
 daomodel.detach();
   }
 }

HTH
Cheers!
--
Mauro Ciancio



Re: guice-injection on page vs. components

2009-06-25 Thread Mauro Ciancio
On Wed, Jun 24, 2009 at 1:38 PM, Aaron Dixon  wrote:

>
> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
> Unable to serialize class:
> com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94
> Field hierarchy is:
>  2 [class=com.mycompany.pages.MyPage, path=2]
>private com.mycompany.dao.MyDao
>
> com.mycompany.pages.MyPage.myDao[class=com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94]
> <- field that is not serializable
>at
>
> org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:342)
>at
>
> org.apache.wicket.util.io.SerializableChecker.checkFields(SerializableChecker.java:610)
> ...
> 
>
> Has anyone else noticed this?
>

  Yes, it happens because the injected class isn't Serializable and when
your page
is serialized the exception is thrown.
  You could use for example a
LoadableDetachableModelto
detach your DAO when
your page is serialized.
  Guice also comes with an interface named Provider. This could helps
because it
dont hold a reference to your un-serializable object.

Example:

class MyPage extends Page {
  LoadableDetachableModel daoModel = new loadable() {
object get() {
  return new dao();
 }
  };

  void something() {
 mydao = daoModel.getObject();
 //stuff
  }

  void ondetach() {
super.ondetach()
 daomodel.detach();
   }
 }

HTH
Cheers!
-- 
Mauro Ciancio


Re: guice-injection on page vs. components

2009-06-24 Thread Luther Baker
For what it's worth ... I use Guice injection across the entire codebase.

Pages get Services
Services get Daos
Daos get connections ... etc

I even inject utility classes as needed and can't say I've had any problems.

-Luther



On Wed, Jun 24, 2009 at 11:38 AM, Aaron Dixon  wrote:

> Hello, all -
>
> Guice/Wicket integration is excellent, but doesn't seem to work properly
> when I use @Inject-ed services on my *page* classes. It only seems to work
> when I inject services on components of my pages. I get
> WicketNotSerializableExceptions for services that I inject on my page class
> instances.
>
> So, if this is my page class:
>
> 
>
> public class MyPage extends WebPage {
>
>@Inject
>   private MyDao myDao; // causes WicketNotSerializableException
>
>   public MyPage() {
>   add(new MyPanel() {
>   @Inject
>   private MyDao myDao; // works fine and dandy
>   ...
>   }
>   }
> }
>
> 
>
> I get:
>
> 
>
>
> org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
> Unable to serialize class:
> com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94
> Field hierarchy is:
>  2 [class=com.mycompany.pages.MyPage, path=2]
>private com.mycompany.dao.MyDao
>
> com.mycompany.pages.MyPage.myDao[class=com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94]
> <- field that is not serializable
>at
>
> org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:342)
>at
>
> org.apache.wicket.util.io.SerializableChecker.checkFields(SerializableChecker.java:610)
> ...
> 
>
> Has anyone else noticed this?
>


guice-injection on page vs. components

2009-06-24 Thread Aaron Dixon
Hello, all -

Guice/Wicket integration is excellent, but doesn't seem to work properly
when I use @Inject-ed services on my *page* classes. It only seems to work
when I inject services on components of my pages. I get
WicketNotSerializableExceptions for services that I inject on my page class
instances.

So, if this is my page class:



public class MyPage extends WebPage {

@Inject
   private MyDao myDao; // causes WicketNotSerializableException

   public MyPage() {
   add(new MyPanel() {
   @Inject
   private MyDao myDao; // works fine and dandy
   ...
   }
   }
}



I get:



org.apache.wicket.util.io.SerializableChecker$WicketNotSerializableException:
Unable to serialize class:
com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94
Field hierarchy is:
  2 [class=com.mycompany.pages.MyPage, path=2]
private com.mycompany.dao.MyDao
com.mycompany.pages.MyPage.myDao[class=com.mycompany.dao.MyDao$$EnhancerByGuice$$3e6e9f94]
<- field that is not serializable
at
org.apache.wicket.util.io.SerializableChecker.check(SerializableChecker.java:342)
at
org.apache.wicket.util.io.SerializableChecker.checkFields(SerializableChecker.java:610)
...


Has anyone else noticed this?