How to pass to column of a Dynamicreports the contents of a compound object. Datasource is a list of this object

Asked

Viewed 103 times

2

I’m making a report using Dynamicreports

For this I am passing a list to be used as Datasource

List<VisaoViagemQuadroMensal> linhas = new ArrayList<VisaoViagemQuadroMensal>();

where :

public class VisaoViagemQuadroMensal {

    public Linha linha;
    public List<VisaoViagemHorario> horarios;
    // get and set
}

public class Linha {

    private String linha;
    private String descricao;
    private Localidade localidadeDeOrigem;
    private Localidade lovalidadeDeDestino;
    // get and set
}

public class VisaoViagemHorario {
    protected HorarioDaViagem horario;
    protected Sentido sentido;
    protected List<Seccao> seccao;
    protected float km1;
    protected float km2;
    protected float km3;
    protected float kmReal;
    // get and set
}

The question is : When I create the Textcolumnbuilder object, how do I inform the Line description? Something like : lines.get(0). getLine(). getDescription();

Below method I create the report

protected JasperReportBuilder gerarRelatorio(Collection dataSource, String path, Map parametros) {
JasperReportBuilder report = DynamicReports.report();

// Nesta linha é que esta a duvida
TextColumnBuilder<String> colDescricao  = col.column("Descricao da Linha","???????????", type.stringType() ).setFixedWidth(40);

ImageBuilder imagemLogo = cmp.image( getClass().getResource("/imagens/logoFundoAzul.png") ).setFixedDimension(140, 28);
VerticalListBuilder listParametros = montaParametros(parametros); 

report
  .setPageFormat(PageType.A4, PageOrientation.LANDSCAPE)
  .setPageMargin(margin(20))
  .title(cmp.text("Parametros").setStyle(Estilos.CABECALHO_COLUNA_ESQUERDA.getEstilo()) , listParametros)
  .pageHeader( cmp.horizontalList( imagemLogo, cmp.text("Quadro Demonstrativo por Linhas").setStyle(Estilos.LABEL_TITULO.getEstilo()))).setPageHeaderStyle(Estilos.CABECALHO_PAGINA.getEstilo())
  .pageFooter(cmp.text("www.transportesalvorada.com.br").setStyle(Estilos.LABEL_RODAPE.getEstilo())).setPageFooterStyle(Estilos.CABECALHO_PAGINA.getEstilo())

  .setColumnTitleStyle(Estilos.CABECALHO_COLUNA_ESQUERDA.getEstilo())

  .detail()
     .columns(colDescricao.setStyle(Estilos.LINHA_TOPO.getEstilo())  )
     .highlightDetailEvenRows()

   .setDataSource(new JRBeanCollectionDataSource(dataSource));

    //report = report.addProperty(JasperProperty.EXPORT_XLS_FREEZE_ROW, "2");
return report;

}

1 answer

1


To whom it may interest, after a lot of testing and analyzing the source, I did as the JSF EL, I removed the get when mounting the object column.

Where in java I do so:

linhas.get(0).getLinha().getLinha();
linhas.get(0).getLinha().getDescricao();

In Textcolumnbuilder I do so:

linha.linha
linha.descricao

Thus remaining:

TextColumnBuilder<String> colLinhaCodigo    = col.column("Linha"      ,"linha.linha"    , type.stringType() ).setFixedWidth(30);
TextColumnBuilder<String> colLinhaDescricao = col.column("Descrição"  ,"linha.descricao"    , type.stringType() ).setFixedWidth(100);
  • 1

    Marcelo, if this solved your problem can mark the question as accepted so facilitate to others who have the same question and enter the post.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.