How to get EL 2.2 working on WAS 7 (with Myfaces and Primefaces)? - jsf-2

I'm migrating a JSF 1.2 project, running in WAS7, to JSF2 with Myfaces 2.1.7 and Primefaces.
Until now, everything was more or less working, putting myfaces-bundle-2.1.7.jar and primefaces 3.3.RC1.jar in the WEB-INF/lib and changing to classloading order.
Now, I'm trying to get EL2.2 working :
Are the corresponding classes part of the Myfaces Impl classes (in myfaces-bundle-2.1.7.jar, but with which specific configuration ?), or did I miss some specific library to add to the /WEB-INF/lib ?
Thanks for reading me ;)

EL 2.2 is not part of JSF 2.0. It's part of Servlet 3.0 which in turn is part of Java EE 6. But WebSphere 7 is a Java EE 5 container, not a Java EE 6 one. JSF 2.0 is part of Java EE 6 but backwards compatible with Servlet 2.5 / Java EE 5, that's probably where your confusion is coming from.
As said, WebSphere 7 is a Servlet 2.5 container and thus doesn't ship with EL 2.2, but with EL 2.1. Your best bet is to install an EL 2.1 implementation which supports the same enhancements (invoking methods with arguments) as in EL 2.2. There's only one: JBoss EL. To install it, just drop jboss-el.jar in webapp's /WEB-INF/lib and add the following context parameter to your web.xml to tell MyFaces to use it instead.
<context-param>
<param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
<param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>

Related

Migrate JSF managed beans to CDI managed beans

I'm planning to convert a web app from using JSF managed bean to using CDI managed beans. I know I'll need to do below:
Add a empty beans.xml file in WEB-INF.
Replace all JSF #ManagedBean to CDI #Named annotations.
Replace all JSF scope annotations with CDI or OmniFaces scope annotations.
Replace all JSF #ManagedProperty with CDI #Inject annotations.
Is that all that needs to be done? Are there any gotchas that I need to be aware of?
Basically, that's indeed all you need to do provided that you're on a Java EE server already. When on Tomcat, you'd need to manually install CDI first. Instructions for both Weld and OpenWebBeans are detailed in the blog How to install CDI in Tomcat?
The below gotchas need to be taken care of:
While OmniFaces 2.x "officially" requires JSF 2.2, OmniFaces 2.0/2.1 is technically backwards compatible with JSF 2.1 and should in TomEE's case work on TomEE 1.x with JSF 2.1 as well, but OmniFaces 2.2 has a hard JSF 2.2 dependency (due to the new <o:viewAction> tag) and won't deploy on TomEE 1.x without upgrading its MyFaces JSF implementation to a 2.2 compatible version, or itself being upgraded to TomEE 7.x. See also OmniFaces Compatibility Matrix.
When you deploy an EAR with multiple WARs with each its own OmniFaces library, then generally all CDI functionality will work in only one WAR as the CDI context of a WAR-provided library is incorrectly interpreted as EAR-wide. This is an oversight in CDI spec and yet to be fixed in a future CDI version. See also OmniFaces Known Issues (CDI).
When you want to use OmniFaces-provided CDI injection support in #FacesConverter or #FacesValidator, and you're going to create/use a CDI 1.1 compatible beans.xml (and thus not a CDI 1.0 compatible one or an empty one), then you need to make sure that you have explicitly set bean-discovery-mode="all" in beans.xml. See also #FacesConverter showcase.
When replacing #ManagedBean(eager=true), be aware that standard CDI has no direct equivalent for this. You would use #Observes for this. OmniFaces offers #Eager annotation for the purpose. See also How to configure a start up managed bean?
When replacing #ManagedProperty in JSF 2.0/2.1/2.2, be aware that you can't inject #{param.xxx}, #{cookie.xxx} and #{initParam.xxx} directly via #Inject alone, while that was just possible via #ManagedProperty. OmniFaces offers respectively #Param, #Cookie and #ContextParam for the purpose. Only in JSF 2.3 there's a new #javax.faces.annotation.ManagedProperty annotation which can be used exactly the same way as original #javax.faces.bean.ManagedProperty which got deprecated since JSF 2.3.

