Hi All,

The problem is :  I got a NullPointerException after using @Inject 
environment : wicket 1.6 snapshot - cdi (weld) - inject - NullPointerException 
- tomcat 7 / jboss AS 7

module 1 : bookstoreservice  (with a beans.xml file)
module 2 : bookstoreweb  (with a beans.xml file)

in the bookstoreservice module I have these 2 classes:

@ApplicationScoped
public class Clock {
    public DateTime getTime() {
        return new DateTime().now();
    }
}

@ApplicationScoped
public class BigBenClock {

    @Inject
    Clock clock;

    public BigBenClock() {
    }

    public DateTime getBigBenTime() {
        return clock.getTime().plusHours(2);
    }
}



First use : All works fine

In a webpage, I have 

    @Inject
    Clock clock;

    @Inject
    BigBenClock bigBenClock;

    add(new Label("time", new PropertyModel(this, "clock.time")));
    add(new Label("bigBenTime", new PropertyModel(this, 
"bigBenClock.bigBenTime")));

All works fine, thanks to Igor's example 
https://www.42lines.net/2011/11/15/integrating-cdi-into-wicket/


Second use : NullPointerException

If I use the injection in the bookstoreservice module with no injection in the 
webpage like this


    @Inject
    Clock clock;

    add(new Label("time", new PropertyModel(this, "clock.time")));

    BigBenClock bigBenClock = new BigBenClock();
    DateTime bigBenTime = bigBenClock.getBigBenTime();

I get a NullPointerException.  The BigBenClock's clok is null.
Same result in Tomcat 7 and Jboss AS7.
        

This is how I start the Wicket application

getComponentInstantiationListeners().add(new JavaEEComponentInjector(this, new 
ModuleJndiNamingStrategy()));
BeanManager beanManager = (BeanManager)getServletContext().getAttribute(  
Listener.BEAN_MANAGER_ATTRIBUTE_NAME);
new 
CdiConfiguration(beanManager).setPropagation(ConversationPropagation.NONE).configure(this);


Any advice ?

Thanks

François
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to