Jump to content
Changes to the Jaspersoft community edition download ×

Stupid Newbie Question


Recommended Posts

By: Warthog - warthog982
Stupid Newbie Question
2006-07-17 14:06
Hey, people -
I'm pretty new to JasperReports -- like, 2 days into it -- and I need to put up a custom data source. It seems like it should be easy enough: I have a basic two-field report and what's essentially a one-record document. Looking at the Log4J output, I can see my data source being instantiated and the expected one call to next() is reached. However, getFieldValue() is never called. I hardcoded calls to the method that actually extracts the field value and the correct data is coming back - Jasper isn't doing it, though. Anybody got any clues at all for me? My thanks in advance...


By: Himanshu - himanshugarg
RE: Stupid Newbie Question
2006-07-18 04:52
Could you post the smallest possible sample that repeats the problem, please.

Thank You,
Himanshu.


By: Warthog - warthog982
RE: Stupid Newbie Question
2006-07-18 08:54
Smallest sample? Here's the whole thing:

JRXML:

 

<?xml version="1.0" encoding="UTF-8" ?><!-- Created with iReport - A designer for JasperReports --><!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd"><jasperReport name="tempfile"              columnCount="1"              printOrder="Vertical"              orientation="Portrait"              pageWidth="595"              pageHeight="842"              columnWidth="555"              columnSpacing="0"              leftMargin="20"              rightMargin="20"              topMargin="30"              bottomMargin="30"              whenNoDataType="NoPages"              isTitleNewPage="false"              isSummaryNewPage="false">    <property name="ireport.scriptlethandling" value="0" />    <property name="ireport.encoding" value="UTF-8" />    <import value="java.util.*" />    <import value="net.sf.jasperreports.engine.*" />    <import value="net.sf.jasperreports.engine.data.*" />    <import value="com.ea.jasperreports.test.*" />    <field name="Summary" class="java.lang.String"/>    <field name="Document_Title" class="java.lang.String"/>    <background>        <band height="0" isSplitAllowed="true" ></band>    </background>    <title>        <band height="0" isSplitAllowed="true" ></band>    </title>    <pageHeader>        <band height="0" isSplitAllowed="true" ></band>    </pageHeader>    <columnHeader>        <band height="0" isSplitAllowed="true" ></band>    </columnHeader>    <detail>        <band height="201" isSplitAllowed="true" >            <staticText>                <reportElement x="180" y="0" width="200"                               height="200" key="staticText"/>                <box topBorder="None"    topBorderColor="#000000"                      leftBorder="None"   leftBorderColor="#000000"                      rightBorder="None"  rightBorderColor="#000000"                      bottomBorder="None" bottomBorderColor="#000000"/>                <textElement><font/></textElement>                <text><![CDATA[Will ANYthing come out of this?]]></text>            </staticText>            <textField isStretchWithOverflow="false"                       sBlankWhenNull="false"                        evaluationTime="Auto"                        hyperlinkType="None"                        hyperlinkTarget="Self" >                <reportElement x="180" y="25" width="158"                               height="30" key="textField-2"/>                <box topBorder="None"    topBorderColor="#000000"                      leftBorder="None"   leftBorderColor="#000000"                      rightBorder="None"  rightBorderColor="#000000"                      bottomBorder="None" bottomBorderColor="#000000"/>                <textElement>                    <font pdfEncoding ="Cp1257"/>                </textElement>                <textFieldExpression class="java.lang.String">                    <![CDATA[$F{Document_Title}]]>                </textFieldExpression>            </textField>            <textField isStretchWithOverflow="false" pattern=""                        isBlankWhenNull="false" evaluationTime="Now"                        hyperlinkType="None" hyperlinkTarget="Self" >                <reportElement x="180" y="62" width="160"                               height="110" key="Summary"/>                <box topBorder="None"    topBorderColor="#000000"                      leftBorder="None"   leftBorderColor="#000000"                      rightBorder="None"  rightBorderColor="#000000"                      bottomBorder="None" bottomBorderColor="#000000"/>                <textElement>                   <font pdfEncoding ="Cp1257"/>                </textElement>                <textFieldExpression class="java.lang.String">                    <![CDATA[$F{Summary}]]>                </textFieldExpression>            </textField>        </band>    </detail>    <columnFooter>        <band height="0" isSplitAllowed="true" ></band>    </columnFooter>    <pageFooter>        <band height="0" isSplitAllowed="true" ></band>    </pageFooter>    <summary>        <band height="0" isSplitAllowed="true" ></band>    </summary></jasperReport>[/code]

Java:

package com.ea.jasperreports.test;import javax.xml.parsers.*;import org.apache.commons.digester.*;import net.sf.jasperreports.engine.*;import net.sf.jasperreports.engine.data.*;import net.sf.jasperreports.view.*;import java.io.*;import java.net.*;import java.util.*;import javax.xml.transform.*;import javax.xml.transform.stream.*;import org.apache.xerces.parsers.DOMParser;import org.apache.log4j.*;import org.w3c.dom.*;import org.xml.sax.InputSource;import org.xml.sax.*;// public class JRICStandardDataSource implements net.sf.jasperreports.engine.JRDataSourcepublic class JRICStandardDataSource implements JRDataSource{    static Logger log = Logger.getLogger("JRICStandardDataSource.class");    private String _xsl;    private File _xml;    Document doc = null;    int count = 0;    Hashtable tmpHash = new Hashtable();    public JRICStandardDataSource(String xmlFile,String xslFile){        BasicConfigurator.configure();        log.debug("Input : "+xmlFile);        _xml = new File(xmlFile);        setDocument(_xml);        try{            log.debug("Title : "+getValue("Document_Title"));            log.debug("Summary: "+getValue("Summary"));       }       catch(Exception e){           e.printStackTrace();       }    }    public boolean next() throws JRException{    log.debug("JRICStandardDataSource.next(): "+ count);    setDocument(_xml);    count++;    return(count>1);}public Object getFieldValue(JRField field) throws JRException{    log.debug("tGetting: "+field.getName()+" ...n");    try{        return(getValue(field.getName()));    }    catch(Exception e){        e.printStackTrace();    }    return(null);}private void setDocument(File f){    DOMParser parser = new DOMParser();    try{        parser.parse(new InputSource(f.getName()));        doc = parser.getDocument();    }    catch(Exception e){        e.printStackTrace();    }}private String getValue(String fieldName) throws Exception{    NodeList nodes = doc.getElementsByTagName(fieldName);    if (nodes==null)        throw new Exception("Field "+fieldName+" not found...");    for (int i=0;i<nodes.getLength();i++){        Node node = nodes.item(i);        System.err.println("Node name: "+node.getNodeName());        if (node.hasChildNodes()){            System.err.println(node.getFirstChild().getNodeValue());            if (node.getFirstChild().getNodeValue()!=null)                return(node.getFirstChild().getNodeValue());        }    }    return(null);}}[/code]




By: Lucian Chirita - lucianc
RE: Stupid Newbie Question
2006-07-19 09:13
Your data source's next() method never returns true:
initially count = 0
count++ --> count = 1
return count>1 --> false

next() should return true when the data source still has data rows.

HTH,
Lucian


By: Warthog - warthog982
RE: Stupid Newbie Question
2006-07-19 09:43
when count is equal to 1, it's not greater than 1; output to the log file indicates that next() is called exactly one time...


By: Warthog - warthog982
RE: Stupid Newbie Question
2006-07-19 09:48
Actually, belay that: must've been thinking in reverse Polish or something. I did change the escape logic to actually be meaningful this time, but getFieldValue() still is never called...

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...