Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can MyFaces + CDI be used on WebLogic 12c?

I've been trying to get this setup running for a couple of days now but still no luck. Here's the test application i've been using:

@Named
@RequestScoped
public class Test {

    private String test = "test";
    public String getTest() { return test; }
    public void setTest(String test) { this.test = test; }
}

And in the jsf page:

<h:outputText value="#{test.test}"/>

Running this sample without MyFaces works fine (renders "test" like it should), but when i deploy MyFaces in the WAR file and do the necessary configuration within weblogic.xml CDI seems to stop working (or at least, the integration bewteen JSF and CDI) and nothing is displayed in the output html. MyFaces itself seems to be ok, though.

My basic configuration is as follows:

  • WebLogic Server 12c (12.1.1.0), patches should be up-to-date as i just downloaded a development version yesterday just to be sure
  • MyFaces-2.1.10, deployed within WEB-INF/libs
  • Beans.xml is in place
  • org.apache.myfaces.webapp.StartupServletContextListener has been registered in web.xml
  • WebLogic is configured to use MyFaces using weblogic.xml

Weblogic.xml contents:

<prefer-application-packages>
    <package-name>javax.faces.*</package-name>
    <package-name>com.sun.faces.*</package-name>
    <package-name>com.bea.faces.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
    <resource-name>javax.faces.*</resource-name>
    <resource-name>com.sun.faces.*</resource-name>
    <resource-name>com.bea.faces.*</resource-name>
    <resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
    <resource-name>META-INF/services/com.sun.faces.spi.FacesConfigResourceProvider</resource-name>
</prefer-application-resources>

What i've learned so far:

  • WL12c is equipped with Weld 1.1.3 as it's CDI implementation.
  • I read somewhere (can't remember where) that whenever you decide to switch JSF implementation you're responsible for integrating JSF/CDI yourself. Is this true (sure hope not)?

Things i've tried so far:

  • Add MyFaces CODI into the mix, hoping it would somehow glue Weld and MyFaces together, but it didn't.
  • Replace Weld by OpenWebBeans as the CDI implementation. This seemed to work at first but gave all kinds of interesting ClassCastExceptions later on in some internal sun.reflection package. This is a solution i'd rather avoid anyway.
  • Manually trigger Weld using various options in web.xml and faces-config.xml. This seems to get Weld going in that it floods the log with all kinds of error messages. To some degree these can be "fixed" by upgrading weblogic to a newer Weld version but each time i do this i bump into the next error. Again, i'd rather avoid this route also.

Is it really that hard to use MyFaces on WL12c while preserving CDI support or am i just missing the obvious ? Thanks for any help.

like image 641
Sjoerd van Kreel Avatar asked Mar 30 '13 17:03

Sjoerd van Kreel


2 Answers

There are quite a few things which are not clear in your example. E.g. what package is the @RequestScoped from? Is it the javax.enterprise.context.RequestScoped (should work) or the javax.faces.bean.RequestScoped (will not work)? If you are using CDI beans only (and no javax.faces.bean stuff) then the only way the JSF container and the CDI container integrate with each other is actually the Unified Expression Language javax.el.ELResolver. And this must work out of the box.

org.apache.myfaces.webapp.StartupServletContextListener is not really needed imo. All you need is to set the FacesServlet.

The problematic spot might be that the JSF EG got forced to use the ServletContainerInitializer [1] to blindly activate the JSF impl, even if the app does not use JSF at all. This is hard to get around as the servlet-3.0 spec only defines how to automatically activate those features but there is NO way to disable them again.

[1] http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContainerInitializer.html

like image 182
struberg Avatar answered Oct 11 '22 14:10

struberg


I'm afraid there is no way to do it. The weld glue code needs to be there. Those tiny little integration layer that is part of the wls deployable libraries for jsf isn't available for myfaces ....

like image 30
Markus Eisele Avatar answered Oct 11 '22 13:10

Markus Eisele