You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Mike Mander <wi...@gmx.de> on 2011/07/28 09:00:33 UTC

Problem while decouple page flow by using SpringBean

Hi,

i would like to decouple the page dependencies. My page flow is 
implemented by using bookmarkable page links.
As we all know they take a page class as parameter. This couples both pages.

So i thought it's a good idea to give the page class a name in my Spring 
application context and reference it in
the caller page.

public StartPage extends WebPage {

   @SpringBean(name="nextPageClass")
   private Class<? extends Page> _nextPageClass;

   public StartPage() {
     add(new BookmarkablePageLink("toNextPage", _nextPageClass);
   }
}

My application context defines:

<bean id="nextPageClass" class="java.lang.Class" factory-method="forName">
<constructor-arg value="my.NextPage"/>
</bean>

But it's not working while java.lang.Class is final. I get

Caused by: java.lang.IllegalArgumentException: Cannot subclass final 
class class java.lang.Class
     at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
     at 
net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
     at 
net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
     at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
     at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
     at 
org.apache.wicket.proxy.LazyInitProxyFactory.createProxy(LazyInitProxyFactory.java:174)
     at 
org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:130)
     at org.apache.wicket.injection.Injector.inject(Injector.java:103)
     ... 47 more

Can i do this in another way?

Thanks
Mike

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


Re: Problem while decouple page flow by using SpringBean

Posted by Mike Mander <wi...@gmx.de>.
Thanks Martin for the work-around.

Jira added: https://issues.apache.org/jira/browse/WICKET-3936

Thanks
Mike

Am 28.07.2011 09:26, schrieb Martin Grigorov:
> i would like to decouple the page dependencies. My page flow is 
> implemented by using bookmarkable page links.
> As we all know they take a page class as parameter. This couples both 
> pages.
>
> So i thought it's a good idea to give the page class a name in my 
> Spring application context and reference it in
> the caller page.
>
> public StartPage extends WebPage {
>
>   @SpringBean(name="nextPageClass")
>   private Class<? extends Page> _nextPageClass;
>
>   public StartPage() {
>     add(new BookmarkablePageLink("toNextPage", _nextPageClass);
>   }
> }
>
> My application context defines:
>
> <bean id="nextPageClass" class="java.lang.Class" 
> factory-method="forName">
> <constructor-arg value="my.NextPage"/>
> </bean>
>
> But it's not working while java.lang.Class is final. I get
>
> Caused by: java.lang.IllegalArgumentException: Cannot subclass final 
> class class java.lang.Class
>     at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
>     at 
> net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
>     at 
> net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
>     at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
>     at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
>     at 
> org.apache.wicket.proxy.LazyInitProxyFactory.createProxy(LazyInitProxyFactory.java:174)
>     at 
> org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:130)
>     at org.apache.wicket.injection.Injector.inject(Injector.java:103)
>     ... 47 more 


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


Re: Problem while decouple page flow by using SpringBean

Posted by Martin Grigorov <mg...@apache.org>.
It is quite easy to extend SpringComponentInjector so that it will
look for another annotation, e.g. @SpringBean2 which wont be proxy-ed.
Yet another one is to create a ticket to add an additional attribute
to original @SpringBean (proxy = false).

On Thu, Jul 28, 2011 at 10:18 AM, Mike Mander <wi...@gmx.de> wrote:
> Found a solution, but would be great if i could get some tips about the
> consequences.
> I was wrapping the beans in proxies by setting the flag in
> SpringComponentInjector to true.
> Now it's set to false and it's working. But i'm a bit in doubt that i opened
> pandoras box
> with this.
>
> It was
> addComponentInstantiationListener(new SpringComponentInjector(this,
> context(), true));
> and is now
> addComponentInstantiationListener(new SpringComponentInjector(this,
> context(), false));
>
> Thanks
> Mike
>
> Hi,
>>
>> i would like to decouple the page dependencies. My page flow is
>> implemented by using bookmarkable page links.
>> As we all know they take a page class as parameter. This couples both
>> pages.
>>
>> So i thought it's a good idea to give the page class a name in my Spring
>> application context and reference it in
>> the caller page.
>>
>> public StartPage extends WebPage {
>>
>>  @SpringBean(name="nextPageClass")
>>  private Class<? extends Page> _nextPageClass;
>>
>>  public StartPage() {
>>    add(new BookmarkablePageLink("toNextPage", _nextPageClass);
>>  }
>> }
>>
>> My application context defines:
>>
>> <bean id="nextPageClass" class="java.lang.Class" factory-method="forName">
>> <constructor-arg value="my.NextPage"/>
>> </bean>
>>
>> But it's not working while java.lang.Class is final. I get
>>
>> Caused by: java.lang.IllegalArgumentException: Cannot subclass final class
>> class java.lang.Class
>>    at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
>>    at
>> net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
>>    at
>> net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
>>    at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
>>    at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
>>    at
>> org.apache.wicket.proxy.LazyInitProxyFactory.createProxy(LazyInitProxyFactory.java:174)
>>    at
>> org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:130)
>>    at org.apache.wicket.injection.Injector.inject(Injector.java:103)
>>    ... 47 more
>>
>> Can i do this in another way?
>>
>> Thanks
>> Mike
>>
>> ---------------------------------------------------------------------
>> 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
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: Problem while decouple page flow by using SpringBean

Posted by Mike Mander <wi...@gmx.de>.
Found a solution, but would be great if i could get some tips about the 
consequences.
I was wrapping the beans in proxies by setting the flag in 
SpringComponentInjector to true.
Now it's set to false and it's working. But i'm a bit in doubt that i 
opened pandoras box
with this.

It was
addComponentInstantiationListener(new SpringComponentInjector(this, 
context(), true));
and is now
addComponentInstantiationListener(new SpringComponentInjector(this, 
context(), false));

Thanks
Mike

Hi,
>
> i would like to decouple the page dependencies. My page flow is 
> implemented by using bookmarkable page links.
> As we all know they take a page class as parameter. This couples both 
> pages.
>
> So i thought it's a good idea to give the page class a name in my 
> Spring application context and reference it in
> the caller page.
>
> public StartPage extends WebPage {
>
>   @SpringBean(name="nextPageClass")
>   private Class<? extends Page> _nextPageClass;
>
>   public StartPage() {
>     add(new BookmarkablePageLink("toNextPage", _nextPageClass);
>   }
> }
>
> My application context defines:
>
> <bean id="nextPageClass" class="java.lang.Class" 
> factory-method="forName">
> <constructor-arg value="my.NextPage"/>
> </bean>
>
> But it's not working while java.lang.Class is final. I get
>
> Caused by: java.lang.IllegalArgumentException: Cannot subclass final 
> class class java.lang.Class
>     at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
>     at 
> net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
>     at 
> net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
>     at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
>     at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
>     at 
> org.apache.wicket.proxy.LazyInitProxyFactory.createProxy(LazyInitProxyFactory.java:174)
>     at 
> org.apache.wicket.spring.injection.annot.AnnotProxyFieldValueFactory.getFieldValue(AnnotProxyFieldValueFactory.java:130)
>     at org.apache.wicket.injection.Injector.inject(Injector.java:103)
>     ... 47 more
>
> Can i do this in another way?
>
> Thanks
> Mike
>
> ---------------------------------------------------------------------
> 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