Hi.

I'm using jasper reports for the first time and my objective is to integrate
it into my web application where i'm using spring, struts2 and hibernate.

For start i create a simple and example with 2 classes: User and Morada
where Morada is a List.
Soo, as far i understand i need to create a report and then a subreport to
represent this List...

The problem is that i get all the User information except this List of
Morada.... My subreport stays blank.....

Here“s my code:

User.java
public class User implements Serializable {
        
        private static final long serialVersionUID = -270523345211099505L;
        
        private int id;
        private int version;

        private String nome;
        private Date dataNascimento;
        private List<Morada> moradas = new ArrayList<Morada>();
        private String carro;
        
        
        public User() {
                super();
                // TODO Auto-generated constructor stub
        }

        public User(int id, int version, String nome, Date dataNascimento,
                        List<Morada> moradas, String carro) {
                super();
                this.id = id;
                this.version = version;
                this.nome = nome;
                this.dataNascimento = dataNascimento;
                this.moradas = moradas;
                this.carro = carro;
        }

        public int getId() {
                return id;
        }
        
        public void setId(int id) {
                this.id = id;
        }

        public int getVersion() {
                return version;
        }
        
        public void setVersion(int version) {
                this.version = version;
        }

        public String getNome() {
                return nome;
        }

        public void setNome(String nome) {
                this.nome = nome;
        }

        public Date getDataNascimento() {
                return dataNascimento;
        }

        public void setDataNascimento(Date dataNascimento) {
                this.dataNascimento = dataNascimento;
        }

        public List<Morada> getMoradas() {
                return moradas;
        }

        public void setMoradas(List<Morada> moradas) {
                this.moradas = moradas;
        }

        public String getCarro() {
                return carro;
        }

        public void setCarro(String carro) {
                this.carro = carro;
        }       
}
***********************************************************

Morada.java
import java.io.Serializable;

public class Morada implements Serializable {
        
        private static final long serialVersionUID = 5916529466303948452L;

        private int id; 
        private int version;
        
        private int user_id;
        
        private String rua;
        private String cidade;
        private String cod_postal;
        
        public Morada() {
                super();
        }
        
        public Morada(int id, int version, int user_id, String rua, String 
cidade,
                        String cod_postal) {
                super();
                this.id = id;
                this.version = version;
                this.user_id = user_id;
                this.rua = rua;
                this.cidade = cidade;
                this.cod_postal = cod_postal;
        }



        public String getRua() {
                return rua;
        }
        public void setRua(String rua) {
                this.rua = rua;
        }
        public String getCidade() {
                return cidade;
        }
        public void setCidade(String cidade) {
                this.cidade = cidade;
        }
        public String getCod_postal() {
                return cod_postal;
        }
        public void setCod_postal(String cod_postal) {
                this.cod_postal = cod_postal;
        }
        public int getId() {
                return id;
        }
        public void setId(int id) {
                this.id = id;
        }
        public int getVersion() {
                return version;
        }
        public void setVersion(int version) {
                this.version = version;
        }
        public int getUser_id() {
                return user_id;
        }
        public void setUser_id(int user_id) {
                this.user_id = user_id;
        }
}
***********************************************************
JasperAction.java
public class JasperAction extends ActionSupport implements SessionAware,
ServletResponseAware{

        /**
         * 
         */
        private static final long serialVersionUID = -2241881591992228718L;
        private User user;
        private Map session;
        
        private String contentType;
        private String contentDisposition;
        private String inputPath;
        private HttpServletResponse servletResponse;
        private InputStream inputStream;
        
        
        private ArrayList<User> dados = new ArrayList<User>();
        
        /** List to use as our JasperReports dataSource. */
    private List<User> myList = new ArrayList<User>();

        
        public User getUser() {
                return user;
        }

        public void setUser(User user) {
                this.user = user;
        }
        
        public Map getSession() {
                return session;
        }

        public void setSession(Map session) {
                this.session = session;
        }
        
        

        public HttpServletResponse getServletResponse() {
                return servletResponse;
        }

        public void setServletResponse(HttpServletResponse servletResponse) {
                this.servletResponse = servletResponse;
        }


        public List<User> getMyList() {
                return myList;
        }

        public void setMyList(List<User> myList) {
                this.myList = myList;
        }

        public String getContentType() {
                return contentType;
        }

        public void setContentType(String contentType) {
                this.contentType = contentType;
        }

        public String getContentDisposition() {
                return contentDisposition;
        }

        public void setContentDisposition(String contentDisposition) {
                this.contentDisposition = contentDisposition;
        }

        public String getInputPath() {
                return inputPath;
        }

        public void setInputPath(String inputPath) {
                this.inputPath = inputPath;
        }

        public InputStream getInputStream() {
                return inputStream;
        }

        public void setInputStream(InputStream inputStream) {
                this.inputStream = inputStream;
        }

        
        public ArrayList<User> getDados() {
                return dados;
        }

        public void setDados(ArrayList<User> dados) {
                this.dados = dados;
        }

        /*******************************************************/
        
        public String execute()throws IOException{
                        
                this.getDados().add((User)this.getSession().get("user"));
                this.setMyList(dados);
                
                try {
                        String reportSource;
                        reportSource = ServletActionContext.getServletContext()
                .getRealPath("/jasper/Users.jrxml");
                        File parent = new File(reportSource).getParentFile();
                        
                        JasperCompileManager.compileReportToFile(reportSource, 
new File(
                parent, "Users.jasper").getAbsolutePath());
                        String jasperFile =
ServletActionContext.getServletContext().getRealPath("/jasper/Users.jasper");
        } catch (Exception e) {
                e.printStackTrace();
                return ERROR;
        }
        
        return SUCCESS;
                
        }

}

