2012-07-12 92 views
0

当我将方法isNullOrEmpty(String)放入报表中时,我的报表出现问题。
我不知道是什么问题。
有人知道是什么问题?类型字符串中的方法isNullOrEmpty(String)不适用于参数(Timestamp)

这是我的JRXML文件:

<jasperReport ....> 
    <parameter name="TRUE" isForPrompting="false" class="java.lang.Boolean"> 
     <defaultValueExpression ><![CDATA[new Boolean(true)]]> 
     </defaultValueExpression> 
    </parameter> 
    <parameter name="date_start" isForPrompting="true" class="java.sql.Timestamp"> 
     <parameterDescription><![CDATA[reports.helpdesk.startDate]]> 
     </parameterDescription> 
     <defaultValueExpression ><![CDATA[new java.sql.Timestamp(System.currentTimeMillis()-262800000)]]> 
     </defaultValueExpression> 
    </parameter> 
    <parameter name="date_end" isForPrompting="true" class="java.sql.Timestamp"> 
     <parameterDescription><![CDATA[reports.helpdesk.endDate]]> 
     </parameterDescription> 
     <defaultValueExpression ><![CDATA[new java.sql.Timestamp(System.currentTimeMillis())]]> 
     </defaultValueExpression> 
    </parameter> 
    <parameter name="CENTRIC_DICTIONARY" isForPrompting="false" class="java.util.Map"/> 
    <parameter name="SCRIPT_DB_CONNECTION" isForPrompting="false" class="java.sql.Connection"/> 
    <field name="enteredby" class="java.lang.Integer"/> 
    <field name="description" class="java.lang.String"/> 
    <field name="assigned_date" class="java.sql.Timestamp"/> 
    <field name="max_score" class="java.lang.Integer"/> 
    <field name="totalAnswer" class="java.lang.Integer"/> 
    <field name="totalticketcreated" class="java.lang.Integer"/> 
    <field name="totalfeedbackreceived" class="java.lang.Integer"/> 
    <field name="score" class="java.lang.Integer"/> 
    <background> 
     <band height="0" isSplitAllowed="true" > 
     </band> 
    </background> 
    <title> 
     <band height="0" isSplitAllowed="true" > 
     </band> 
    </title> 
    <pageHeader> 
     <band height="108" isSplitAllowed="true" > 
      <staticText> 
       <reportElement 
        x="0" 
        y="0" 
        width="802" 
        height="20" 
        key="staticText"/> 
       <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> 
       <textElement textAlignment="Center" verticalAlignment="Top" rotation="None" lineSpacing="Single"> 
        <font fontName="SansSerif" size="12" isBold="true"/> 
       </textElement> 
       <text><![CDATA[Customer Feedback by Counter]]> 
       </text> 
      </staticText> 
      <textField isStretchWithOverflow="true" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > 
       <reportElement 
        x="0" 
        y="20" 
        width="802" 
        height="35" 
        key="textField" 
        isRemoveLineWhenBlank="true"/> 
       <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> 
       <textElement textAlignment="Center" verticalAlignment="Top" rotation="None" lineSpacing="Single"> 
        <font size="12" isBold="true"/> 
       </textElement> 
       <textFieldExpression class="java.lang.String"><![CDATA[" From (" + $P{date_start} + " - " + $P{date_start} + ")"]]> 
       </textFieldExpression> 
      </textField> 
      <textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" > 
       <reportElement 
        x="0" 
        y="54" 
        width="802" 
        height="41" 
        key="textField" 
        isRemoveLineWhenBlank="true"/> 
       <box topBorder="None" topBorderColor="#000000" leftBorder="None" leftBorderColor="#000000" rightBorder="None" rightBorderColor="#000000" bottomBorder="None" bottomBorderColor="#000000"/> 
       <textElement textAlignment="Left" verticalAlignment="Top" rotation="None" isStyledText="true" lineSpacing="1_1_2"> 
        <font size="11" isBold="true"/> 
       </textElement> 
       <textFieldExpression class="java.lang.String"><![CDATA[(!Strings.isNullOrEmpty($P{date_start})) ? "Date Ticket Created From : " + $P{date_start} +"\n" + "Date Ticket Created to : " + $P{date_end} 
    : "Date Ticket Created From : " + $P{date_start} +"\n" + "Date Ticket Created to : " + $P{date_end}]]> 
       </textFieldExpression> 
      </textField> 
     </band> 
    </pageHeader> 
</jasperReport> 

更新: - 为什么当我用这个公式的计算结果不能显示:

new SimpleDateFormat("dd/MM/yyyy").format($P{date_start})!= null && new SimpleDateFormat("dd/MM/yyyy").format($P{date_end})!=null && ($P{lookup_department}==null) && ($P{lookup_assignedOfficer}==null) ? "Date Ticket Created From : " + new SimpleDateFormat("dd/MM/yyyy").format($P{date_start}) +"\n" + "Date Ticket Created to : " + new SimpleDateFormat("dd/MM/yyyy").format($P{date_end}) 
:new SimpleDateFormat("dd/MM/yyyy").format($P{date_start})!=null && new SimpleDateFormat("dd/MM/yyyy").format($P{date_end})!=null && ($P{lookup_department}!=null) && ($P{lookup_assignedOfficer}==null) ? "Division :"+$F{division} 
:new SimpleDateFormat("dd/MM/yyyy").format($P{date_start})!=null && new SimpleDateFormat("dd/MM/yyyy").format($P{date_end})!=null && ($P{lookup_department}==null) && ($P{lookup_assignedOfficer}!=null) ? "Ticket Created :"+$F{tickedcreted} 
: $F{division} 

回答

0

你DATE_START参数是一个时间戳和isNullOrEmpty ()方法显然需要一个String。试试这个:

$P{date_start} != null 

整个文本字段表达式变为:

<textFieldExpression class="java.lang.String"><![CDATA[($P{date_start} != null) ? "Date Ticket Created From : " + $P{date_start} +"\n" + "Date Ticket Created to : " + $P{date_end} 
: "Date Ticket Created From : " + $P{date_start} +"\n" + "Date Ticket Created to : " + $P{date_end}]]></textFieldExpression> 
+0

我有更新我的公式。你可以看到我的代码有什么问题,因为我正在做你所做的事情,但结果并没有出现:(:(:(:( – 2012-07-13 14:52:32

+0

这太难读了 - 你不需要在新的SimpleDateFormat上检查null,只是检查日期是否为空,但是仍然很难确定你想传达的是什么逻辑 – 2012-07-14 12:57:56

+0

我尝试但是不显示,如果你看到我的第一个代码,我已经把默认的值。因为数据在数据刚刚显示为非空数据时遇到了问题,即使我已经将条件置为null。任何想法? – 2012-07-14 15:24:17

相关问题