问题
I have recently upgraded to using Oracles new JSF-2.3 which involved adding the dependency as an external library in my pom.xml as I am using maven, As opposed to previously using WebSphere Application server's (WAS) inbuilt JSF-2.2 feature. I wanted to upgrade to make use of the new f:websocket feature which allows me to push messages from server to client for some clever asynchronous page loading.
But before we get into that, once I upgraded, I noticed that my @ManagedBean annotations were deprecated. After some quick googling I found I should be using CDI annotations like @Named etc. which led me to my JSF-2.3 not finding my @Named CDI-1.2 managed bean question, from which I learnt that I could not use an external JSF library with WAS's inbuilt CDI-1.2 feature together.
My issue is, according to the JSF-2.3 spec on the server side I need to inject a "PushContext" into a variable on my managed bean using the CDI @Inject annotation like so:
@Inject @Push(channel="foo")
private PushContext bar;
I have been unable to find a JSF equivalent annotation to @Inject which works to inject an instance into my PushContext variable and have tried @ManagedProperty for example. So I need to get an implementation of CDI working with JSF 2.3 to make this work.
Things I have tried:
- I have tried using inbuilt CDI feature in WAS with the code shown in my above mentioned question.
- I have tried not using the default CDI feature, and adding a CDI-1.2 dependency in my pom.xml (so adding CDI as an external library) which also didn't work
- Have also tried only adding the Javax.inject library since all I needed the @Inject annotation as a dependency instead of CDI which also didn't work (was worth a try)
I am lost as to how I am supposed to make use of the new JSF-2.3 features in WAS if I can't get an implementation of CDI working with a custom JSF library, surely I am missing something...
I have also heard of something called "cdi-enablers" can these help me ? are they legit ? or just some hacks someone put together to make something work ?
help !!!
回答1:
After much research and forum trawling, I have concluded that getting JSF-2.3 and CDI-1.2 working together to make use of the f:websocket feature in WAS is near impossible. See my post on IBM support page which confirms this.
A way to still make use of web sockets using JSF-2.2 is to use the Javax.websocket package as @Gas pointed out in my previous question. However the limitation of this web socket implementation is that it is nowhere near as easy to send data contained in a SessionScoped ManagedBean to the client of that session only as it would have been using f:websocket from JSF-2.3 as I would have liked to do.
来源:https://stackoverflow.com/questions/44109997/implementing-jsf-2-3-and-cdi-together-in-websphere-application-server