ELResolver无法处理空基对象 - Weblogic 10.3.x,Facelets 1.1.14,RichFaces 3.3.2

时间:2011-05-10 12:52:58

标签: jsf richfaces weblogic facelets el

我在使用Weblogic 10.3.4和10.3.5(又名11g)下的RichFaces 3.3.2和Facelets 1.1.14时遇到了麻烦。我有一个带有表达式#{empty messages}的xhtml文件,在控制台上我得到以下异常:

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)

此时messages变量确实不存在,但这就是我使用empty语句的原因。它在Tomcat 5.5和Websphere 6.1上运行良好。

完整的xhtml文件:

<?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 );
    }

}

我只能猜测Weblogic正在使用不同的ELResolver实现,这可能是由类加载器冲突造成的,但我已经习惯了一段时间而且无处可去。

我在WEB-INF / lib中有以下jar:

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

我的faces-config.xml看起来像这样:

<?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>
编辑:我正在部署作为独立的war文件,但我也尝试将其打包为EAR模块。问题依然存在。在部署为EAR文件时,除了我自己的weblogic.xml之外,还添加了web.xml jar,其中包含以下内容:

<?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>

我还在耳朵的application.xml目录中添加了META-INF,只是引用了war模块。我还添加了一个weblogic-application.xml文件,以进一步指定类加载器隔离:

<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>

2 个答案:

答案 0 :(得分:0)

实际上,EL实现应该由容器本身提供。类路径冲突只会导致类/方法定义错误,如LinkageErrorNoClassDefFoundErrorAbstractMethodError等。这不是这种情况,但这确实看起来很像Weblogic中的错误EL实现。由于我不使用WebLogic,我无法测试/确认这一点。

您可以尝试使用以下表达式

#{messages == null || empty messages}

或者您可以尝试完全替换EL实现,例如JBoss一个(允许传递方法参数)。只需将jboss-el.jar放入/WEB-INF/lib,然后将以下内容添加到web.xml

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

答案 1 :(得分:0)

毕竟,事实证明这是一个类加载器问题。我已将JSF 1.2 jar打包到我的应用程序的WEB-INF / lib文件夹中:

jsf-api.jar
jsf-impl.jar

Weblogic 10.3.x有自己的实现,位于MW_HOME/wlserver/common/deployable-libraries/jsf-1.2.war(以及jsf-2.0.war中的2.0版本)。我用jsf-1.2.war!/WEB-INF/lib中的以下罐子替换了我自己的webapp中的上述罐子:

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

我还必须删除 prefer-application-packagesweblogic.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>
-->

此后,页面显示正确。 (它确实导致其他问题,例如每页上都有ViewExpiredException,但这是另一个问题,我认为......)