ELResolver 无法处理空基本对象 - Weblogic 10.3.x、Facelet 1.1.14、RichFa



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

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 中有以下罐子:

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

我的脸配置.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>

网站.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>

编辑:我正在部署为独立的战争文件,但我也尝试打包为 EAR 模块。问题仍然存在。部署为 EAR 文件时,除了我自己的 web.xml 之外,我还添加了一个 weblogic.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>

我还在耳朵的META-INF目录中添加了一个application.xml,只是引用了 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>

实际上,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>
事实证明,

这毕竟是一个类加载器问题。我已经将 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版本)。我在我自己的 web 应用程序中用 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

我还必须删除 weblogic.xmlprefer-application-packages 元素中的所有包:

<!--
<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,但我认为这是另一个问题......

相关内容

  • 没有找到相关文章

最新更新