ZK在Composer或者ViewModel外,不会自动注解Spring bean,所以要手工获取.如下:
@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class)
public class AuthenticationInit implements Initiator {
@WireVariable
AuthenticationService authService;
public void doInit(Page page, Map<String, Object> args) throws Exception {
//wire service manually by calling Selectors API
[color=red]Selectors.wireVariables(page, this, Selectors.newVariableResolvers(getClass(), null));[/color]
UserCredential cre = authService.getUserCredential();
if(cre==null || cre.isAnonymous()){
Executions.sendRedirect("/chapter8/login.zul");
return;
}
}
}
@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class)
public class AuthenticationInit implements Initiator {
@WireVariable
AuthenticationService authService;
public void doInit(Page page, Map<String, Object> args) throws Exception {
//wire service manually by calling Selectors API
[color=red]Selectors.wireVariables(page, this, Selectors.newVariableResolvers(getClass(), null));[/color]
UserCredential cre = authService.getUserCredential();
if(cre==null || cre.isAnonymous()){
Executions.sendRedirect("/chapter8/login.zul");
return;
}
}
}