-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'm using ZK SpringBoot, trying to have in the SelectorComposer the @Autowired stuff that I'm able to use in the SpringController.
https://www.zkoss.org/wiki/ZKDeveloper'sReference/MVC/Controller/Composer#WireSpring-managedbeans
This example don't work:
@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class)
public class UsersComposer extends SelectorComposer<Window> {
@WireVariable
private List<User> users;
public ListModel<User> getUsers() {
return new ListModelList<User>(users);
}
}
In my own code I'm using the following:
@VariableResolver(DelegatingVariableResolver.class)
public class PartialProductDetailsRead extends SelectorComposer<Grid> {
@WireVariable
private ConfigProperties configProperties;
@WireVariable
private RestTemplate restTemplate;
...
Then I'm calling the wired stuff on my:
@Override
public ComponentInfo doBeforeCompose(Page page, Component parent, ComponentInfo compInfo) {
System.out.println(configProperties.getHost());
...
configProperties is always null.
What I'm doing wrong?
Doesn't look wrong by itself and the question is: What does it do?
To verify ZK's variable resolver is doing what it's supposed to do you can simply place a breakpoint into DelegatingVariableResolver.resolveVariable()
.
ZK should call this method in order to resolve the variables "configProperties" and "restTemplate" (by Name - ZK doesn't try to wire by type). Then a few lines into debugging it should call Spring's applicationContext.getBean()
for a bean by that name.
https://github.com/zkoss/zk/blob/master/zkplus/src/org/zkoss/zkplus/spring/DelegatingVariableResolver.java#L162-L169 https://github.com/zkoss/zk/blob/master/zkplus/src/org/zkoss/zkplus/spring/SpringUtil.java#L54
If spring returns null - i.e. no spring bean exists by that name - then you know you need to configure the bean id/name or alias in your spring config to make it visible to ZK's WireVariable, or rename the variable accordingly in your SelectorComposer or specify the name @WireVariable("the_correct_bean_name")
. If it fails otherwise or doesn't get called at all, we might be able to help from the ZK side.
Asked: 2021-09-26 21:16:47 +0800
Seen: 14 times
Last updated: Sep 27 '21