carolino 13 de abr. de 2010
meu código que gera o relatório “no caso ele só vai imprimir o campo nome”
public class Relatorio {
@SuppressWarnings ( { "deprecation" , "unchecked" })
public void gerar ( String layout , List <?> list ) throws ClassNotFoundException ,
SQLException , JRException {
JasperDesign desenho = JRXmlLoader . load ( layout );
JasperReport relatorio = JasperCompileManager . compileReport ( desenho );
JRBeanCollectionDataSource jrRS = new JRBeanCollectionDataSource ( list );
Map parametros = new HashMap ();
parametros . put ( "nome" , jrRS );
JasperPrint impressao = JasperFillManager . fillReport ( relatorio ,
parametros , jrRS );
JasperViewer view = new JasperViewer ( impressao , false );
view . show ();
}
}
método que chama o método gerar para gerar relatórios
public void imprimirRelatorioVendedor () throws Exception {
String layout ;
ServletContext servletContext = ( ServletContext ) FacesContext . getCurrentInstance (). getExternalContext (). getContext ();
layout = servletContext . getRealPath ( "Relatorios/nomeRelatorio.jrxml" );
new Relatorio (). gerar ( layout , getVendedoresId ());
}
e na minha classe java a propriedade está como “String nome” mesmo…
e existe get/set para ele…
TheKill 13 de abr. de 2010
carolino:
meu código que gera o relatório “no caso ele só vai imprimir o campo nome”
public class Relatorio {
@SuppressWarnings ( { "deprecation" , "unchecked" })
public void gerar ( String layout , List <?> list ) throws ClassNotFoundException ,
SQLException , JRException {
JasperDesign desenho = JRXmlLoader . load ( layout );
JasperReport relatorio = JasperCompileManager . compileReport ( desenho );
JRBeanCollectionDataSource jrRS = new JRBeanCollectionDataSource ( list );
Map parametros = new HashMap ();
parametros . put ( "nome" , jrRS );
JasperPrint impressao = JasperFillManager . fillReport ( relatorio ,
parametros , jrRS );
JasperViewer view = new JasperViewer ( impressao , false );
view . show ();
}
}
Tipo, no iReport vc tem um List de String chamado Nome ?
Qual objeto vc tem lá?? Obs.: Deve ser um Parametro do tipo List de preferencia String
carolino 13 de abr. de 2010
então TheKill…
dentro do meu “nomeRelatorio.jrxml” tenho o campo que se refere a propriedade nome
<detail>
<band height= "100" isSplitAllowed= "true" >
<textField isStretchWithOverflow= "false" isBlankWhenNull= "false" evaluationTime= "Now" hyperlinkType= "None" hyperlinkTarget= "Self" >
<reportElement
x= "175"
y= "27"
width= "100"
height= "18"
key= "textField" />
<box></box>
<textElement>
<font/>
</textElement>
<textFieldExpression class= "java.lang.String" > <![CDATA[$F{nome}]]> </textFieldExpression>
</textField>
</band>
</detail>
TheKill 13 de abr. de 2010
perguntei se ele é Parameter, e qual tipo de parameter?
Ps.: vc esta mandando da aplicação um parametro… consecutivamente deve ter um objeto para receber o parametro no relatório…
att. Jonas