ZK Spring 3.1.1 MVVM Use @Scope/@Component or No?

asked 2013-03-19 05:02:12 +0800

rickcr gravatar image rickcr
704 7

updated 2013-03-19 13:36:49 +0800

Trying to follow the documentation and small talks on spring http://www.zkoss.org/documentation/zkspring is a bit confusing since different approaches seem to be taken.

Currently, I'm defining my ViewModels and injecting resources like so (since somewhere I saw this approach used):

 public class MyViewModel {

     private SomeService someService;

In my ZUL I bind to this ViewModel...

<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
<div id="foo"  apply="org.zkoss.bind.BindComposer"   
    viewModel="@id('vm') @init(myVM)">

Is this an OK approach to take or should I not be declaring my ViewModels as Spring managed components and instead do...

      public class MyViewModel {

          private SomeService someService;

(ZUL would then use the full class name)

What is the preferred approach? Also, if the first approach is valid, is prototype scope ok or should I maybe be using Desktop scope?


Follow up: per the developer Doc (not the Spring docs which is why there is confusion) they recommend the first approach, but the developer doc also mentions, annotating your Service classes that are to be wired in your view models with

 public class MyServiceImpl implements MyService {

I understand the rationale for this if you were going to hold some state in that bean, but if you are SURE your Service class is going to act only as a singleton, can we leave that off? ViewModels won't be living longer than your singleton service classes so I'd think this would be ok? (Obviously for any beans you want to inject with prototype scope, the proxyMode=ScopedProxyMode.TARGET_CLASS make sense.) Most of my Service classes are simply data access services that hold no state.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-03-19 06:40:01 +0800

rickcr gravatar image rickcr
704 7

updated 2013-03-19 14:46:19 +0800

[This comment was before EDIT above]

Hawk helped out in another post. Turns out it's described in detail in the developers guide (NOT the Spring guides found under the documentation section.) [ I'm sure others will get confused on the documentation structure.. my recommendation is to maybe just mention on the spring documentation page to see the standard developer's guide since it seems more detailed there. ]

Answer: Approach one is preferred.


link publish delete flag offensive edit


Another annoyance is it seems using zk-spring I now have to define my @Service with a qualifier (eg @Service("serviceName") when previously I was able to rely on Spring's defaults of finding only one @Service for an interface and it would inject that version properly. Any ideas why this is?

rickcr ( 2013-03-19 15:12:30 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

1 follower



Asked: 2013-03-19 05:02:12 +0800

Seen: 54 times

Last updated: Mar 19 '13

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More