spring do the transaction aop ,so i set VM a component,there is nothing with binding,i cant get you
yaminglin1977 ( 2013-02-01 23:39:08 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
i try zk+spring+hibernate,i want to declare transactional method in VM, so the following code is written:
@Component
public class SomeViewModel {
@Command
public void cmd() {
save();
}
@Transactional
public void save(){
ใใใ//database operation
}
}
when it run ,it throw following exception :
org.zkoss.zk.ui.UiException: cannot find any method that is annotated for the command cmd with
@Command in org.lym.exam1.ctrl.SomeViewModel@1f1df3f
at org.zkoss.bind.impl.BinderImpl.doExecute(BinderImpl.java:1511)
please tell me how to realize the function of this?
Warning: Register a Composer (or ViewModel) as a Spring bean Many developers tend to register ZK's composer (or ViewModel) as a Spring-managed bean, but we do not recommend this approach because none of Spring's scopes matches correctly with the life cycle of the composers, please see ZK Developer's Reference/MVC/Controller/Wire Variables for more details. The scope of a composer is "desktop" scope that is shorter than "session" and longer than "prototype". Only ZK knows when to create composers (or ViewModel), so it's better to let composers be managed by ZK
You can read this link
And also, in my blog, there is an example on this subject. here is the link
Why do you want your vm to be a component?
If it is just for the @Transactional
just delete @Component
you don't need it.
If you want to access a method of your vm inside another calss use http://www.zkoss.org/javadoc/latest/zk/org/zkoss/bind/BindUtils.html (BindUtils.postGlobalCommand)
btw: A good http://www.ibm.com/developerworks/java/library/j-ts1/index.html (article) about transaction patterns
spring do the transaction aop ,so i set VM a component,there is nothing with binding,i cant get you
yaminglin1977 ( 2013-02-01 23:39:08 +0800 )editthank all,
the reason why i declare @transactional in VM is to avoid using 'open session in view' pattern which is is discussed in
http://stackoverflow.com/questions/1103363/why-is-hibernate-open-session-in-view-considered-a-bad-practice
, So if i invoke multiply service methods in a VM method without OSIV,I can't guantee these service methods is in single transaction. how to implement this goal without using 'open session in view' pattern?
I thought of two solution for my own question:
No 1: this multiply servcie methods are reconstructed into single service method,the disavantage is that service layer is influnced by present layer.
No 2: using Vistor Design Pattern to let service method visit VM's member,so i can declare transaction annotation on service method ,meanwhile declaring binding annotation on VM's method.
About this question, I very want to hear other people's advice besides the front advice .
Asked: 2013-01-29 03:18:56 +0800
Seen: 95 times
Last updated: Feb 01 '13
Zk + Spring Security redirect to strange page after login
ZK Spring webflow and flowScope
Spring security doesn't return user inside event listener
ZK Spring 3.1.1 MVVM Use @Scope/@Component or No?
Upgrading from Spring3.1 to 3.1.1 Maven.. pulls in 3.0.x jars... issues
When would I want to use ThreadLocalListener?
ZKoss with springsecurity using database
I will suggest you to wrap Transactional in service or dao bean, and them could be a spring bean
dennis ( 2013-01-29 06:43:38 +0800 )edit