Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-05 Thread Leszek Gawron
igor.vaynberg wrote:
 this is nice.
 
 what i do like about it
 * you can inject anything anywhere
 
 what i dont like is
 * post constructor injection like youve mentioned - delegate or not it still
 sucks, a different pointcut is needed
yes .. that's ugly. I have posted a question on spring forum - have no 
answer yet (will also try on aspectj lists)

 * you have to keep your variables transient - very easy mistake to make,
 otherwise big boo boo might happen if the dependency is serializable and you
 wont know until much later
Why would you want your services serializable?

 * you have to inject everything - ie i cant take an instance of injected
 service and pass it to some other component to use
Do you really need to pass the service if you could just inject it also 
into target?

 * i dont like @Configure on the entire object, i like per-field annotations
 on the fields
that is probably the matter of taste. @Configurable gives you 2 work modes:

- the ability to autowire all setters by type or name:
@Configurable(autowire=Autowire.BY_NAME)

- injection configuration from a prototype
@Configurable
public class MyModel {
 private FooService fooService;

 //setter here
}

and in applicationContext :
bean class=com.mycompany.MyModel scope=prototype
!-- do any injection types you like --
/bean

In the second mode you can mix different injection types so it doesn't 
really matter the annotation is defined at class level.

I do not know if it is possible to configure AOP with field level 
annotations.

 * you have to have access to the java runtime args to install the weaver
not really. You can weave your classes 3 different ways:

- LTW - Load-Time Weaving, the classes are weaved as they are loaded at 
runtime. This is the only one that requires java agent configuration on 
command line

- aspectj compiler - compile your classes with special compiler. As the 
compiler extends standard JDT compiler you can use it on any classes 
(not only those to be weaved). For those using maven there is a special 
plugin utilising aspectj compiler.

- aspectj weaver - even if you have no access to java source you can 
weave .class files or whole jars that you compiled with standard compiler.

 what is needed to fix this
 * a different aspect that wraps the bean in the wicket-proxy just like we do
 now - that should give you the ultimate freedom, 
agreed, I will investigate the problem further

but then what worries me is
 if tomcat will let you cluster objects loaded through aspectj classloader.
I do not think this will be a problem when offline weaving is used. The 
class is loaded just as an ordinary class. Needs testing though.

-- 
Leszek Gawron
[EMAIL PROTECTED]

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-05 Thread Eelco Hillenius
Yeah. I'm using a similar patter for non-Wicket cases too. I actually
prefer this to wiring using XML.

Eelco


On 10/3/06, Joni Freeman [EMAIL PROTECTED] wrote:
 Yes, it works. I use it in many places.

 Joni

 On Tue, 2006-10-03 at 16:28 +0200, Matej Knopp wrote:
  But it should. I don't see reason why this wouldn't work? If I recall
  correctly it worked for me.
 
  -Matej
 
  Leszek Gawron wrote:
   Eelco Hillenius wrote:
   I just wanted to share another way of injecting spring services into
   wicket code. This one uses AOP.
  
   - o - Why another approach? - o -
  
   Using wicket-spring along with wicket-spring-annot works nicely for
   components (althought you have to remember not initializing it
   yourself)
   but does not work for other parts of application - models. Just ask
   your
   self how many times you have put a spring service into wicket page
   only
   to pass it to model constructed:
  
   Thanks for the contribution. It's always good to know multiple ways
   of doing this. However, in this case I was wondering whether you
   tried this?
  
   public class SomeModel extends SomeOtherModel {
  
  @SpringBean MyService service;
  
  public SomeModel() {
InjectorHolder.getInjector().inject(this);
  }
   }
  
   yep .. didn't work. Only Components get the dependencies injected.
  
 
 
  -
  Take Surveys. Earn Cash. Influence the Future of IT
  Join SourceForge.net's Techsay panel and you'll get the chance to share your
  opinions on IT  business topics through brief surveys -- and earn cash
  http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
  ___
  Wicket-user mailing list
  Wicket-user@lists.sourceforge.net
  https://lists.sourceforge.net/lists/listinfo/wicket-user
 



 -
 Take Surveys. Earn Cash. Influence the Future of IT
 Join SourceForge.net's Techsay panel and you'll get the chance to share your
 opinions on IT  business topics through brief surveys -- and earn cash
 http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
 ___
 Wicket-user mailing list
 Wicket-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/wicket-user


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-05 Thread Johan Compagner
 - o - Gotchas - o -Every programming solutions got one. This one also. With current
