You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ondrej Zizka <oz...@redhat.com> on 2013/03/04 22:25:53 UTC

42lines CDI injection failure fallback - set to null?

Hi all,

I use the CDI integration.

    new 
CdiConfiguration(bm).setPropagation(ConversationPropagation.NONE).configure(this);

When the injection fails, it happens in <init>. Can I configure it to 
set the field to null,  as a NPE during page rendering is easier to 
handle than init exception?
I didn't find anything in the lib itself.

The stacktrace is:

      at org.jboss.weld.manager.SimpleInjectionTarget.inject(SimpleInjectionTarget.java:102)
      at net.ftlines.wicket.cdi.NonContextual.inject(NonContextual.java:141)
      at net.ftlines.wicket.cdi.NonContextualManager.inject(NonContextualManager.java:49)
      at net.ftlines.wicket.cdi.AbstractInjector.inject(AbstractInjector.java:38)
      at net.ftlines.wicket.cdi.ComponentInjector.onInstantiation(ComponentInjector.java:43)
      at org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:36)
      at org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:34)
      at org.apache.wicket.util.listener.ListenerCollection.notify(ListenerCollection.java:80)
      at org.apache.wicket.application.ComponentInstantiationListenerCollection.onInstantiation(ComponentInstantiationListenerCollection.java:32)
      at org.apache.wicket.Component.<init>(Component.java:679)


Thanks,
Ondra

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: 42lines CDI injection failure fallback - set to null?

Posted by Ondrej Zizka <oz...@redhat.com>.
For the future reference:

One can inject using

        @Inject Instance<MyBean> bean;

and then call

        bean.isUnsatisfied()

This wouldn't throw an exception and allow to check before use.

Ondra


On 03/05/2013 12:59 AM, Igor Vaynberg wrote:
> this is how cdi works, if it cannot inject something it fails. notice
> the top frame is inside weld not wicket nor wicket-cdi.
>
> if you have things that can be optional you should inject
> Instance<Thing> and query that for thing.
>
> -igor
>
> On Mon, Mar 4, 2013 at 1:25 PM, Ondrej Zizka <oz...@redhat.com> wrote:
>> Hi all,
>>
>> I use the CDI integration.
>>
>>     new
>> CdiConfiguration(bm).setPropagation(ConversationPropagation.NONE).configure(this);
>>
>> When the injection fails, it happens in <init>. Can I configure it to set
>> the field to null,  as a NPE during page rendering is easier to handle than
>> init exception?
>> I didn't find anything in the lib itself.
>>
>> The stacktrace is:
>>
>>       at
>> org.jboss.weld.manager.SimpleInjectionTarget.inject(SimpleInjectionTarget.java:102)
>>       at net.ftlines.wicket.cdi.NonContextual.inject(NonContextual.java:141)
>>       at
>> net.ftlines.wicket.cdi.NonContextualManager.inject(NonContextualManager.java:49)
>>       at
>> net.ftlines.wicket.cdi.AbstractInjector.inject(AbstractInjector.java:38)
>>       at
>> net.ftlines.wicket.cdi.ComponentInjector.onInstantiation(ComponentInjector.java:43)
>>       at
>> org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:36)
>>       at
>> org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:34)
>>       at
>> org.apache.wicket.util.listener.ListenerCollection.notify(ListenerCollection.java:80)
>>       at
>> org.apache.wicket.application.ComponentInstantiationListenerCollection.onInstantiation(ComponentInstantiationListenerCollection.java:32)
>>       at org.apache.wicket.Component.<init>(Component.java:679)
>>
>>
>> Thanks,
>> Ondra
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: 42lines CDI injection failure fallback - set to null?

Posted by Igor Vaynberg <ig...@gmail.com>.
this is how cdi works, if it cannot inject something it fails. notice
the top frame is inside weld not wicket nor wicket-cdi.

if you have things that can be optional you should inject
Instance<Thing> and query that for thing.

-igor

On Mon, Mar 4, 2013 at 1:25 PM, Ondrej Zizka <oz...@redhat.com> wrote:
> Hi all,
>
> I use the CDI integration.
>
>    new
> CdiConfiguration(bm).setPropagation(ConversationPropagation.NONE).configure(this);
>
> When the injection fails, it happens in <init>. Can I configure it to set
> the field to null,  as a NPE during page rendering is easier to handle than
> init exception?
> I didn't find anything in the lib itself.
>
> The stacktrace is:
>
>      at
> org.jboss.weld.manager.SimpleInjectionTarget.inject(SimpleInjectionTarget.java:102)
>      at net.ftlines.wicket.cdi.NonContextual.inject(NonContextual.java:141)
>      at
> net.ftlines.wicket.cdi.NonContextualManager.inject(NonContextualManager.java:49)
>      at
> net.ftlines.wicket.cdi.AbstractInjector.inject(AbstractInjector.java:38)
>      at
> net.ftlines.wicket.cdi.ComponentInjector.onInstantiation(ComponentInjector.java:43)
>      at
> org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:36)
>      at
> org.apache.wicket.application.ComponentInstantiationListenerCollection$1.notify(ComponentInstantiationListenerCollection.java:34)
>      at
> org.apache.wicket.util.listener.ListenerCollection.notify(ListenerCollection.java:80)
>      at
> org.apache.wicket.application.ComponentInstantiationListenerCollection.onInstantiation(ComponentInstantiationListenerCollection.java:32)
>      at org.apache.wicket.Component.<init>(Component.java:679)
>
>
> Thanks,
> Ondra
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org