I am getting a strange error. I created a simple JSF composite component, that is:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<cc:interface>
<cc:attribute name="fieldId" required="true" />
<cc:attribute name="targetValue" type="java.sql.Date" required="true" />
<cc:attribute name="required" default="false" />
<cc:attribute name="disabled" default="false" />
<cc:attribute name="styleClass" />
</cc:interface>
<cc:implementation>
<p:calendar id="#{cc.attrs.fieldId}" disabled="#{cc.attrs.disabled}" required="#{cc.attrs.required}" locale="pt" navigator="true" pattern="dd/MM/yyyy" showOn="button" value="#{cc.attrs.targetValue}" styleClass="#{cc.attrs.styleClass}">
<f:convertDateTime type="date" dateStyle="short" pattern="dd/MM/yyyy"/>
<f:ajax event="blur" execute="@this" render="@this" />
</p:calendar>
</cc:implementation>
</html>
And I´m using this on my form, normally:
<p:outputLabel for="inputInicial:dataInicial" value="#{msg['entity.dataInicial']}" />
<po:inputData id="inputInicial" targetValue="#{acaoController.entity.dataInicial}" fieldId="dataInicial"/>
<p:outputLabel for="inputFinal:dataFinal" value="#{msg['entity.dataFinal']}" />
<po:inputData id="inputFinal" targetValue="#{acaoController.entity.dataFinal}" fieldId="dataFinal" />
And, it works fine when I click to add a new entity... I click on save, and it saves as expected.
When I click to edit an existing entity, and click on save button... This errors occurs:
SEVERE: Servlet.service() for servlet [facesServlet] in context with path [/ProjetoOlimpio] threw exception [javax.el.ELException: /resources/olimpio/inputData.xhtml @18,238 value="#{cc.attrs.targetValue}": Cannot convert 30/12/12 21:00 of type class java.util.Date to class java.sql.Date] with root cause
javax.el.ELException: /resources/olimpio/inputData.xhtml @18,238 value="#{cc.attrs.targetValue}": Cannot convert 30/12/12 21:00 of type class java.util.Date to class java.sql.Date
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:139)
at javax.faces.component.UIInput.updateModel(UIInput.java:818)
at javax.faces.component.UIInput.processUpdates(UIInput.java:735)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at javax.faces.component.UIForm.processUpdates(UIForm.java:281)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at org.primefaces.component.layout.Layout.processUpdates(Layout.java:252)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1242)
at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1231)
at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
My model uses java.util.Date class of course.
import java.util.Date;
[...]
@Column(name = "data_inicial")
@Temporal(TemporalType.DATE)
private Date dataInicial;
@Column(name = "data_final")
@Temporal(TemporalType.DATE)
private Date dataFinal;
I am using Spring Data to persist! It is hard to understand...
Why does it work on save (not on update) ? Why does it show the selected Date correctly on the view after I click to edit the entity?
Here some info about my enviroment: INFO: Starting Servlet Engine: Apache Tomcat/7.0.12 INFO: Initializing Mojarra 2.1.10 INFO: Running on PrimeFaces 3.4.2 INFO: Running on PrimeFaces Extensions 0.6.1
**EDIT
1 - As I said on the comments: the problem is with the composite component, if I put the p:calendar directly on the form it works. So I´ll edit the code snippet of the CC to the whole thing! :)
Notice that I have a type="java.sql.Date" That was added because I was testing. Originally it had no type attribute. I also tested with type="java.util.Date.