ELResolver cannot handle a null base Object - Weblogic 10.3.x, Facelets 1.1.14, RichFaces 3.3.2

岁酱吖の 提交于 2019-12-25 04:47:04

问题


I'm having trouble using RichFaces 3.3.2 and Facelets 1.1.14 under Weblogic 10.3.4 and 10.3.5 (aka 11g). I have an xhtml file with the expression #{empty messages}, and on the console I get the following exception:

SEVERE: Error Rendering View[/index.xhtml]
javax.el.ELException: //media/DADOS/data/java/wl1034/user_projects/domains/wlrep1034/autodeploy/SimpleJSFa/index.xhtml:

  ELResolver cannot handle a null base Object with identifier 'messages'

    at com.sun.facelets.compiler.TextInstruction.write(TextInstruction.java:48)
    at com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39)
    at com.sun.facelets.compiler.UILeaf.encodeAll(UILeaf.java:149)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:889)
    at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
    at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
    at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:108)

The messages variable really does not exist at this point, but that's why I used an empty statement. It works fine on Tomcat 5.5 and Websphere 6.1.

The complete xhtml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:rich="http://richfaces.org/rich">

<body>

    <h1>Bean Message: #{TestBean.greeting}</h1>

    Are there messages pending? #{messages == null || empty messages} .

</body>
</html>

TestBean.java:

package eg.bean;

import java.util.ArrayList;
import java.util.List;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

public class TestBean {

    private String greeting = "Hello, World!";

    public TestBean() {
        // Uncommenting the following line puts an object in the session, under the
        // key "messages", and then the page displays properly.
        // addSomeMessages();
    }

    public String getGreeting() {
        return greeting;
    }

    public void setGreeting( String message ) {
        this.greeting = message;
    }

    public void addSomeMessages() {
        // This method is not being called for this example, but this is where
        // I would add a list of messages to be displayed to the user, and place it
        // on session scope (not advisable, I know, but bear with me)
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        List<String> messages = new ArrayList<String>();
        messages.add( "A message.");
        request.getSession().setAttribute( "messages", messages );
    }

}

I can only guess that somehow a different implementation of ELResolver is being used by Weblogic, which could be caused by classloader conflicts, but I've been fiddling with it for a while and am getting nowhere.

I have the following jars in WEB-INF/lib:

commons-beanutils-1.7.0.jar
commons-digester-1.8.jar
commons-logging-1.1.1.jar
jsf-api.jar
jsf-facelets.jar
jsf-impl.jar
richfaces-api-3.3.2.SR1.jar
richfaces-impl-3.3.2.SR1.jar
richfaces-ui-3.3.2.SR1.jar
SimpleJSF.jar

My faces-config.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xi="http://www.w3.org/2001/XInclude"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">

 <managed-bean>
  <managed-bean-name>TestBean</managed-bean-name>
  <managed-bean-class>eg.bean.TestBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
 </managed-bean>

 <application>
  <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
  <resource-bundle>
   <base-name>RepositoryBundle</base-name>
   <var>bundle</var>
  </resource-bundle>
 </application>
</faces-config>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

    <!-- Use Documents Saved as *.xhtml -->
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>

    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>

    <context-param>
      <param-name>com.sun.faces.disableVersionTracking</param-name>
      <param-value>true</param-value>
    </context-param>

    <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <param-name>facelets.LIBRARIES</param-name>
        <param-value>/WEB-INF/sense.taglib.xml</param-value>
    </context-param>

    <context-param>
        <param-name>com.sun.faces.validateXml</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
        <param-value>com.sensedia.repository.web.startup.SensediaFaceletViewHandler</param-value>
    </context-param>

    <context-param>
        <param-name>com.prime.facestrace.DISABLE_TRACE</param-name>
        <param-value>false</param-value>
    </context-param>

    <!-- ********************** SERVLETS ********************** -->

    <!-- Faces Servlet -->
    <servlet>
        <servlet-name>FacesServlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- ********************** FILTERS ********************** -->
    <filter>
        <filter-name>richfaces</filter-name>
        <filter-class>org.ajax4jsf.Filter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>richfaces</filter-name>
        <servlet-name>FacesServlet</servlet-name>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>

    <!-- Faces Servlet Mapping -->
    <servlet-mapping>
        <servlet-name>FacesServlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>

    <welcome-file-list>
        <welcome-file>index.jsf</welcome-file>
    </welcome-file-list>

</web-app>

EDIT: I was deploying as a standalone war file, but I also tried packaging as an EAR module. Problem persists. When deploying as an EAR file I added a weblogic.xml jar besides my own web.xml with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <container-descriptor>
        <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor>
</weblogic-web-app>

I also added an application.xml to the ear's META-INF directory, simply referencing the war module. I also added a weblogic-application.xml file besides that one, to further specify classloader isolation:

<weblogic-application xmlns="http://www.bea.com/ns/weblogic/90"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <application-param>
        <param-name>webapp.encoding.default</param-name>
        <param-value>UTF-8</param-value>
    </application-param>

    <prefer-application-packages>
        <package-name>org.mozilla.*</package-name>
        <package-name>javax.jws.*</package-name>
        <package-name>com.sun.*</package-name>
        <package-name>javax.xml.rpc.*</package-name>
        <package-name>javax.xml.soap.*</package-name>
    </prefer-application-packages>

</weblogic-application>

回答1:


Actually, the EL implementation is supposed to be provided by the container itself. A classpath conflict would only lead to class/method definition errors like LinkageError, NoClassDefFoundError, AbstractMethodError, etc. This is not the case here, but this indeed look much like a bug in Weblogic's EL implementation. Since I don't use WebLogic, I can't test/confirm this.

You could try to use the following expression instead

#{messages == null || empty messages}

Or you could try to totally replace the EL implementation, for example the JBoss one (which allows passing method arguments). Just drop jboss-el.jar in /WEB-INF/lib and add the following to the web.xml

<context-param>     
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>   
</context-param>



回答2:


It turns out to be a classloader issue after all. I had packaged the JSF 1.2 jars into my application's WEB-INF/lib folder:

jsf-api.jar
jsf-impl.jar

Weblogic 10.3.x has its own implementation, located in MW_HOME/wlserver/common/deployable-libraries/jsf-1.2.war (and the 2.0 version in jsf-2.0.war). I replaced the above jars in my own webapp with the following jars from jsf-1.2.war!/WEB-INF/lib:

glassfish.jsf_1.0.0.0_1-2-15.jar
glassfish.jstl_1.2.0.1.jar
javax.jsf_1.1.0.0_1-2.jar
wls.jsf.di.jar

I also had to remove all the packages in the prefer-application-packages element in weblogic.xml:

<!--
<prefer-application-packages>
    <package-name>org.mozilla.*</package-name>
    <package-name>javax.jws.*</package-name>
    <package-name>com.sun.*</package-name>
    <package-name>javax.xml.rpc.*</package-name>
    <package-name>javax.xml.soap.*</package-name>
</prefer-application-packages>
-->

After this, the page displayed correctly. (It did cause other problems, such as a ViewExpiredException on every page, but that's another problem, I think...)



来源:https://stackoverflow.com/questions/5950306/elresolver-cannot-handle-a-null-base-object-weblogic-10-3-x-facelets-1-1-14

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!