@Configurable implementation services get injected AFTER the injectee iscreated (after all constructors got invoked). That means this won't work: public class LeaguePage extends BaseSquasherPage { private LeagueService leagueService;
 public LeaguePage( PageParameters parameters ) throws StringValueConversionException { Long leagueId = parameters.getLong( id ); // nasty NPE here!
 League league = leagueService.loadLeague( leagueId ); add( new Label( leagueName, league.getName() ) ); } }Why is that?did you look what the did change in the byte codes?
At what point do they really do the injection?johan
-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-05 Thread Frank Bille
Hey LeszekLooks good. If you have time for it couldn't you turn this into a wiki? In that way it's easier for users to find this.http://www.wicket-wiki.org.uk/wiki
FrankOn 10/3/06, Leszek Gawron [EMAIL PROTECTED] wrote:
Hello,I just wanted to share another way of injecting spring services intowicket code. This one uses AOP.- o - Why another approach? - o -Using wicket-spring along with wicket-spring-annot works nicely for
components (althought you have to remember not initializing it yourself)but does not work for other parts of application - models. Just ask yourself how many times you have put a spring service into wicket page only
to pass it to model constructed: public class RankingPanel extends Panel { @SpringBean private LeagueService leagueService; public RankingPanel( String id, IModel leagueModel ) {
 super( id ); add( new ListView( ranking, new RankingModel( leagueService, leagueModel ) ) { @Override protected void populateItem( ListItem listItem ) {
 PlayerRank rank = (PlayerRank) listItem.getModelObject(); listItem.add( new Label( position, String.valueOf( rank.getPosition() ) ) ); listItem.add
( new Label( player, rank.getPlayer().getFullName() ) ); } } ); } }If you could have your model injected with appropriate service thiswould probably be:
 public class RankingPanel extends Panel { public RankingPanel( String id, IModel leagueModel ) { super( id ); add( new ListView( ranking, new RankingModel( leagueModel ) ) {
 @Override protected void populateItem( ListItem listItem ) { PlayerRank rank = (PlayerRank) listItem.getModelObject(); listItem.add( new Label( position, 
String.valueOf( rank.getPosition() ) ) ); listItem.add( new Label( player, rank.getPlayer().getFullName() ) ); } } ); } }
- o - What you'll need - o -- your current fancy project- one fresh spring (at least 2.0 M1). I have used 2.0-rc2.- one ripe aspectj (http://ibiblio.org/maven2/aspectj/
) especially aspectjrt and aspectjweaver. I have used 1.5.2.- java 1.5 (there are probably some ways to do it with 1.4 - didn'tbother to try)- o - Implementation - o -Spring 2.0
 M1 introduced @Configurable annotation [1]. We can use it toinject spring beans into ANY object (not only created by spring but alsosimply instantiated with new MyObject() ).Let's create a simple spring context:
 ?xml version=1.0 encoding=UTF-8? beans xmlns=http://www.springframework.org/schema/beans xmlns:xsi=
http://www.w3.org/2001/XMLSchema-instance xmlns:aop=http://www.springframework.org/schema/aop
 xmlns:tx=http://www.springframework.org/schema/tx xsi:schemaLocation= 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd bean class=org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor
/ aop:spring-configured/ bean id=leagueService class=com.mobilebox.squasher.service.impl.LeagueServiceImpl autowire=byName/
 /beansWe have a single service declared here. What's more important isaop:spring-configured/ which simply saying turns on Spring AspectJmachinery. Please refer to [1] for additional info.
Now let's build a wicket model: @Configurable(autowire = Autowire.BY_NAME, dependencyCheck = true) public class RankingModel extends LoadableDetachableModel { protected transient LeagueService leagueService;
 public void setLeagueService( LeagueService leagueService ) { this.leagueService = leagueService; } public RankingModel( IModel master ) { 
this.master = master; } @SuppressWarnings(unchecked) @Override protected Object load() { return new LinkedList( leagueService.getRanking( 
leagueService.loadRound( (Long) master.getObject( null ) ) ) ); } }Nothing shocking. Just remember to annotate your class with@Configurable and make your reference to LeagueService transient.
You need to put an additional file on the classpath to make it all work.The location should be META-INF/aop.xml. Mine states: aspectj weaver options=-showWeaveInfo -XmessageHandlerClass:
org.springframework.aop.aspectj.AspectJWeaverMessageHandler include within=com.mobilebox.squasher..*/ /weaver aspects include within=
org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect/ /aspects /aspectjYou can drop aspectj/weaver/@options. This is only for debuggingpurposes. Remember to change 
aspectj/weaver/include/@within attribute tomatch the package (and subpackages) you want weaved.That's all for coding. Let's run it.- o - Running - o -Put aspectjrt.jar on classpath. Create you JVM with additional option
(adjust aspectjweaver location): java -javaagent:lib/aspectjweaver.jar com.mobilebox.squasher.launcher.JettyRunnerIf you run your container from withing Eclipse IDE put'-javaagent:lib/aspectjweaver.jar' in 'VM arguments' editbox.
That's all. AspectJ will weave your RankingModel class on load andinject leagueService reference. 

Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-05 Thread James McLaughlin
Strange. Virtually all my models do this and it works perfectly. I think you are missing the id parameter in your SpringBean declaration. Maybe that is killing you.jimOn 10/3/06, 