***********************************************************
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd";>

<struts>

        <constant name="struts.objectFactory" value="spring"></constant>
    <constant name="struts.enable.DynamicMethodInvocation"
value="true"></constant>
    <constant name="struts.devMode" value="false"></constant>

    <package name="IReport" extends="tiles-default" >
        
                        <result-types>
                                <result-type name="tiles"
class="org.apache.struts2.views.tiles.TilesResult" default="true"/>
                                <result-type name="stream"
class="org.apache.struts2.dispatcher.StreamResult" default="false"/>
                                <result-type name="dispatcher"
class="org.apache.struts2.dispatcher.ServletDispatcherResult"
default="false"/>
                                <result-type name="jasper"
class="org.apache.struts2.views.jasperreports.JasperReportsResult"
default="false"/> 
                        </result-types>
                        
                        <global-results>
                                <result name="error" 
type="dispatcher">/WEB-INF/jsp/Error.jsp</result>
                                <result name="cancel">welcome</result>
                        </global-results>
                        
                        <global-exception-mappings>
                                <exception-mapping 
exception="java.lang.Throwable" result="error"/> 
                        </global-exception-mappings>
                        
                        
                        
                        <!-- ************************************** CREATE
*********************************************** -->
                                
                        <!-- Create User -->
                        <action name="insertUser_*" method="{1}"
class="com.ht.webapp.action.UserAction">
                                <result name="input">insertUser</result>
                                <result name="next">insertMorada</result>
                        </action>
                        
                        <!-- Create Morada -->
                        <action name="insertMorada_*" method="{1}"
class="com.ht.webapp.action.UserAction">
                                <result name="input">insertMorada</result>
                                <result name="success">sucesso</result>
                        </action>
                        
                        <!-- **************************************** READ
************************************************ -->
                        
                        <!-- Read -->
                        <action name="readUser_*" method="{1}"
class="com.ht.webapp.action.UserAction">
                                <result name="input">searchUser</result>
                                <result name="success">readUser</result>
                        </action>
                                                
                        <!-- ******************************** SEARCH INFORMATION
********************************************* -->
                                                
                        <!-- Search User -->
                        <action name="searchUser_*" method="{1}"
class="com.ht.webapp.action.UserAction">
                                <result name="success">readUser</result>
                        </action>
                        
                        <!-- ******************************** EXPORT
********************************************* -->
                                                
                        <!-- Export -->
                        <action name="PDF" 
class="com.ht.webapp.action.JasperAction">
                                <result name="success" type="jasper">
                                        /jasper/Users.jasper
                                        myList
                                        PDF
                                </result>
                        </action>
                        <action name="HTML" 
class="com.ht.webapp.action.JasperAction">
                                <result name="success" type="jasper">
                                        /jasper/Users.jasper
                                        myList
                                        HTML
                                </result>
                        </action>
                        <action name="XML" 
class="com.ht.webapp.action.JasperAction">
                                <result name="success" type="jasper">
                                        /jasper/Users.jasper
                                        myList
                                        XML
                                </result>
                        </action>
                        <action name="CSV" 
