-
1. Re: Issue with Date Converter
rogermorituesta.rogermori.yahoo.com Mar 3, 2011 10:24 AM (in response to lfelipeas)Hi Luis:
Show the piece of jsf code that calls the View/Edit pages.
Roger.
-
2. Re: Issue with Date Converter
lfelipeas Mar 3, 2011 10:43 AM (in response to lfelipeas)<rich:dataTable id="pmnAditivoList" var="_pmnAditivo" value="#{pmnAditivoList.resultList}" rendered="#{not empty pmnAditivoList.resultList}"> <h:column> <f:facet name="header"> <ui:include src="layout/sort.xhtml"> <ui:param name="entityList" value="#{pmnAditivoList}"/> <ui:param name="propertyLabel" value="Aquisicao"/> <ui:param name="propertyPath" value="pmnAditivo.id.sqAquisicao"/> </ui:include> </f:facet> <h:outputText value="#{_pmnAditivo.id.sqAquisicao}"/> </h:column> <h:column> <f:facet name="header"> <ui:include src="layout/sort.xhtml"> <ui:param name="entityList" value="#{pmnAditivoList}"/> <ui:param name="propertyLabel" value="Data Inicio"/> <ui:param name="propertyPath" value="pmnAditivo.id.dtInicio"/> </ui:include> </f:facet> <h:outputText value="#{_pmnAditivo.id.dtInicio}"> <f:convertDateTime dateStyle="short" pattern="dd/MM/yyyy" type="date"/> </h:outputText> </h:column> <rich:column styleClass="action"> <f:facet name="header">Ações</f:facet> <s:link view="/Aditivo/#{empty from ? 'PmnAditivo' : from}.xhtml" value="#{empty from ? 'Visualizar' : 'Selecionar'}" propagation="#{empty from ? 'none' : 'default'}" id="pmnAditivoViewId"> <f:param name="pmnAditivoSqAquisicao" value="#{_pmnAditivo.id.sqAquisicao}"/> <f:param name="pmnAditivoDtInicio" value="#{_pmnAditivo.id.dtInicio}"/> </s:link> #{' '} <s:link view="/Aditivo/PmnAditivoEdit.xhtml" value="Editar" propagation="none" id="pmnAditivoEdit" rendered="#{empty from}"> <f:param name="pmnAditivoSqAquisicao" value="#{_pmnAditivo.id.sqAquisicao}"/> <f:param name="pmnAditivoDtInicio" value="#{_pmnAditivo.id.dtInicio}"/> </s:link> </rich:column>
But I think that my list page doesn't interfere in nothing. I'll put the View page too, just in case.
<s:decorate id="dtInicio" template="layout/display.xhtml"> <ui:define name="label">Data Início</ui:define> <h:outputText value="#{pmnAditivoHome.instance.id.dtInicio}"/> </s:decorate> <div class="actionButtons"> <s:button view="/Aditivo/PmnAditivoEdit.xhtml" id="edit" value="Editar"/> <s:button view="/Aditivo/#{empty pmnAditivoFrom?'PmnAditivoList'pmnAditivoFrom}.xhtml" id="done" value="Fechar"/> </div>
-
3. Re: Issue with Date Converter
rogermorituesta.rogermori.yahoo.com Mar 3, 2011 12:01 PM (in response to lfelipeas)Assuming that the following jsf code is calling the Edit, the problem is a format mismatch between the f:param and the page parameter. As you noticed, the page parameter is using the defaul date converter.
<s:link view="/Aditivo/PmnAditivoEdit.xhtml" value="Editar" propagation="none" id="pmnAditivoEdit" rendered="#{empty from}"> <f:param name="pmnAditivoSqAquisicao" value="#{_pmnAditivo.id.sqAquisicao}"/> <f:param name="pmnAditivoDtInicio" value="#{_pmnAditivo.id.dtInicio}"/> </s:link>
There exists several flavors to fix this problem according to your specific context.
Replace all your date attributes with long
Then use a transient attribute long to date converter to do the tranlation
@Column(..) public long getXXXDate() { return XXXDate; } public long setXXXDate(long xxxx) { XXXDate = xxxx; } @Transient public Date getYYYDate() { return new Date(XXXDate); } public long setYYYDate(Date xxxx) { XXXDate = xxxx.getTime(); }
Match the format f:parm and page parameter using a component
In your components.xml configure the component:
<component name="DATE_FORMATTER" class="com.hersys.utils.date.DateFormatter" auto-create="true" scope="application" > <property name="timeZone">#{timeZone}</property> </component>
The component itself:
public class DateFormatter { private TimeZone timeZone; private DateFormat dateFormat = DateFormat.getDateTimeInstance(); public String format(Date date) { if (date == null) { return null; } return dateFormat.format(date); } public TimeZone getTimeZone() { return timeZone; } public void setTimeZone(TimeZone timeZone) { this.timeZone = timeZone; dateFormat.setTimeZone(timeZone); } }
In you JSF view:
<s:link view="/Aditivo/PmnAditivoEdit.xhtml" value="Editar" propagation="none" id="pmnAditivoEdit" rendered="#{empty from}"> <f:param name="pmnAditivoSqAquisicao" value="#{_pmnAditivo.id.sqAquisicao}"/> <f:param name="pmnAditivoDtInicio" value="#{DATE_FORMATTER.format(_pmnAditivo.id.dtInicio)}"/> </s:link>
-
4. Re: Issue with Date Converter
lfelipeas Mar 3, 2011 1:14 PM (in response to lfelipeas)Hi Roger, thanks for your help.
Now I'm getting another problem. This time it is in the Validator.First, I made the changes you've said, but he went to the default Converter and I got again the same Converter Exception.
So, I tried to change the value attribute in the edit.page.xml. And it is when this Validator error happens. It says:parameter is invalid: Illegal Syntax for Set Operation.
-
5. Re: Issue with Date Converter
lfelipeas Mar 3, 2011 1:21 PM (in response to lfelipeas)Just to let you know, I only tried the second method of solving the problem.
I'll try the first one right now.
-
6. Re: Issue with Date Converter
lfelipeas Mar 3, 2011 1:56 PM (in response to lfelipeas)I don't know if I'm using this transient attribute correctly.
I'm getting some errors. Or nothing happens, he just use the normal getter and setter. -
7. Re: Issue with Date Converter
rogermorituesta.rogermori.yahoo.com Mar 3, 2011 2:36 PM (in response to lfelipeas)Hi Luiz:
It is either solution but not both together.
I have both working, and am supposing you have something in your Edit page (xml) descriptor.If you are using the transient you have check your embeddeId to make sure that it is using the setter and not accesing the attribure directly. Also you have to use the transient instead of the date attribute in the List (f:param) and Edit (page parameter) page as well.
The Component is less intrusive.
Can you post your code including your page XML descriptor to have more insight.
Thank you.
Roger.
-
8. Re: Issue with Date Converter
lfelipeas Mar 3, 2011 2:57 PM (in response to lfelipeas)I've found more info!
16:41:43,584 SEVERE [viewhandler] Error Rendering View[/Aditivo/PmnAditivoEdit.xhtml] javax.faces.convert.ConverterException: java.lang.String cannot be cast to javax.faces.convert.Converter at javax.faces.convert.DateTimeConverter.getAsString(DateTimeConverter.java:463) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:448) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:467) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:286) at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:154) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:861) at org.jboss.seam.ui.util.cdk.RendererBase.renderChild(RendererBase.java:190) at org.jboss.seam.ui.util.cdk.RendererBase.renderChildren(RendererBase.java:166) at org.jboss.seam.ui.renderkit.DecorateRendererBase.doEncodeChildren(DecorateRendererBase.java:152) at org.jboss.seam.ui.util.cdk.RendererBase.encodeChildren(RendererBase.java:92) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837) at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277) at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258) at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:220) at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:215) at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933) 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:110) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83) at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178) at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290) at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368) at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495) at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69) at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92) at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126) at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619) Caused by: java.lang.IllegalArgumentException: Illegal pattern character 'o' at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:751) at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:558) at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:483) at javax.faces.convert.DateTimeConverter.getDateFormat(DateTimeConverter.java:491) at javax.faces.convert.DateTimeConverter.getAsString(DateTimeConverter.java:450)
Here goes my edit.page.xml
<?xml version="1.0" encoding="UTF-8"?> <page login-required="true" no-conversation-view-id="/Aditivo/PmnAditivoList.xhtml" xmlns="http://jboss.com/products/seam/pages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd"> <begin-conversation flush-mode="MANUAL" join="true"/> <action execute="#{pmnAditivoHome.wire}"/> <param name="pmnAditivoFrom"/> <param name="pmnAditivoSqAquisicao" value="#{pmnAditivoHome.pmnAditivoId.sqAquisicao}"/> <param name="pmnAditivoDtInicio" value="#{pmnAditivoHome.instance.id.dtInicio}"/> <navigation from-action="#{pmnAditivoHome.persist}"> <rule if-outcome="persisted"> <end-conversation/> <redirect view-id="/Aditivo/PmnAditivo.xhtml"/> </rule> </navigation> <navigation from-action="#{pmnAditivoHome.update}"> <rule if-outcome="updated"> <end-conversation/> <redirect view-id="/Aditivo/PmnAditivo.xhtml"/> </rule> </navigation> <navigation from-action="#{pmnAditivoHome.remove}"> <rule if-outcome="removed"> <end-conversation/> <redirect view-id="/Aditivo/PmnAditivoList.xhtml"/> </rule> </navigation> </page>
I'll put my Entity and my EmbeddableID class, just in case.
Here's the Entity
@Entity @Table(name = "PMN_ADITIVO", schema = "BL_CORP_PRJ") public class PmnAditivo implements java.io.Serializable { private PmnAditivoId id; private short nuDiasPrazo; private BigDecimal vlAditivo; public PmnAditivo() { } public PmnAditivo(PmnAditivoId id, short nuDiasPrazo, BigDecimal vlAditivo) { this.id = id; this.nuDiasPrazo = nuDiasPrazo; this.vlAditivo = vlAditivo; } @EmbeddedId @AttributeOverrides({ @AttributeOverride(name = "sqAquisicao", column = @Column(name = "SQ_AQUISICAO", nullable = false, precision = 10, scale = 0)), @AttributeOverride(name = "dtInicio", column = @Column(name = "DT_INICIO", nullable = false, length = 7)) }) @NotNull public PmnAditivoId getId() { return this.id; } public void setId(PmnAditivoId id) { this.id = id; } @Column(name = "NU_DIAS_PRAZO", nullable = false, precision = 3, scale = 0) public short getNuDiasPrazo() { return this.nuDiasPrazo; } public void setNuDiasPrazo(short nuDiasPrazo) { this.nuDiasPrazo = nuDiasPrazo; } @Column(name = "VL_ADITIVO", nullable = false, precision = 12) @NotNull public BigDecimal getVlAditivo() { return this.vlAditivo; } public void setVlAditivo(BigDecimal vlAditivo) { this.vlAditivo = vlAditivo; }
And here's the EmbeddableID class
@Embeddable public class PmnAditivoId implements java.io.Serializable { private long sqAquisicao; private Date dtInicio; public PmnAditivoId() { } public PmnAditivoId(long sqAquisicao, Date dtInicio) { this.sqAquisicao = sqAquisicao; this.dtInicio = dtInicio; } @Column(name = "SQ_AQUISICAO", nullable = false, precision = 10, scale = 0) public long getSqAquisicao() { return this.sqAquisicao; } public void setSqAquisicao(long sqAquisicao) { this.sqAquisicao = sqAquisicao; } @Column(name = "DT_INICIO", nullable = false, length = 7) @NotNull public Date getDtInicio() { return this.dtInicio; } public void setDtInicio(Date dtInicio) { this.dtInicio = dtInicio; } public boolean equals(Object other) { if ((this == other)) return true; if ((other == null)) return false; if (!(other instanceof PmnAditivoId)) return false; PmnAditivoId castOther = (PmnAditivoId) other; return (this.getSqAquisicao() == castOther.getSqAquisicao()) && ((this.getDtInicio() == castOther.getDtInicio()) || (this .getDtInicio() != null && castOther.getDtInicio() != null && this .getDtInicio().equals(castOther.getDtInicio()))); } public int hashCode() { int result = 17; result = 37 * result + (int) this.getSqAquisicao(); result = 37 * result + (getDtInicio() == null ? 0 : this.getDtInicio().hashCode()); return result; } }
-
9. Re: Issue with Date Converter
lfelipeas Mar 3, 2011 3:20 PM (in response to lfelipeas)Here is the Scoped Variables.
Request Parameters Name Value pmnAditivoDtInicio 21/02/2011 00:00:00 pmnAditivoSqAquisicao 57 Request Attributes Name Value ajaxContext org.ajax4jsf.context.AjaxContextImpl@566a82 invalid false pmnAditivoDtInicio Mon Feb 21 00:00:00 BRT 2011 pmnAditivoSqAquisicao 57 required false Session Attributes Name Value None Application Attributes Name Value DATE_FORMATTER org.domain.bl.converter.DateFormatter@1436e53 securityRules org.jboss.seam.drools.RuleBase@16a9bc0
-
10. Re: Issue with Date Converter
rogermorituesta.rogermori.yahoo.com Mar 3, 2011 3:59 PM (in response to lfelipeas)This piece of code is causing the problem:
<param name="pmnAditivoSqAquisicao" value="#{pmnAditivoHome.pmnAditivoId.sqAquisicao}"/> <param name="pmnAditivoDtInicio" value="#{pmnAditivoHome.instance.id.dtInicio}"/>
Have in mind that the Home object will call it setId(Object x) method prior to retrieve the desired instance. So, replace it with something like this:
<param name="pmnAditivoSqAquisicao" value="#{pmnAditivoHome.sqAquisicao}"/> <param name="pmnAditivoDtInicio" value="#{pmnAditivoHome.dtInicio}"/>
And
@name("pmnAditivoHome") { ............ CompositeId cid = new CompositeId(); setSqAquisicao(String yyy) { cid.SqAquisicao(yyy); setId(cid); } setDtInicio(Date xxx) { cid.setDtInicio(xxx); setId(cid); } ..... }
-
11. Re: Issue with Date Converter
lfelipeas Mar 4, 2011 9:08 AM (in response to lfelipeas)My setters are in the CompositeID object. So I'd have to something like this:
PmnAditivoId pid = new PmnAditivoId(); public void setSqAquisicao(long sqAquisicao) { pid.setSqAquisicao(sqAquisicao); setId(pid); } public void setDtInicio(Date dtInicio) { pid.setDtInicio(dtInicio); setId(pid); }
Right? Or I understood wrong?
-
12. Re: Issue with Date Converter
lfelipeas Mar 4, 2011 9:42 AM (in response to lfelipeas)I don't know if this can affect something but I'm thinking that I'm getting this converter exception because the converter is trying to convert a date using the standards of the US locale while my date, the one that is going to the converter, is using the Brazil locale.
-
13. Re: Issue with Date Converter
lfelipeas Mar 4, 2011 9:59 AM (in response to lfelipeas)My converter is using this:
dateStyle: short
locale: Locale (there's an attribute inside the Locale called language and he's using EN)
log: LogImpl
pattern: M/d/yyyy
timeStyle: short
timeZone: ZoneInfo (here there's an ID and he's using
America/SaoPaulo
)transientFlag: false
type: date
-
14. Re: Issue with Date Converter
lfelipeas Mar 4, 2011 12:35 PM (in response to lfelipeas)SOLVED!
The converter was set to convert an US date type. So added a converter modifying the pattern, the timeZone, the dateStyle and the locale. With the DATEFORMATTER, the new converter recognizes the date and successfully convert it.