JSF复合组件中的日期转换异常

问题描述

| 当我从JSF访问JPA管理的日期值时,它返回一个javax.faces.component.UdateModelException
\'Cannot convert 01.01.10 00:00 of type class java.util.Date to class org.apache.openjpa.util.java$util$Date$proxy 
直接从EL使用时,使用JPA管理的日期值(表示已被代理)可以很好地工作:
\'<h:outputLabel value=\"MyDateValue\" for=\"input\"/> 
\'<h:inputText id=\"inputDate\" value=\"#{bean.myDate}\"/> 
但是,在尝试与复合组件一起使用时会引起麻烦   并返回以下转换器异常,因此无法更新模型... (简化的)JSF复合组件inputDate.xhtml  
    <head> 
            <title>A date input field</title> 
    </head> 

    <composite:interface> 
            <composite:attribute name=\"dateValue\"/> 
    </composite:interface> 

    <composite:implementation> 
            <h:outputLabel value=\"MyDateValue\" for=\"input\"/> 
            <h:inputText id=\"input\" value=\"#{cc.attrs.dateValue}\"/> 
    </composite:implementation> 
  假设: 从组合内部访问值时,似乎OpenJPA中的代理替换处理方式有所不同。我的猜测是,当EL解析器传递给复合对象时,它对对象值的调用处理方式会有所不同。将其传递给复合材料意味着首先在复合材料中对其进行访问,这为时已晚,并且无法完成所需的代理替换(因此转换器异常) 因此,我尝试更改MyFaces的表达语言,但是即使我将类加载更改为last parent,并从libfish文件夹中的glassfish提供了el-impl和el-api,并插入了必要的语言,它也无法在Websphere中使用MyFaces的上下文参数 你们如何在复合组件中使用JPA管理的日期(或其他代理实体)???     

解决方法

        如果您使用的是sun EL实施,则可以使用以下ELResolver来解决此问题:
public class BugfixELResolver extends ELResolver {
//...
@Override
public Class<?> getType(ELContext anElContext,Object aBase,Object aProperty) {
    if (aBase.getClass().getCanonicalName().equals(\"com.sun.faces.el.CompositeComponentAttributesELResolver.ExpressionEvalMap\")){
        Object tempProperty=((Map)aBase).get(aProperty);
        if (tempProperty!=null&&tempProperty.getClass().getCanonicalName().equals(\"org.apache.openjpa.util.java.util.Date.proxy\")) {
            anElContext.setPropertyResolved(true);
            return java.util.Date.class;
        }
    }
    return null;
}


}
通过以下方式将其添加到faces-config:
<el-resolver>
    xxx.BugfixELResolver
</el-resolver>
也可以在无法更改EL实现的环境(如Websphere等)中使用此解决方法。     ,        这是解决方法。问题似乎出在WebSpheres的ExpressionLanguage实现,或者说是执行了订单解析器。注册JBoss EL实现可以正常工作,并在调用复合组件之前解析日期代理。我也尝试了Glassfish EL,但是它也不起作用... 注册备用EL非常奇怪:web.xml中MyFaces的设置是
<context-param>
   <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
   <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
</context-param>
另外,在
WebContent/META-INF/services/
下,需要用named8ѭ这一行来命名文件ѭ7。全班来自
jboss-el-2.0.2.CR1.jar
(抱歉,找不到Maven存储库的链接) 找到更好的解决方案后,我会及时通知您。     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...