joinfaces icon indicating copy to clipboard operation
joinfaces copied to clipboard

No qualifying bean of type 'javax.faces.push.PushContext' available

Open nils-christian opened this issue 6 years ago • 12 comments

Hi,

We are using Joinfaces 4.0.5 with MyFaces 2.3.3. Since 2.3, JSF allows the usage of Websockets. Those can (according to Joinfaces documentation) be enabled with joinfaces.jsf.enable-websocket-endpoint=true If I add a controller bean with the following content, the error message from the title occurs.

@Named
@ViewScoped
public class Controller {

	private PushContext pushContext;

	@Inject
	public Controller( @Push final PushContext pushContext ) {
		this.pushContext = pushContext;
	}

       ...

}

Once enabled, the AbstractFacesInitializer creates the Websocket, but it seems that there is no implementation of the PushContext available in the Spring context. It seems to me that usually the PushContextFactoryBean is responsible to create the contexts, but in Joinfaces the factory is not active. I would assume that some similar (Spring) bean factory is required.

I can as always share a minimal example if you need it.

Best regards

Nils

nils-christian avatar Jun 03 '19 17:06 nils-christian

Hi,

I tried to create the push context via Spring:

@Bean
@Push
@Scope ( ConfigurableBeanFactory.SCOPE_PROTOTYPE )
public PushContext pushContext( final InjectionPoint ip ) {
	final Push push = ip.getAnnotation( Push.class );
	final String channel = push.channel( ).isEmpty( ) ? ip.getMember( ).getName( ) : push.channel( );
	return new PushContextImpl( channel );
}

However, this is not sufficient - the WebsocketComponentRenderer throws a NPE while trying to access further beans from the uninitialized CDI-Utils.

nils-christian avatar Jun 03 '19 17:06 nils-christian

The PushContext implementations of both MyFaces and Mojarra heavily depend on CDI.

larsgrefer avatar Jun 15 '19 23:06 larsgrefer

Hi @larsgrefer,

it's not possible to register the missing beans in Spring?

Kind regards Oliver

OLibutzki avatar Jun 17 '19 05:06 OLibutzki

org.apache.myfaces.push.cdi.PushContextImpl itself heavily depends on CDI.

larsgrefer avatar Jun 17 '19 09:06 larsgrefer

Ok, I see :-(

OLibutzki avatar Jun 17 '19 10:06 OLibutzki

Hi everyone, in this case which alternatives are you using?

and considering that JSF is getting more and more dependent on CDI, do you think JoinFaces will be able to keep up?

SirError avatar Jul 03 '19 19:07 SirError

You could try If PushContext works when including org.joinfaces:weld-spring-boot-starter

larsgrefer avatar Jul 17 '19 12:07 larsgrefer

Including weld CDI does also not work. Any idea of how we can get PushContext working?

Tosken1337 avatar Feb 06 '20 12:02 Tosken1337

Because JSF 2.3 Websocket rely heavily on CDI you have to make your Controller instantied by your CDI container (e.g WELD) and not by Spring. I have been able to make it work by excluding my JSF controllers from the Spring component scan and having my PushContext injected properly. Note that you have now two CDI containers (Spring & WELD) working side by side with your JSF controllers managed by WELD and not Spring.

cdumarcey avatar Jul 06 '20 07:07 cdumarcey

@cdumarcey can you give some working example? tried to exclude my controller by defining fitlers in @ComponentScan annotation. But haven't succeed, it looks like it ignores it, and I get an exception about No qualifying bean of type 'javax.faces.push.PushContext'

Gwulior avatar Oct 12 '20 18:10 Gwulior

I also need to integrate Push notifications in my JoinFaces application, and get a No qualifying bean of type 'org.omnifaces.cdi.PushContext' error.

mossaab0 avatar Oct 12 '20 19:10 mossaab0

Is there any example on how to make this work . Please help

ManasaChitrashekar avatar Oct 04 '21 14:10 ManasaChitrashekar