0

ZK SpringBoot @WireVariable not working

asked 2021-09-26 21:16:47 +0800

franferri gravatar image franferri
48 2

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?

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2021-09-27 09:34:29 +0800

cor3000 gravatar image cor3000
6168 2 7
ZK Team

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().

https://github.com/zkoss/zk/blob/master/zkplus/src/org/zkoss/zkplus/spring/DelegatingVariableResolver.java#L97-L106

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.

link publish delete flag offensive edit
0

answered 2021-09-27 22:46:24 +0800

franferri gravatar image franferri
48 2

Worked, cor3000 you rock tons!

@Bean("RestTemplate")

and

@Component("ConfigProperties")

did the trick

link publish delete flag offensive edit

Comments

thanks for getting back!

cor3000 ( 2021-09-28 12:41: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

Follow
1 follower

RSS

Stats

Asked: 2021-09-26 21:16:47 +0800

Seen: 9 times

Last updated: Sep 27

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