Re: Issue with injection in ActionListener JSF Artifact

2017-08-15 Thread Eduardo B
When we register an ActionListener or PhaseListener globally via
faces-config.xml, the instance that is created per listener is injectable,
that is, we can do @Inject in the instance. These listeners are added to
the injected bean storage list in the application map and as a result, we
can call @PreDestroy and @PostConstruct on this scenario.

On the other hand, when facelet elements  and
 are used, the instances that are created (per click for
action listener or per view for phase listener) are not injectable. That
is, we cannot do @Inject inside of these objects. And @PreDestroy and
@PostConstruct are not invoked on them.

I supposes we want to have the same behavior in both cases.

To solve this issue, we can probably do a similar logic as what was done in
FacesConfigurator that we call inject on the instance, and then store that
in the injected bean storage list. We can add that logic in the
ActionListenerHandler and PhaseListenerHandler classes after the instance
is created.


// Code snippet

instance = (ActionListener) ReflectionUtil.forName(this.type).newInstance();

ExternalContext externalContext = faces.getExternalContext();

// Note that we have to make INJECTED_BEAN_STORAGE_KEY public

List injectedBeanStorage =
(List)externalContext.getApplicationMap()


.get(FacesConfigurator.INJECTED_BEAN_STORAGE_KEY);

InjectionProvider injectionProvider =
InjectionProviderFactory.getInjectionProviderFactory(


externalContext).getInjectionProvider(externalContext);

Object creationMetaData = injectionProvider.inject(instance);

injectedBeanStorage.add(new BeanEntry(instance, creationMetaData));

injectionProvider.postConstruct(instance, creationMetaData);


But there is an issue when adding that. Every time we use
 with type defined but no binding, a new instance is
created on every button click, the same will happen with
. These instances are added to the list of injected bean
storage, and that reference will exist until app shuts down, creating a *memory
leak*. So we need a way to remove those references from the list once we
are out of scope. We might need a different list for this case. Any
comments will be appreciated.

On Fri, Aug 11, 2017 at 5:19 PM, Eduardo B  wrote:

> In the specs, section 5.4.1 talks about the JSF Artifacts that are
> eligible for Injection.
>
> I tried testing it on Mojarra but couldn't get it to work. I couldn't even
> get to work other JSF Artifacts on Mojarra, so I'm not sure if they support
> all the objects specified in section 5.4.1 or if I'm missing some kind of
> configuration.
>
> On Fri, Aug 11, 2017 at 4:57 PM, Thomas Andraschko <
> andraschko.tho...@gmail.com> wrote:
>
>> Not sure.
>> Does it work in Mojarra or did you check the specs?
>>
>> 2017-08-11 22:44 GMT+02:00 Eduardo B :
>>
>>> I have encountered an issue with injection on a JSF Artifact. The
>>> scenario is as follows:
>>>
>>> When a class implements ActionListener, and that action listener is
>>> invoked from a facelet as the snippet below:
>>>
>>> 
>>>
>>> 
>>>
>>> >> />
>>>
>>> 
>>>
>>> 
>>>
>>> The behavior I’m seeing is that we cannot do @Inject on the class that
>>> implements the ActionListener, and @PreDestroy is not being invoked on app
>>> shut down. However, if we register the action listener in the
>>> faces-config.xml, I can see that injection is possible.
>>>
>>> Is Injection from a facelet for an ActionListener needs to be supported?
>>>
>>>
>>> Regards,
>>>
>>> Eduardo M. Breijo-Baullosa
>>>
>>
>>
>


Re: Issue with injection in ActionListener JSF Artifact

2017-08-11 Thread Eduardo B
In the specs, section 5.4.1 talks about the JSF Artifacts that are eligible
for Injection.

I tried testing it on Mojarra but couldn't get it to work. I couldn't even
get to work other JSF Artifacts on Mojarra, so I'm not sure if they support
all the objects specified in section 5.4.1 or if I'm missing some kind of
configuration.

On Fri, Aug 11, 2017 at 4:57 PM, Thomas Andraschko <
andraschko.tho...@gmail.com> wrote:

> Not sure.
> Does it work in Mojarra or did you check the specs?
>
> 2017-08-11 22:44 GMT+02:00 Eduardo B :
>
>> I have encountered an issue with injection on a JSF Artifact. The
>> scenario is as follows:
>>
>> When a class implements ActionListener, and that action listener is
>> invoked from a facelet as the snippet below:
>>
>> 
>>
>> 
>>
>> > />
>>
>> 
>>
>> 
>>
>> The behavior I’m seeing is that we cannot do @Inject on the class that
>> implements the ActionListener, and @PreDestroy is not being invoked on app
>> shut down. However, if we register the action listener in the
>> faces-config.xml, I can see that injection is possible.
>>
>> Is Injection from a facelet for an ActionListener needs to be supported?
>>
>>
>> Regards,
>>
>> Eduardo M. Breijo-Baullosa
>>
>
>


Re: Issue with injection in ActionListener JSF Artifact

2017-08-11 Thread Thomas Andraschko
Not sure.
Does it work in Mojarra or did you check the specs?

2017-08-11 22:44 GMT+02:00 Eduardo B :

> I have encountered an issue with injection on a JSF Artifact. The scenario
> is as follows:
>
> When a class implements ActionListener, and that action listener is
> invoked from a facelet as the snippet below:
>
> 
>
> 
>
>  />
>
> 
>
> 
>
> The behavior I’m seeing is that we cannot do @Inject on the class that
> implements the ActionListener, and @PreDestroy is not being invoked on app
> shut down. However, if we register the action listener in the
> faces-config.xml, I can see that injection is possible.
>
> Is Injection from a facelet for an ActionListener needs to be supported?
>
>
> Regards,
>
> Eduardo M. Breijo-Baullosa
>


Issue with injection in ActionListener JSF Artifact

2017-08-11 Thread Eduardo B
I have encountered an issue with injection on a JSF Artifact. The scenario
is as follows:

When a class implements ActionListener, and that action listener is invoked
from a facelet as the snippet below:











The behavior I’m seeing is that we cannot do @Inject on the class that
implements the ActionListener, and @PreDestroy is not being invoked on app
shut down. However, if we register the action listener in the
faces-config.xml, I can see that injection is possible.

Is Injection from a facelet for an ActionListener needs to be supported?


Regards,

Eduardo M. Breijo-Baullosa