MyFaces 2.1.16 and WebSphere 7 [duplicate]

This question already has answers here:
Can JSF 2.0 be used with Websphere application server version 7.x
(8 answers)
Closed 8 years ago.
I'm working with the following:
IBM WebSphere 7.0.0.33
Apache MyFaces 2.1.16
Java 1.6
Servlet Container 2.5
Just trying to get a simple Application going and getting errors.
I read here JSF2.0 and WAS7 about WAS7 configuration for MyFaces (It's for JSF2.0), but that did not help so far.
I'm trying to figure out now if WAS7 even supports JSF2.1 .
MyFaces says that Servelt Container of 2.5 is ok MyFaces2.1, but on some other page here it was posted that JSF needs 3.0 (which is not available with WAS7).
So, which one is correct?
Should I be able to run JSF2.1 with WAS7 ?
Thanks
No, WAS 7 doesn't support JSF 2.1, not even WAS 8, not sure regarding WAS 8.5
However, you can define custom JSF implementation, look at this answer : Can JSF 2.0 be used with Websphere application server version 7.x

Upgrading Omnifaces - duplicates validator ID

I have a java ee 6 project bundled as ear-file that contains two web war-archive. Both using Omnifaces. Today I upgrade Omnifaces to the newest version 1.6. But now I cannot deploy anymore. I got the following exception:
java.lang.IllegalArgumentException: Registering validator 'class org.omnifaces.validator.RequiredCheckboxValidator' failed, duplicates validator ID 'omnifaces.RequiredCheckboxValidator' of other validator 'class org.omnifaces.validator.RequiredCheckboxValidator'.
at org.omnifaces.cdi.validator.ValidatorExtension.processValidators(ValidatorExtension.java:73)
...
My Envroiment:
JBoss AS 7.1.1/ Omnifaces 1.6/ JSF Mojarra 2.1.26/ Primefaces 3.5
THX in advance.
This bug has been fixed in 1.6.1. There's quite a story behind this bug, so I just wrote a blog on that: CDI behaved unexpectedly in EAR, so OmniFaces 1.6.1 released!
Summarized: CDI context isn't WAR-wide, but EAR-wide. As to the particular exception you faced, it's because there was only one CDI ValidatorExtension being loaded from one WAR which is then applied EAR-wide and thus processing all #FacesValidator classes from both WARs instead of the WAR where the CDI extension was being loaded from.
Note that this is not a problem in OmniFaces. This is a problem in the way how CDI works in EARs.

How to replace JSF 1.2 with JSF 2.0

I have an application, full application that made on JSF 1.2. Now we are adding module in it. Can i replace JSF 1.2 with JSF 2.0 ? Means only new module use JSF 2.0 and the remaining application become unaffected by the change? Means is JSF 2.0 is fully compatible with JSF 1.2. Like i open the project in netbeans and add JSF 2.0 jar in the project and remove the JSF 1.2 jar? Can i do that ? or i should have use JSF 1.2 for new module because application is made on JSF 1.2 ?
Thanks
There's a pretty good thread for that where they explain basic settings to more advanced settings to migrate from JSF 1.2 to JSF 2.0

EJB3.0 #EJB annotation in Managed Bean JSF2 Websphere 7 impossible?

The websphere 7 only supports Java EE 5, but JSF2 is contained in Java EE 6, is there any tricks to implement #EJB annotation in ManagedBean?
The #EJB annotation is part of EJB 3.0 which is part of Java EE 5. It is not part of JSF 2.0 nor Java EE 6. It should work just fine on JSF 1.x managed beans in a Java EE 5 environment. The only difference with JSF 2.x managed beans in Java EE 6 is that you can't annotate JSF managed beans with #ManagedBean, but have to register them in faces-config.xml. That shouldn't make difference for the #EJB annotation.
JSF2 can be in Java EE 5 as well. The reason why annotations do not work is about Websphere. See the following link for details: http://www.java.net/node/701374#comment-813807
This issue seems to be fixed in Websphere 7.0.0.19 :
http://wasbehindtheglass.blogspot.co.uk/

Resources