Leszek Gawron [EMAIL PROTECTED] wrote:

Joni Freeman wrote: Yes, it works. I use it in many places. JoniI have just checked: public class GlobalNewsListModel extends LoadableDetachableModel { @SpringBean private NewsService newsService;
 public NewsService getNewsService() { return newsService; } @SuppressWarnings(unchecked) @Override protected Object load() {
 return new LinkedList( getNewsService().getGlobalNews(Session.get().getLocale().getLanguage(), 10 ) ); } }

throws NPE. Not much space for eror, is it? The only thing I can thinkof is that you are using nested classes or anonymous classes (which youshould not do for models - so I've read).--Leszek Gawron
-Take Surveys. Earn Cash. Influence the Future of ITJoin SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing listWicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user
-- // Jim McLaughlin // Director, Software Engineering// Stonewater Control Systems
// http://www.stonewatercontrols.com// (o) 847.864.1060 x107// (c) 773.416.0994

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-05 Thread Leszek Gawron
reposting...

igor.vaynberg wrote:
 this is nice.

 what i do like about it
 * you can inject anything anywhere

 what i dont like is
 * post constructor injection like youve mentioned - delegate or not 
  it still sucks, a different pointcut is needed
yes .. that's ugly. I have posted a question on spring forum - have no
answer yet (will also try on aspectj lists)

 * you have to keep your variables transient - very easy mistake to make,
 otherwise big boo boo might happen if the dependency is serializable 
  and you wont know until much later
Why would you want your services serializable?

 * you have to inject everything - ie i cant take an instance of injected
 service and pass it to some other component to use
Do you really need to pass the service if you could just inject it also
into target?

 * i dont like @Configure on the entire object, i like per-field 
  annotations on the fields
that is probably the matter of taste. @Configurable gives you 2 work modes:

- the ability to autowire all setters by type or name:
@Configurable(autowire=Autowire.BY_NAME)

- injection configuration from a prototype
@Configurable
public class MyModel {
 private FooService fooService;

 //setter here
}

and in applicationContext :
bean class=com.mycompany.MyModel scope=prototype
!-- do any injection types you like --
/bean

In the second mode you can mix different injection types so it doesn't
really matter the annotation is defined at class level.

I do not know if it is possible to configure AOP with field level
annotations.

 * you have to have access to the java runtime args to install the weaver
not really. You can weave your classes 3 different ways:

- LTW - Load-Time Weaving, the classes are weaved as they are loaded at
runtime. This is the only one that requires java agent configuration on
command line

- aspectj compiler - compile your classes with special compiler. As the
compiler extends standard JDT compiler you can use it on any classes
(not only those to be weaved). For those using maven there is a special
plugin utilising aspectj compiler.

- aspectj weaver - even if you have no access to java source you can
weave .class files or whole jars that you compiled with standard compiler.

 what is needed to fix this
 * a different aspect that wraps the bean in the wicket-proxy just 
  like we do now - that should give you the ultimate freedom,
agreed, I will investigate the problem further

  but then what worries me is
 if tomcat will let you cluster objects loaded through aspectj 
  classloader.
I do not think this will be a problem when offline weaving is used. The
class is loaded just as an ordinary class. Needs testing though.

-- 
Leszek Gawron
[EMAIL PROTECTED]



-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-05 Thread Leszek Gawron
Frank Bille wrote:
 Hey Leszek
 
 Looks good. If you have time for it couldn't you turn this into a wiki? 
 In that way it's easier for users to find this.
 
 http://www.wicket-wiki.org.uk/wiki http://www.wicket-wiki.org.uk/wiki
No problem. Since my last post I have found the proper (I hope) pointcut 
definition that allows services to be injected before initialization.

-- 
Leszek Gawron

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-05 Thread igor.vaynberg

 * you have to keep your variables transient - very easy mistake to make,
 otherwise big boo boo might happen if the dependency is serializable and
 you
 wont know until much later
Why would you want your services serializable?

because some services you are not in control of, they come from other
libraries, and they might implement Serializable. so if you inject this and
forget to mark the var as transient you are heading for a world of pain.

 * you have to inject everything - ie i cant take an instance of injected
 service and pass it to some other component to use
Do you really need to pass the service if you could just inject it also 
into target?

yes. i might want to perform some service resolution somewhere else, and
then give the component the one it needs to use - think plugins. declarative
injection works great, but by far not for all usecases.

 * i dont like @Configure on the entire object, i like per-field
 annotations
 on the fields
that is probably the matter of taste. @Configurable gives you 2 work modes:

- the ability to autowire all setters by type or name:
@Configurable(autowire=Autowire.BY_NAME)

- injection configuration from a prototype
@Configurable
public class MyModel {
 private FooService fooService;

 //setter here
}

and in applicationContext :
bean class=com.mycompany.MyModel scope=prototype
!-- do any injection types you like --
/bean

yeah, the second one: injection by prototype is horrid. can you imagine
configuring tiny components in application context - thats a lot of xml.

the reason i like fields is because i can mix in match. i have a lot of
situations where some components are injected and some are not, so for me
injecting the entire class wont work.

 * you have to have access to the java runtime args to install the weaver
not really. You can weave your classes 3 different ways:

- LTW - Load-Time Weaving, the classes are weaved as they are loaded at 
runtime. This is the only one that requires java agent configuration on 
command line

- aspectj compiler - compile your classes with special compiler. As the 
compiler extends standard JDT compiler you can use it on any classes 
(not only those to be weaved). For those using maven there is a special 
plugin utilising aspectj compiler.

im not a big fan of postcompilation steps even if they are transparent in
the ide. but at the end this might be the nicest way to go. with a maven
plugin it shouldnt be too bad i suppose.

- aspectj weaver - even if you have no access to java source you can 
weave .class files or whole jars that you compiled with standard compiler.

this wont work, the aspectj class loader has to be above the
webapplication's classloader otherwise all hell will break lose once you try
to store one of these objects in session. 

 what is needed to fix this
 * a different aspect that wraps the bean in the wicket-proxy just like we
 do
 now - that should give you the ultimate freedom, 
agreed, I will investigate the problem further

-Igor

-- 
View this message in context: 
http://www.nabble.com/-tutorial--Wicket-%2B-Spring-integration---revisited-tf2375652.html#a6663433
Sent from the Wicket - User mailing list archive at Nabble.com.


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-03 Thread Eelco Hillenius

 I just wanted to share another way of injecting spring services into
 wicket code. This one uses AOP.

 - o - Why another approach? - o -

 Using wicket-spring along with wicket-spring-annot works nicely for
 components (althought you have to remember not initializing it  
 yourself)
 but does not work for other parts of application - models. Just ask  
 your
 self how many times you have put a spring service into wicket page  
 only
 to pass it to model constructed:


Thanks for the contribution. It's always good to know multiple ways  
of doing this. However, in this case I was wondering whether you  
tried this?

public class SomeModel extends SomeOtherModel {

   @SpringBean MyService service;

   public SomeModel() {
 InjectorHolder.getInjector().inject(this);
   }
}


Eelco

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-03 Thread Leszek Gawron
Eelco Hillenius wrote:
 I just wanted to share another way of injecting spring services into
 wicket code. This one uses AOP.

 - o - Why another approach? - o -

 Using wicket-spring along with wicket-spring-annot works nicely for
 components (althought you have to remember not initializing it  
 yourself)
 but does not work for other parts of application - models. Just ask  
 your
 self how many times you have put a spring service into wicket page  
 only
 to pass it to model constructed:
 
 
 Thanks for the contribution. It's always good to know multiple ways  
 of doing this. However, in this case I was wondering whether you  
 tried this?
 
 public class SomeModel extends SomeOtherModel {
 
@SpringBean MyService service;
 
public SomeModel() {
  InjectorHolder.getInjector().inject(this);
}
 }

yep .. didn't work. Only Components get the dependencies injected.

-- 
Leszek Gawron

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-03 Thread Matej Knopp
But it should. I don't see reason why this wouldn't work? If I recall 
correctly it worked for me.

-Matej

Leszek Gawron wrote:
 Eelco Hillenius wrote:
 I just wanted to share another way of injecting spring services into
 wicket code. This one uses AOP.

 - o - Why another approach? - o -

 Using wicket-spring along with wicket-spring-annot works nicely for
 components (althought you have to remember not initializing it  
 yourself)
 but does not work for other parts of application - models. Just ask  
 your
 self how many times you have put a spring service into wicket page  
 only
 to pass it to model constructed:

 Thanks for the contribution. It's always good to know multiple ways  
 of doing this. However, in this case I was wondering whether you  
 tried this?

 public class SomeModel extends SomeOtherModel {

@SpringBean MyService service;

public SomeModel() {
  InjectorHolder.getInjector().inject(this);
}
 }
 
 yep .. didn't work. Only Components get the dependencies injected.
 


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-03 Thread Joni Freeman
Yes, it works. I use it in many places.

Joni

On Tue, 2006-10-03 at 16:28 +0200, Matej Knopp wrote:
 But it should. I don't see reason why this wouldn't work? If I recall 
 correctly it worked for me.
 
 -Matej
 
 Leszek Gawron wrote:
  Eelco Hillenius wrote:
  I just wanted to share another way of injecting spring services into
  wicket code. This one uses AOP.
 
  - o - Why another approach? - o -
 
  Using wicket-spring along with wicket-spring-annot works nicely for
  components (althought you have to remember not initializing it  
  yourself)
  but does not work for other parts of application - models. Just ask  
  your
  self how many times you have put a spring service into wicket page  
  only
  to pass it to model constructed:
 
  Thanks for the contribution. It's always good to know multiple ways  
  of doing this. However, in this case I was wondering whether you  
  tried this?
 
  public class SomeModel extends SomeOtherModel {
 
 @SpringBean MyService service;
 
 public SomeModel() {
   InjectorHolder.getInjector().inject(this);
 }
  }
  
  yep .. didn't work. Only Components get the dependencies injected.
  
 
 
 -
 Take Surveys. Earn Cash. Influence the Future of IT
 Join SourceForge.net's Techsay panel and you'll get the chance to share your
 opinions on IT  business topics through brief surveys -- and earn cash
 http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
 ___
 Wicket-user mailing list
 Wicket-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/wicket-user
 



-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-03 Thread Leszek Gawron
Joni Freeman wrote:
 Yes, it works. I use it in many places.
 
 Joni
I have just checked:

 public class GlobalNewsListModel extends LoadableDetachableModel {
 @SpringBean
 private NewsService   newsService;
 
 public NewsService getNewsService() {
 return newsService;
 }
 
 @SuppressWarnings(unchecked)
 @Override
 protected Object load() {
 return new LinkedList( getNewsService().getGlobalNews(  
 Session.get().getLocale().getLanguage(),
 10 ) );
 }
 }


throws NPE. Not much space for eror, is it? The only thing I can think 
of is that you are using nested classes or anonymous classes (which you 
should not do for models - so I've read).


-- 
Leszek Gawron

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-03 Thread igor.vaynberg

you missed this:

  public SomeModel() {
InjectorHolder.getInjector().inject(this);
  }

-Igor


Leszek Gawron-2 wrote:
 
 Joni Freeman wrote:
 Yes, it works. I use it in many places.
 
 Joni
 I have just checked:
 
 public class GlobalNewsListModel extends LoadableDetachableModel {
 @SpringBean
 private NewsService   newsService;
 
 public NewsService getNewsService() {
 return newsService;
 }
 
 @SuppressWarnings(unchecked)
 @Override
 protected Object load() {
 return new LinkedList( getNewsService().getGlobalNews( 
 Session.get().getLocale().getLanguage(),
 10 ) );
 }
 }
 
 
 throws NPE. Not much space for eror, is it? The only thing I can think 
 of is that you are using nested classes or anonymous classes (which you 
 should not do for models - so I've read).
 
 
 -- 
 Leszek Gawron
 
 -
 Take Surveys. Earn Cash. Influence the Future of IT
 Join SourceForge.net's Techsay panel and you'll get the chance to share
 your
 opinions on IT  business topics through brief surveys -- and earn cash
 http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
 ___
 Wicket-user mailing list
 Wicket-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/wicket-user
 
 

-- 
View this message in context: 
http://www.nabble.com/-tutorial--Wicket-%2B-Spring-integration---revisited-tf2375652.html#a6622516
Sent from the Wicket - User mailing list archive at Nabble.com.


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-03 Thread Leszek Gawron
igor.vaynberg wrote:
 you missed this:
 
   public SomeModel() {
 InjectorHolder.getInjector().inject(this);
   }
 
hmmm .. another thread local/singleton ... nice :)

-- 
Leszek Gawron, IT Manager  MobileBox sp. z o.o.
+48 (61) 855 06 67  http://www.mobilebox.pl
mobile: +48 (501) 720 812   fax: +48 (61) 853 29 65

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user


Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-03 Thread igor.vaynberg

this is nice.

what i do like about it
* you can inject anything anywhere

what i dont like is
* post constructor injection like youve mentioned - delegate or not it still
sucks, a different pointcut is needed
* you have to keep your variables transient - very easy mistake to make,
otherwise big boo boo might happen if the dependency is serializable and you
wont know until much later
* you have to inject everything - ie i cant take an instance of injected
service and pass it to some other component to use
* i dont like @Configure on the entire object, i like per-field annotations
on the fields
* you have to have access to the java runtime args to install the weaver

what is needed to fix this
* a different aspect that wraps the bean in the wicket-proxy just like we do
now - that should give you the ultimate freedom, but then what worries me is
if tomcat will let you cluster objects loaded through aspectj classloader.

-Igor



Leszek Gawron-2 wrote:
 
 Hello,
 I just wanted to share another way of injecting spring services into 
 wicket code. This one uses AOP.
 
 - o - Why another approach? - o -
 
 Using wicket-spring along with wicket-spring-annot works nicely for 
 components (althought you have to remember not initializing it yourself) 
 but does not work for other parts of application - models. Just ask your 
 self how many times you have put a spring service into wicket page only 
 to pass it to model constructed:
 
 public class RankingPanel extends Panel {
 @SpringBean
 private LeagueService leagueService;
 
 public RankingPanel( String id, IModel leagueModel ) {
 super( id );
 add( new ListView( ranking, new RankingModel( leagueService,
 leagueModel ) ) {
 @Override
 protected void populateItem( ListItem listItem ) {
 PlayerRank rank = (PlayerRank) listItem.getModelObject();
 listItem.add( new Label( position, String.valueOf(
 rank.getPosition() ) ) );
 listItem.add( new Label( player,
 rank.getPlayer().getFullName() ) );
 }
 } );
 }
 }
 
 If you could have your model injected with appropriate service this 
 would probably be:
 
 public class RankingPanel extends Panel {
 public RankingPanel( String id, IModel leagueModel ) {
 super( id );
 add( new ListView( ranking, new RankingModel( leagueModel ) ) {
 @Override
 protected void populateItem( ListItem listItem ) {
 PlayerRank rank = (PlayerRank) listItem.getModelObject();
 listItem.add( new Label( position, String.valueOf(
 rank.getPosition() ) ) );
 listItem.add( new Label( player,
 rank.getPlayer().getFullName() ) );
 }
 } );
 }
 }
 
 - o - What you'll need - o -
 
 - your current fancy project
 - one fresh spring (at least 2.0 M1). I have used 2.0-rc2.
 - one ripe aspectj (http://ibiblio.org/maven2/aspectj/) especially
aspectjrt and aspectjweaver. I have used 1.5.2.
 - java 1.5 (there are probably some ways to do it with 1.4 - didn't 
 bother to try)
 
 - o - Implementation - o -
 
 Spring 2.0 M1 introduced @Configurable annotation [1]. We can use it to 
 inject spring beans into ANY object (not only created by spring but also 
 simply instantiated with new MyObject() ).
 
 Let's create a simple spring context:
 
 ?xml version=1.0 encoding=UTF-8?
 beans xmlns=http://www.springframework.org/schema/beans;
 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
 xmlns:aop=http://www.springframework.org/schema/aop;
 xmlns:tx=http://www.springframework.org/schema/tx;
 xsi:schemaLocation=
 http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop.xsd;
 bean
 class=org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor/
 
 aop:spring-configured/
 
 bean id=leagueService
 class=com.mobilebox.squasher.service.impl.LeagueServiceImpl
 autowire=byName/
 /beans
 
 We have a single service declared here. What's more important is 
 aop:spring-configured/ which simply saying turns on Spring AspectJ 
 machinery. Please refer to [1] for additional info.
 
 Now let's build a wicket model:
 
 @Configurable(autowire = Autowire.BY_NAME, dependencyCheck = true)
 public class RankingModel extends LoadableDetachableModel {
 protected transient LeagueService   leagueService;
 
 public void setLeagueService( LeagueService leagueService ) {
 this.leagueService = leagueService;
 }
 
 public RankingModel( IModel master ) {
 this.master = master;
 }
 
 @SuppressWarnings(unchecked)
 @Override
 protected Object load() {
 return new 

Re: [Wicket-user] [tutorial] Wicket + Spring integration - revisited

2006-10-03 Thread igor.vaynberg

in life, but especially in programming, you cant have something for nothing
:)

-Igor


Leszek Gawron wrote:
 
 igor.vaynberg wrote:
 you missed this:
 
   public SomeModel() {
 InjectorHolder.getInjector().inject(this);
   }
 
 hmmm .. another thread local/singleton ... nice :)
 
 -- 
 Leszek Gawron, IT Manager  MobileBox sp. z o.o.
 +48 (61) 855 06 67  http://www.mobilebox.pl
 mobile: +48 (501) 720 812   fax: +48 (61) 853 29 65
 
 -
 Take Surveys. Earn Cash. Influence the Future of IT
 Join SourceForge.net's Techsay panel and you'll get the chance to share
 your
 opinions on IT  business topics through brief surveys -- and earn cash
 http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
 ___
 Wicket-user mailing list
 Wicket-user@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/wicket-user
 
 

-- 
View this message in context: 
http://www.nabble.com/-tutorial--Wicket-%2B-Spring-integration---revisited-tf2375652.html#a6622712
Sent from the Wicket - User mailing list archive at Nabble.com.


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user