我正在将我的项目从WebSphere 7迁移到WebSphere 8,而我正在使用JSF 1.2。
我遇到了IBM JSF / html_extended标记以及标准转换器的问题,这些转换器主要是JSF 1.2核心组件。我也将我的Java EE版本从5更新到6(这可能不是原因)。最后,还有一个组件树。
下面是我的堆栈跟踪:
javax.faces.component.UpdateModelException: org.apache.jasper.el.JspELException: /sc40/NewContract.jsp(130,5) '#{pc_NewContract.overrideAsOfDtSQL}' Cannot convert 4/23/12 12:00 AM of type class java.util.Date to class java.sql.Date at javax.faces.component.UIInput.updateModel(UIInput.java:398) at javax.faces.component.UIInput.processUpdates(UIInput.java:299) at javax.faces.component.UIForm.processUpdates(UIForm.java:187) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1258) at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1258) at javax.faces.component.UIViewRoot._processUpdatesDefault(UIViewRoot.java:1321) at javax.faces.component.UIViewRoot.access$600(UIViewRoot.java:75) at javax.faces.component.UIViewRoot$UpdateModelPhaseProcessor.process(UIViewRoot.java:1423) at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1282) at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:765) at org.apache.myfaces.lifecycle.UpdateModelValuesExecutor.execute(UpdateModelValuesExecutor.java:34) at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171) at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189) at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1147) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:722) at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:449) at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178) at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1020) at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3639) at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304) at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:950) at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1659) at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511) at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305) at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83) at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165) at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:816) at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1648) Caused by: org.apache.jasper.el.JspELException: /sc40/NewContract.jsp(130,5) '#{pc_NewContract.overrideAsOfDtSQL}' Cannot convert 4/23/12 12:00 AM of type class java.util.Date to class java.sql.Date at org.apache.jasper.el.JspValueExpression.setValue(JspValueExpression.java:98) at javax.faces.component.UIInput.updateModel(UIInput.java:380) ... 35 more
答案 0 :(得分:6)
'#{pc_NewContract.overrideAsOfDtSQL}'无法将类型为java.util.Date的4/23/12 12:00 AM转换为类java.sql.Date
你显然有一个
private java.sql.Date overrideAsOfDtSQL;
这不正确。 类型的java.sql.*
类型属于模型。将其替换为java.util.Date
。
private java.util.Date overrideAsOfDtSQL;
当您使用java.sql.Time
时,同样的答案也适用。
请注意,java.sql.Date
和java.sql.Time
是java.util.Date
的子类,这就是它在使用<f:convertDateTime>
从对象转换为字符串时的工作原理。只有从字符串转换为对象才会起作用,因为<f:convertDateTime>
始终会转换为java.util.Date
。
答案 1 :(得分:0)
没有更改hibernate模型的解决方法。我更喜欢这种方式,因为所有更改都在jsf层中。
您可以在复合组件中使用绑定。下一个代码是rich:calendar(使用java.util.Date)
的示例... &lt; cc:interface componentType =“CalendarComponent”&gt;
... &LT; /立方厘米:接口&GT;
<cc:implementation>
... &lt; rich:calendar value =“#{cc.attrs.value}”binding =“#{cc.attrs.calendar}”/&gt;
...
&LT; /立方厘米:执行&GT;
...
并在CalendarComponent中:
import java.util.Date;
import javax.faces.component.FacesComponent;
import javax.faces.component.UINamingContainer;
import javax.faces.context.FacesContext;
import org.richfaces.component.UICalendar;
@FacesComponent(value = "CalendarComponent")
public class CalendarComponent extends UINamingContainer {
@Override
public void processUpdates(FacesContext context) {
Object o = calendar.getValue();
if (o instanceof Date) {
Date d = (Date) o;
//this ensures type changing
calendar.setValue(new java.sql.Date(d.getTime()));
}
super.processUpdates(context);
}
private UICalendar calendar;
public UICalendar getCalendar() {
return calendar;
}
public void setCalendar(UICalendar calendar) {
this.calendar = calendar;
}
}