6 Replies Latest reply on Aug 12, 2011 11:54 AM by cacelis

    Error setting a Date type parameter [solved]

    cacelis

      Hi there.

       

      I am trying to set a Date type parameter to a report through the next code:

       

       

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:rich="http://richfaces.org/rich"
                xmlns:a4j="http://richfaces.org/a4j"
                xmlns:birt="http://www.eclipse.org/birt/taglibs/birt.tld"
          xmlns:b="http://jboss.com/products/seam/birt">
      
      
      <ui:composition template="/layout/template.xhtml">
                <ui:define name="body">
                          <h:form id="homeForm">
                                    <rich:panel id="panel_config_report">
                                              <f:facet name="header">
                                                        <h:outputText value="Reportes - Distribución" />
                                              </f:facet>
                                              <table align="center">
                                                        <tr align="center">
                                                                  <td><h:outputLabel value="Fecha Inicio:" /></td>
                                                                  <td>
                                                                            <rich:calendar id="fecha_inicio" datePattern="yyyy/MM/dd"
                                                                                      locale="CO" popup="true" enableManualInput="false"
                                                                                      value="#{report.report.fechaInicio}" />
                                                                  </td>
                                                                  <td><h:outputLabel value="Fecha Fin:" /></td>
                                                                  <td>
                                                                            <rich:calendar id="fecha_fin" datePattern="yyyy/MM/dd"
                                                                                      locale="CO" popup="true" enableManualInput="false"
                                                                                      value="#{report.report.fechaFin}" />
                                                                  </td>
                                                                  <td><h:outputLabel value="Zona:" /></td>
                                                                  <td>
                                                                            <h:selectOneMenu id="zona" value="#{report.report.zona}">
                                                                                      <s:selectItems value="#{tblDistribucionUsuariosMovilList.resultList}"
                                                                                                var="user" itemValue="#{user.usuario}" label="#{user.usuario}"
                                                                                                noSelectionLabel="---SELECCIONE---" />
                                                                            </h:selectOneMenu> 
                                                                  </td>
                                                                  <td><h:outputLabel value="Tipo Reporte:" /></td>
                                                                  <td>
                                                                            <h:selectOneMenu id="tipo_reporte" value="#{report.report.tipoEnvio}">
                                                                                      <s:selectItems value="#{tblValorMaestroList.resultList}"
                                                                                                var="master" itemValue="#{master.nombre}" label="#{master.descripcion}"
                                                                                                noSelectionLabel="---SELECCIONE---" />
                                                                            </h:selectOneMenu> 
                                                                  </td>
                                                        </tr>
                                                        <tr>
                                                                  <td colspan="8" align="center">
                                                                            <h:commandButton action="#{report.generateReport()}" value="Generate" />
                                                                  </td>
                                                        </tr>
                                              </table>
                                    </rich:panel>
                                    <rich:panel id="report" rendered="#{report.report.fechaFin != null and report.report.fechaInicio != null and report.report.zona != null and report.report.tipoEnvio != null}">
                                              <f:facet name="header">
                                                        <h:outputText value="Report BIRT" />
                                              </f:facet> 
                                              <b:birt embeddable="true" designName="distribution/design/reporteSinDetalle.rptdesign">
                                                        <b:param name="FechaInicio" value="#{report.report.fechaInicio != null ? report.report.fechaInicio : '0'}" />
                                                        <b:param name="FechaFin" value="#{report.report.fechaFin != null ? report.report.fechaFin : '0'}" />
                                                        <b:param name="Zona" value="#{report.report.zona != null ? report.report.zona : ''}" />
                                                        <b:param name="TipoReporte" value="#{report.report.tipoEnvio != null ? report.report.tipoEnvio : ''}" />
                                              </b:birt>
                                    </rich:panel>
                          </h:form>
                </ui:define>
      </ui:composition>
      </html>
      

       

       

      Dates values arrive to class ReporteBackingBean.java (its nickname is "report") but, when they arrive to the report, console shows the next error:

       

       

      GRAVE [org.jboss.tools.birt] the value of parameter FechaInicio is invalid: org.eclipse.birt.core.exception.CoreException: Can not convert the value of Mon Aug 01 00:00:00 COT 2011 to Date type.
      

       

       

      The ReporteBackingBean.java class has a method that starts a conversation and other that finishes it. Also, It has an object of the Report.java class.

      The code of the Report.java class is the next:

       

       

      @Entity
      public class Report {
                private Date fechaInicio;
                private Date fechaFin;
                private String zona;
                private String tipoEnvio;
      
                /**
                 * @return the fechaInicio
                 */
                public Date getFechaInicio() {
                          return fechaInicio;
                }
                /**
                 * @param fechaInicio the fechaInicio to set
                 */
                public void setFechaInicio(Date fechaInicio) {
                          this.fechaInicio = fechaInicio;
                }
                /**
                 * @return the fechaFin 
                 */
                public Date getFechaFin() {
                          return fechaFin;
                }
                /**
                 * @param fechaFin the fechaFin to set
                 */
                public void setFechaFin(Date fechaFin) {
                          this.fechaFin = fechaFin;
                }
                /**
                 * @return the zona
                 */
                public String getZona() {
                          return zona;
                }
                /**
                 * @param zona the zona to set
                 */
                public void setZona(String zona) {
                          this.zona = zona;
                }
                /**
                 * @return the tipoEnvio
                 */
                public String getTipoEnvio() {
                          return tipoEnvio;
                }
                /**
                 * @param tipoEnvio the tipoEnvio to set
                 */
                public void setTipoEnvio(String tipoEnvio) {
                          this.tipoEnvio = tipoEnvio;
                }
      }
      

       

       

      Can you help me?

       

      Thanks in advance.

        • 1. Re: Error setting a Date type parameter
          snjeza

          You set a date type parameter as a String in a format that BIRT doesn't recognize.

           

          Try the following:

           

          - define the FechaInicio date parameter in some format in the reporteSinDetalle.rptdesign report (yyyy-MM-dd, for instance)

          - add the getFechaInicioAsString method to Report.java that will return the date as a String in the yyyy-MM-dd format(or whatever format you defined in the report).

          1 of 1 people found this helpful
          • 2. Re: Error setting a Date type parameter
            cacelis

            Hi Snjezana.

            Thanks for your answer.

             

            I did what you told me but now I have the following error:

             

             

            GRAVE [org.jboss.tools.birt] the value of parameter FechaInicio is invalid: org.eclipse.birt.core.exception.CoreException: Can not convert the value of 2011/08/01 to Date type.
            

             

             

            I defined "yyyy/MM/dd" as the date format in the report.

             

             

            Thanks.

            • 3. Re: Error setting a Date type parameter
              cacelis

              Hi Snjezana.

               

              I defined two other parameters in the report and I sent them from Report.java in the "yyyy/MM/dd" date format:

               

              1. FechaInicioString (String)

              2. FechaFinString (String)

               

              I put the following at initialize() method of the report:

               

               

              params["FechaInicio"] = Date.parse(params["FechaInicioString"]);
              params["FechaFin"] = Date.parse(params["FechaFinString"]);
              

               

               

              BIRT shows the next error in the web page:

               

               

              The following items have errors:
              
              
              Table (id = 14):
              + An exception occurred during processing. Please see the following message for details:
              Failed to prepare the query execution for the data set: ElTiempoDataSet1
              Cannot convert the parameter value 1,312,174,800,000 to type class java.sql.Date.
              Can not convert the value of 1.3121748E12 to java.sql.Date type.
              
              

               

               

              Thanks for your help.

              • 4. Re: Error setting a Date type parameter
                snjeza

                Does your report work when you call it in the design mode (the Preview tab) and add 2011/08/01 as a parameter?

                1 of 1 people found this helpful
                • 5. Re: Error setting a Date type parameter
                  cacelis

                  When I try with FechaInicio and FechaFin, the report runs succesfully but in the other case, when I try with FechaInicioString and FechaFinString, the report does not run and BIRT shows the same error.

                  • 6. Re: Error setting a Date type parameter
                    cacelis

                    The solution is put the next code at initiliaze() method of the report:

                     

                     

                    importPackage(Packages.java.text);
                    df = new SimpleDateFormat("yyyy/MM/dd");
                    params["FechaInicio"] = df.parse(params["FechaInicioString"]);
                    params["FechaFin"] = df.parse(params["FechaFinString"]);