0

How to user @Inject of CDI Beans in frontend layer

asked 2018-02-24 21:40:07 +0800

Ethernut gravatar image Ethernut
1 1

Hello everyone,

I am building my web application with CDI and I want to inject my CDI beans into the controller without using @WireVariable. Is that possible in ZK? Every thread that I have searched only deals with @WireVariable which I do not prefer at all.

Is there any way to link my ZK frontend layer with my business layer using @Inject ?

I appreciate any kind of help!

regards, Ethernut

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-02-26 15:03:21 +0800

chillworld gravatar image chillworld flag of Belgium
5367 4 9
https://github.com/chillw...

Yes it's possible, but not recommended.
Extend all your VM's from this :

package be.chillworld.web.common;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

/**
 *
 * @author chillworld */
public abstract class AbstractVM {

    public AbstractVM() {
        this.autowire(this);
    }

    protected final void autowire(Object object) {
        this.getApplicationContext().getAutowireCapableBeanFactory()
                .autowireBean(object);
        this.getApplicationContext().getAutowireCapableBeanFactory()
                .initializeBean(object, null);
    }

    /**
     * Gets the application context.
     *
     * @return the application context
     */
    protected final ApplicationContext getApplicationContext() {
        return WebApplicationContextUtils
                .getRequiredWebApplicationContext(Executions.getCurrent()
                        .getDesktop().getWebApp().getServletContext());
    }
}

Chill.

link publish delete flag offensive 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
2 followers

RSS

Stats

Asked: 2018-02-24 21:40:07 +0800

Seen: 10 times

Last updated: Feb 26 '18

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