class="com.ht.webapp.action.JasperAction">
                                <result name="success" type="jasper">
                                        /jasper/Users.jasper
                                        myList
                                        CSV
                                </result>
                        </action>
                        <action name="XLS" 
class="com.ht.webapp.action.JasperAction">
                                <result name="success" type="jasper">
                                        /jasper/Users.jasper
                                        myList
                                        XLS
                                </result>
                        </action>
                                
    </package>

</struts>
***********************************************************

and 

Here's my .jrxml
Users.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="Users"

                 columnCount="1"

                 printOrder="Vertical"

                 orientation="Portrait"

                 pageWidth="595"

                 pageHeight="842"

                 columnWidth="535"

                 columnSpacing="0"

                 leftMargin="30"

                 rightMargin="30"

                 topMargin="20"

                 bottomMargin="20"

                 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.*" />



        <parameter name="SUBREPORT_DIR" isForPrompting="false"
class="java.lang.String">

                <defaultValueExpression 
><![CDATA["\\jasper\\"]]></defaultValueExpression>

        </parameter>



        <field name="carro" class="java.lang.String">

                <fieldDescription><![CDATA[carro]]></fieldDescription>

        </field>

        <field name="dataNascimento" class="java.util.Date">

                <fieldDescription><![CDATA[dataNascimento]]></fieldDescription>

        </field>

        <field name="id" class="java.lang.Integer">

                <fieldDescription><![CDATA[id]]></fieldDescription>

        </field>

        <field name="moradas" class="java.util.List">

                <fieldDescription><![CDATA[moradas]]></fieldDescription>

        </field>

        <field name="nome" class="java.lang.String">

                <fieldDescription><![CDATA[nome]]></fieldDescription>

        </field>



                <background>

                        <band height="0"  isSplitAllowed="true" >

                        </band>

                </background>

                <title>

                        <band height="50"  isSplitAllowed="true" >

                        </band>

                </title>

                <pageHeader>

                        <band height="50"  isSplitAllowed="true" >

                        </band>

                </pageHeader>

                <columnHeader>

                        <band height="30"  isSplitAllowed="true" >

                        </band>

                </columnHeader>

                <detail>

                        <band height="255"  isSplitAllowed="true" >

                                <textField isStretchWithOverflow="false" 
isBlankWhenNull="false"
evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >

                                        <reportElement
                                                x="88"
                                                y="60"
                                                width="100"
                                                height="18"
                                                key="textField"/>

                                        <box></box>

                                        <textElement>

                                                

                                        </textElement>

                                <textFieldExpression  
class="java.lang.String"><![CDATA[$F{carro}]]></textFieldExpression>

                                </textField>

                                <textField isStretchWithOverflow="false" 
isBlankWhenNull="false"
evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >

                                        <reportElement
                                                x="88"
                                                y="42"
                                                width="100"
                                                height="18"
                                                key="textField"/>

                                        <box></box>

                                        <textElement>

                                                

                                        </textElement>

                                <textFieldExpression  
class="java.util.Date"><![CDATA[$F{dataNascimento}]]></textFieldExpression>

                                </textField>

                                <textField isStretchWithOverflow="false" 
isBlankWhenNull="false"
evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >

                                        <reportElement
                                                x="58"
                                                y="5"
                                                width="100"
                                                height="19"
                                                key="textField"/>

                                        <box></box>

                                        <textElement>

                                                

                                        </textElement>

                                <textFieldExpression  
class="java.lang.Integer"><![CDATA[$F{id}]]></textFieldExpression>

                                </textField>

                                <textField isStretchWithOverflow="false" 
isBlankWhenNull="false"
evaluationTime="Now" hyperlinkType="None"  hyperlinkTarget="Self" >

                                        <reportElement
                                                x="71"
                                                y="24"
                                                width="100"
                                                height="18"
                                                key="textField"/>

                                        <box></box>

                                        <textElement>

                                                

                                        </textElement>

                                <textFieldExpression  
class="java.lang.String"><![CDATA[$F{nome}]]></textFieldExpression>

                                </textField>

                                <staticText>

                                        <reportElement
                                                x="36"
                                                y="5"
                                                width="22"
                                                height="19"
                                                key="staticText-1"/>

                                        <box></box>

                                        <textElement>

                                                

                                        </textElement>

                                <text><![CDATA[ID:]]></text>

                                </staticText>

                                <staticText>

                                        <reportElement
                                                x="36"
                                                y="24"
                                                width="35"
                                                height="18"
                                                key="staticText-2"/>

                                        <box></box>

                                        <textElement>

                                                

                                        </textElement>

                                <text><![CDATA[Nome:]]></text>

                                </staticText>

                                <staticText>

                                        <reportElement
                                                x="36"
                                                y="42"
                                                width="52"
                                                height="18"
                                                key="staticText-3"/>

                                        <box></box>

                                        <textElement>

                                                

                                        </textElement>

                                <text><![CDATA[Data]]></text>

                                </staticText>

                                <staticText>

                                        <reportElement
                                                x="36"
                                                y="60"
                                                width="52"
                                                height="18"
                                                key="staticText-4"/>

                                        <box></box>

                                        <textElement>

                                                

                                        </textElement>

                                <text><![CDATA[Carro?]]></text>

                                </staticText>

                                <subreport  isUsingCache="true">

                                        <reportElement
                                                x="217"
                                                y="9"
                                                width="296"
                                                height="233"
                                                key="subreport-1"/>

                                        <dataSourceExpression><![CDATA[new
JRBeanCollectionDataSource($F{moradas})]]></dataSourceExpression>

                                        <subreportExpression 
class="java.net.URL"><![CDATA[getClass().getResource("/jasper/Users_subreport0.jasper")]]></subreportExpression>

                                </subreport>

                        </band>

                </detail>

                <columnFooter>

                        <band height="30"  isSplitAllowed="true" >

                        </band>

                </columnFooter>

                <pageFooter>

                        <band height="50"  isSplitAllowed="true" >

                        </band>

                </pageFooter>

                <lastPageFooter>

                        <band height="50"  isSplitAllowed="true" >

                        </band>

                </lastPageFooter>

                <summary>

                        <band height="50"  isSplitAllowed="true" >

                        </band>

                </summary>

</jasperReport>


***********************************************************
Users_subreport0.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="classic"

                 columnCount="1"

                 printOrder="Vertical"

                 orientation="Portrait"

                 pageWidth="535"

                 pageHeight="802"

                 columnWidth="535"

                 columnSpacing="0"

                 leftMargin="0"

                 rightMargin="0"

                 topMargin="0"

                 bottomMargin="0"

                 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="it.businesslogic.ireport.IReportScriptlet" />





        <field name="cidade" class="java.lang.String"/>

        <field name="cod_postal" class="java.lang.String"/>

        <field name="rua" 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="69"  isSplitAllowed="true" >

                                <textField isStretchWithOverflow="false" 
pattern=""
isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" 
hyperlinkTarget="Self" >

                                        <reportElement
                                                x="127"
                                                y="2"
                                                width="398"
                                                height="17"
                                                forecolor="#000000"
                                                backcolor="#FFFFFF"
                                                key="textField"/>

                                        <box>                                   
<topPen lineWidth="0.0" lineStyle="Solid"
lineColor="#000000"/>

                                        <leftPen lineWidth="0.0" 
lineStyle="Solid" lineColor="#000000"/>

                                        <bottomPen lineWidth="0.0" 
lineColor="#000000"/>

                                        <rightPen lineWidth="0.0" 
lineStyle="Solid" lineColor="#000000"/>

</box>

                                        <textElement textAlignment="Left" 
verticalAlignment="Top"
rotation="None" lineSpacing="Single">

                                                

                                        </textElement>

                                <textFieldExpression  
class="java.lang.String"><![CDATA[$F{cidade}]]></textFieldExpression>

                                </textField>

                                <staticText>

                                        <reportElement
                                                x="0"
                                                y="2"
                                                width="178"
                                                height="17"
                                                forecolor="#000000"
                                                backcolor="#FFFFFF"
                                                key="staticText"
                                                positionType="Float"/>

                                        <box>                                   
<topPen lineWidth="0.0" lineStyle="Solid"
lineColor="#000000"/>

                                        <leftPen lineWidth="0.0" 
lineStyle="Solid" lineColor="#000000"/>

                                        <bottomPen lineWidth="0.0" 
lineColor="#000000"/>

                                        <rightPen lineWidth="0.0" 
lineStyle="Solid" lineColor="#000000"/>

</box>

                                        <textElement textAlignment="Left" 
verticalAlignment="Top"
rotation="None" lineSpacing="Single">

                                                

                                        </textElement>

                                <text><![CDATA[cidade]]></text>

                                </staticText>

                                <textField isStretchWithOverflow="false" 
pattern=""
isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" 
hyperlinkTarget="Self" >

                                        <reportElement
                                                x="127"
                                                y="21"
                                                width="398"
                                                height="17"
                                                forecolor="#000000"
                                                backcolor="#FFFFFF"
                                                key="textField"/>

                                        <box>                                   
<topPen lineWidth="0.0" lineStyle="Solid"
lineColor="#000000"/>

                                        <leftPen lineWidth="0.0" 
lineStyle="Solid" lineColor="#000000"/>

                                        <bottomPen lineWidth="0.0" 
lineColor="#000000"/>

                                        <rightPen lineWidth="0.0" 
lineStyle="Solid" lineColor="#000000"/>

</box>

                                        <textElement textAlignment="Left" 
verticalAlignment="Top"
rotation="None" lineSpacing="Single">

                                                

                                        </textElement>

                                <textFieldExpression  
class="java.lang.String"><![CDATA[$F{cod_postal}]]></textFieldExpression>

                                </textField>

                                <staticText>

                                        <reportElement
                                                x="0"
                                                y="21"
                                                width="178"
                                                height="17"
                                                forecolor="#000000"
                                                backcolor="#FFFFFF"
                                                key="staticText"
                                                positionType="Float"/>

                                        <box>                                   
<topPen lineWidth="0.0" lineStyle="Solid"
lineColor="#000000"/>

                                        <leftPen lineWidth="0.0" 
lineStyle="Solid" lineColor="#000000"/>

                                        <bottomPen lineWidth="0.0" 
lineColor="#000000"/>

                                        <rightPen lineWidth="0.0" 
lineStyle="Solid" lineColor="#000000"/>

</box>

                                        <textElement textAlignment="Left" 
verticalAlignment="Top"
rotation="None" lineSpacing="Single">

                                                

                                        </textElement>

                                <text><![CDATA[cod_postal]]></text>

                                </staticText>

                                <textField isStretchWithOverflow="false" 
pattern=""
isBlankWhenNull="false" evaluationTime="Now" hyperlinkType="None" 
hyperlinkTarget="Self" >

                                        <reportElement
                                                x="127"
                                                y="40"
                                                width="398"
                                                height="17"
                                                forecolor="#000000"
                                                backcolor="#FFFFFF"
                                                key="textField"/>

                                        <box>                                   
<topPen lineWidth="0.0" lineStyle="Solid"
lineColor="#000000"/>

                                        <leftPen lineWidth="0.0" 
lineStyle="Solid" lineColor="#000000"/>

                                        <bottomPen lineWidth="0.0" 
lineColor="#000000"/>

                                        <rightPen lineWidth="0.0" 
lineStyle="Solid" lineColor="#000000"/>

</box>

                                        <textElement textAlignment="Left" 
verticalAlignment="Top"
rotation="None" lineSpacing="Single">

                                                

                                        </textElement>

                                <textFieldExpression  
class="java.lang.String"><![CDATA[$F{rua}]]></textFieldExpression>

                                </textField>

                                <staticText>

                                        <reportElement
                                                x="0"
                                                y="40"
                                                width="178"
                                                height="17"
                                                forecolor="#000000"
                                                backcolor="#FFFFFF"
                                                key="staticText"
                                                positionType="Float"/>

                                        <box>                                   
<topPen lineWidth="0.0" lineStyle="Solid"
lineColor="#000000"/>

                                        <leftPen lineWidth="0.0" 
lineStyle="Solid" lineColor="#000000"/>

                                        <bottomPen lineWidth="0.0" 
lineColor="#000000"/>

                                        <rightPen lineWidth="0.0" 
lineStyle="Solid" lineColor="#000000"/>

</box>

                                        <textElement textAlignment="Left" 
verticalAlignment="Top"
rotation="None" lineSpacing="Single">

                                                

                                        </textElement>

                                <text><![CDATA[rua]]></text>

                                </staticText>

                        </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>

***********************************************************


I'm sorry for this big post but i really need a solution....
-- 
View this message in context: 
http://www.nabble.com/Subreport-and-Struts2-problem-tp18336645p18336645.html
Sent from the jasperreports-questions mailing list archive at Nabble.com.


-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
jasperreports-questions mailing list
jasperreports-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jasperreports-questions

Reply via email to