JasperReport - Using DynamicJasper after having a lot of JRXML reports built












0















JasperReport - Using DynamicJasper after having a lot of JRXML reports built



Problem Overview



Currently my java software uses compiled .jrxml files to generate reports. However, the users are complaining that they want to customize the reports. Which is basically So I found out about DynamicJasper. The problem is that the ready-to-use .jasper reports that I previously Built has their own layout which I ended up adjusting, inserting image placeholders for logos that are sent via parameters.





QUESTION



Is there a way to either copy the style or re-use these previously built report layouts in a simple way?





As far as I remember, I built those reports using the Jasper template called Cherry . And For some I used landscape and for others I used portrait type.





I Dont think this question is a duplicate due to the constraints of the problem itself: I cant rebuild every report to be DynamicJasper nor I can change the layour aggressively.



References



How to use jrxml file as design template in DynamicJasper



How to get same styles in DynamicReports and JasperReports










share|improve this question

























  • Quite interesting how you vote to close the question but dont even comment on it.

    – KenobiShan
    Nov 28 '18 at 20:13






  • 1





    I ended up creating the templates in Java code instead. I don't think there is a 'simple way' as what you're asking is about integrating the two. Check dynamicjasper.com/docs/current/xref-test/ar/com/fdvs/dj/test/… for ways of doing this, surely integrating will be just as time consuming as building them to be properly dynamic

    – juju
    Dec 3 '18 at 11:35






  • 1





    There is another way That I found out. I will post an answer later today. But thanks for the comment :)

    – KenobiShan
    Dec 3 '18 at 11:39






  • 1





    I would be very interested in that cheers

    – juju
    Dec 3 '18 at 11:40
















0















JasperReport - Using DynamicJasper after having a lot of JRXML reports built



Problem Overview



Currently my java software uses compiled .jrxml files to generate reports. However, the users are complaining that they want to customize the reports. Which is basically So I found out about DynamicJasper. The problem is that the ready-to-use .jasper reports that I previously Built has their own layout which I ended up adjusting, inserting image placeholders for logos that are sent via parameters.





QUESTION



Is there a way to either copy the style or re-use these previously built report layouts in a simple way?





As far as I remember, I built those reports using the Jasper template called Cherry . And For some I used landscape and for others I used portrait type.





I Dont think this question is a duplicate due to the constraints of the problem itself: I cant rebuild every report to be DynamicJasper nor I can change the layour aggressively.



References



How to use jrxml file as design template in DynamicJasper



How to get same styles in DynamicReports and JasperReports










share|improve this question

























  • Quite interesting how you vote to close the question but dont even comment on it.

    – KenobiShan
    Nov 28 '18 at 20:13






  • 1





    I ended up creating the templates in Java code instead. I don't think there is a 'simple way' as what you're asking is about integrating the two. Check dynamicjasper.com/docs/current/xref-test/ar/com/fdvs/dj/test/… for ways of doing this, surely integrating will be just as time consuming as building them to be properly dynamic

    – juju
    Dec 3 '18 at 11:35






  • 1





    There is another way That I found out. I will post an answer later today. But thanks for the comment :)

    – KenobiShan
    Dec 3 '18 at 11:39






  • 1





    I would be very interested in that cheers

    – juju
    Dec 3 '18 at 11:40














0












0








0


1






JasperReport - Using DynamicJasper after having a lot of JRXML reports built



Problem Overview



Currently my java software uses compiled .jrxml files to generate reports. However, the users are complaining that they want to customize the reports. Which is basically So I found out about DynamicJasper. The problem is that the ready-to-use .jasper reports that I previously Built has their own layout which I ended up adjusting, inserting image placeholders for logos that are sent via parameters.





QUESTION



Is there a way to either copy the style or re-use these previously built report layouts in a simple way?





As far as I remember, I built those reports using the Jasper template called Cherry . And For some I used landscape and for others I used portrait type.





I Dont think this question is a duplicate due to the constraints of the problem itself: I cant rebuild every report to be DynamicJasper nor I can change the layour aggressively.



References



How to use jrxml file as design template in DynamicJasper



How to get same styles in DynamicReports and JasperReports










share|improve this question
















JasperReport - Using DynamicJasper after having a lot of JRXML reports built



Problem Overview



Currently my java software uses compiled .jrxml files to generate reports. However, the users are complaining that they want to customize the reports. Which is basically So I found out about DynamicJasper. The problem is that the ready-to-use .jasper reports that I previously Built has their own layout which I ended up adjusting, inserting image placeholders for logos that are sent via parameters.





QUESTION



Is there a way to either copy the style or re-use these previously built report layouts in a simple way?





As far as I remember, I built those reports using the Jasper template called Cherry . And For some I used landscape and for others I used portrait type.





I Dont think this question is a duplicate due to the constraints of the problem itself: I cant rebuild every report to be DynamicJasper nor I can change the layour aggressively.



References



How to use jrxml file as design template in DynamicJasper



How to get same styles in DynamicReports and JasperReports







jasper-reports dynamic-jasper






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 28 '18 at 20:01







KenobiShan

















asked Nov 28 '18 at 18:39









KenobiShanKenobiShan

2391527




2391527













  • Quite interesting how you vote to close the question but dont even comment on it.

    – KenobiShan
    Nov 28 '18 at 20:13






  • 1





    I ended up creating the templates in Java code instead. I don't think there is a 'simple way' as what you're asking is about integrating the two. Check dynamicjasper.com/docs/current/xref-test/ar/com/fdvs/dj/test/… for ways of doing this, surely integrating will be just as time consuming as building them to be properly dynamic

    – juju
    Dec 3 '18 at 11:35






  • 1





    There is another way That I found out. I will post an answer later today. But thanks for the comment :)

    – KenobiShan
    Dec 3 '18 at 11:39






  • 1





    I would be very interested in that cheers

    – juju
    Dec 3 '18 at 11:40



















  • Quite interesting how you vote to close the question but dont even comment on it.

    – KenobiShan
    Nov 28 '18 at 20:13






  • 1





    I ended up creating the templates in Java code instead. I don't think there is a 'simple way' as what you're asking is about integrating the two. Check dynamicjasper.com/docs/current/xref-test/ar/com/fdvs/dj/test/… for ways of doing this, surely integrating will be just as time consuming as building them to be properly dynamic

    – juju
    Dec 3 '18 at 11:35






  • 1





    There is another way That I found out. I will post an answer later today. But thanks for the comment :)

    – KenobiShan
    Dec 3 '18 at 11:39






  • 1





    I would be very interested in that cheers

    – juju
    Dec 3 '18 at 11:40

















Quite interesting how you vote to close the question but dont even comment on it.

– KenobiShan
Nov 28 '18 at 20:13





Quite interesting how you vote to close the question but dont even comment on it.

– KenobiShan
Nov 28 '18 at 20:13




1




1





I ended up creating the templates in Java code instead. I don't think there is a 'simple way' as what you're asking is about integrating the two. Check dynamicjasper.com/docs/current/xref-test/ar/com/fdvs/dj/test/… for ways of doing this, surely integrating will be just as time consuming as building them to be properly dynamic

– juju
Dec 3 '18 at 11:35





I ended up creating the templates in Java code instead. I don't think there is a 'simple way' as what you're asking is about integrating the two. Check dynamicjasper.com/docs/current/xref-test/ar/com/fdvs/dj/test/… for ways of doing this, surely integrating will be just as time consuming as building them to be properly dynamic

– juju
Dec 3 '18 at 11:35




1




1





There is another way That I found out. I will post an answer later today. But thanks for the comment :)

– KenobiShan
Dec 3 '18 at 11:39





There is another way That I found out. I will post an answer later today. But thanks for the comment :)

– KenobiShan
Dec 3 '18 at 11:39




1




1





I would be very interested in that cheers

– juju
Dec 3 '18 at 11:40





I would be very interested in that cheers

– juju
Dec 3 '18 at 11:40












1 Answer
1






active

oldest

votes


















1














So to answer my own question, here's a recipe.



1º You take your jrxml and clean it according to :
http://dynamicjasper.com/2010/10/06/how-to-use-custom-jrxml-templates/



Which basically requires:




  • The template must not have groups, DynamicJAsper will create them if
    necessary.


  • The detail band must be empty: DynamicJasper will work in the detail
    band, any previously existing element will be deleted.


  • One template per page size and orientation will be needed: This is

    because DJ knows how to arrange the element he creates, but not the

    existing ones.



2º You call setTemplateFile method:



 public DynamicReportBuilder setTemplateFile(String path,
boolean importFields,
boolean importVariables,
boolean importParameters,
boolean importDatasets)


With the required boolean flags. Those boolean flags will allow you to load or not load the parameters,fields,variables and dataset that you set on your jrxml.



And below I attach a mock example. However, you are going to need your own jrxml file to test.



public class TestReport {

protected static JasperPrint jp;
protected static JasperReport jr;
protected static Map params = new HashMap();
protected static DynamicReport dr;

public static void main(String args) throws SQLException, ColumnBuilderException, ClassNotFoundException {

TestReport t = new TestReport();
t.createReport();

}

public void createReport() throws SQLException, ColumnBuilderException, ClassNotFoundException {

ArrayList<Fruit> createMockDataset = createMockDataset();

Style titleStyle = new Style();
titleStyle.setHorizontalAlign(HorizontalAlign.CENTER);
titleStyle.setFont(Font.ARIAL_SMALL_BOLD);

Style dataStyle = new Style();
dataStyle.setHorizontalAlign(HorizontalAlign.CENTER);
dataStyle.setFont(Font.ARIAL_SMALL);
dataStyle.setBlankWhenNull(true);

final List items = SortUtils.sortCollection(createMockDataset, Arrays.asList(new String{"name", "description"}));

FastReportBuilder drb = new FastReportBuilder();
drb.setTemplateFile("templatePortrait.jrxml", true, true, true, true);
drb.addColumn("name", "name", String.class.getName(), 30, dataStyle)
.addColumn("description", "description", String.class.getName(), 50, dataStyle)
.setTitle("Report")
.setSubtitle("")
.setPrintBackgroundOnOddRows(true)
.setUseFullPageWidth(true);



DynamicReport dynamicReport = drb.build();

dynamicReport.setTitleStyle(titleStyle);

HashMap parametros = new HashMap();
parametros.put("dataRelatorio", MyTools.getDataPorExtenso());

doReport(dynamicReport, items, parametros);
}

public void doReport(final DynamicReport _report, final Collection _data, HashMap parametros) {
try {
JRDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(_data);

JasperPrint jasperPrint = DynamicJasperHelper.generateJasperPrint(_report, new ClassicLayoutManager(), beanCollectionDataSource, parametros);

JasperViewer.viewReport(jasperPrint);
} catch (JRException ex) {
ex.printStackTrace();
}
}


public ArrayList<Fruit> createMockDataset() {
ArrayList<Fruit> fruits = new ArrayList<>();

Fruit f1 = new Fruit();
f1.name = "Apple X1";
f1.description = "Yummy yummy apple for the stackoverflow readers 1";

Fruit f2 = new Fruit();
f2.name = "Apple Ag";
f2.description = "Yummy yummy apple for the stackoverflow readers 2";

Fruit f3 = new Fruit();
f3.name = "Apple Mn";
f3.description = "Yummy yummy apple for the stackoverflow readers 3";

Fruit f4 = new Fruit();
f4.name = "Apple O2";
f4.description = "Yummy yummy apple for the stackoverflow readers 4";

//Evaluations for f1
for (int i = 0; i < 4; i++) {
Evaluation e = new Evaluation();
e.id = i;
e.score = Math.random() * 10;
f1.evaluations.add(e);
}

//evaluations for f4
for (int i = 0; i < 4; i++) {
Evaluation e = new Evaluation();
e.id = i;
e.score = Math.random() * 10;
f4.evaluations.add(e);
}

fruits.add(f1);
fruits.add(f2);
fruits.add(f3);
fruits.add(f4);

return fruits;

}

public class Fruit {

public String name;
public String description;
public ArrayList<Evaluation> evaluations = new ArrayList<Evaluation>();

public Fruit() {

}

public Fruit(String name, String description) {
this.name = name;
this.description = description;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public ArrayList<Evaluation> getEvaluations() {
return evaluations;
}

public void setEvaluations(ArrayList<Evaluation> evaluations) {
this.evaluations = evaluations;
}

}

public class Evaluation {

public int id;
public double score;

public Evaluation() {

}

public Evaluation(int id, double score) {
this.id = id;
this.score = score;
}

public int getId() {
return id;
}

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

public double getScore() {
return score;
}

public void setScore(double score) {
this.score = score;
}

}

}





share|improve this answer
























  • thanks for this! any ideas on this

    – juju
    Feb 18 at 21:19












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526035%2fjasperreport-using-dynamicjasper-after-having-a-lot-of-jrxml-reports-built%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














So to answer my own question, here's a recipe.



1º You take your jrxml and clean it according to :
http://dynamicjasper.com/2010/10/06/how-to-use-custom-jrxml-templates/



Which basically requires:




  • The template must not have groups, DynamicJAsper will create them if
    necessary.


  • The detail band must be empty: DynamicJasper will work in the detail
    band, any previously existing element will be deleted.


  • One template per page size and orientation will be needed: This is

    because DJ knows how to arrange the element he creates, but not the

    existing ones.



2º You call setTemplateFile method:



 public DynamicReportBuilder setTemplateFile(String path,
boolean importFields,
boolean importVariables,
boolean importParameters,
boolean importDatasets)


With the required boolean flags. Those boolean flags will allow you to load or not load the parameters,fields,variables and dataset that you set on your jrxml.



And below I attach a mock example. However, you are going to need your own jrxml file to test.



public class TestReport {

protected static JasperPrint jp;
protected static JasperReport jr;
protected static Map params = new HashMap();
protected static DynamicReport dr;

public static void main(String args) throws SQLException, ColumnBuilderException, ClassNotFoundException {

TestReport t = new TestReport();
t.createReport();

}

public void createReport() throws SQLException, ColumnBuilderException, ClassNotFoundException {

ArrayList<Fruit> createMockDataset = createMockDataset();

Style titleStyle = new Style();
titleStyle.setHorizontalAlign(HorizontalAlign.CENTER);
titleStyle.setFont(Font.ARIAL_SMALL_BOLD);

Style dataStyle = new Style();
dataStyle.setHorizontalAlign(HorizontalAlign.CENTER);
dataStyle.setFont(Font.ARIAL_SMALL);
dataStyle.setBlankWhenNull(true);

final List items = SortUtils.sortCollection(createMockDataset, Arrays.asList(new String{"name", "description"}));

FastReportBuilder drb = new FastReportBuilder();
drb.setTemplateFile("templatePortrait.jrxml", true, true, true, true);
drb.addColumn("name", "name", String.class.getName(), 30, dataStyle)
.addColumn("description", "description", String.class.getName(), 50, dataStyle)
.setTitle("Report")
.setSubtitle("")
.setPrintBackgroundOnOddRows(true)
.setUseFullPageWidth(true);



DynamicReport dynamicReport = drb.build();

dynamicReport.setTitleStyle(titleStyle);

HashMap parametros = new HashMap();
parametros.put("dataRelatorio", MyTools.getDataPorExtenso());

doReport(dynamicReport, items, parametros);
}

public void doReport(final DynamicReport _report, final Collection _data, HashMap parametros) {
try {
JRDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(_data);

JasperPrint jasperPrint = DynamicJasperHelper.generateJasperPrint(_report, new ClassicLayoutManager(), beanCollectionDataSource, parametros);

JasperViewer.viewReport(jasperPrint);
} catch (JRException ex) {
ex.printStackTrace();
}
}


public ArrayList<Fruit> createMockDataset() {
ArrayList<Fruit> fruits = new ArrayList<>();

Fruit f1 = new Fruit();
f1.name = "Apple X1";
f1.description = "Yummy yummy apple for the stackoverflow readers 1";

Fruit f2 = new Fruit();
f2.name = "Apple Ag";
f2.description = "Yummy yummy apple for the stackoverflow readers 2";

Fruit f3 = new Fruit();
f3.name = "Apple Mn";
f3.description = "Yummy yummy apple for the stackoverflow readers 3";

Fruit f4 = new Fruit();
f4.name = "Apple O2";
f4.description = "Yummy yummy apple for the stackoverflow readers 4";

//Evaluations for f1
for (int i = 0; i < 4; i++) {
Evaluation e = new Evaluation();
e.id = i;
e.score = Math.random() * 10;
f1.evaluations.add(e);
}

//evaluations for f4
for (int i = 0; i < 4; i++) {
Evaluation e = new Evaluation();
e.id = i;
e.score = Math.random() * 10;
f4.evaluations.add(e);
}

fruits.add(f1);
fruits.add(f2);
fruits.add(f3);
fruits.add(f4);

return fruits;

}

public class Fruit {

public String name;
public String description;
public ArrayList<Evaluation> evaluations = new ArrayList<Evaluation>();

public Fruit() {

}

public Fruit(String name, String description) {
this.name = name;
this.description = description;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public ArrayList<Evaluation> getEvaluations() {
return evaluations;
}

public void setEvaluations(ArrayList<Evaluation> evaluations) {
this.evaluations = evaluations;
}

}

public class Evaluation {

public int id;
public double score;

public Evaluation() {

}

public Evaluation(int id, double score) {
this.id = id;
this.score = score;
}

public int getId() {
return id;
}

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

public double getScore() {
return score;
}

public void setScore(double score) {
this.score = score;
}

}

}





share|improve this answer
























  • thanks for this! any ideas on this

    – juju
    Feb 18 at 21:19
















1














So to answer my own question, here's a recipe.



1º You take your jrxml and clean it according to :
http://dynamicjasper.com/2010/10/06/how-to-use-custom-jrxml-templates/



Which basically requires:




  • The template must not have groups, DynamicJAsper will create them if
    necessary.


  • The detail band must be empty: DynamicJasper will work in the detail
    band, any previously existing element will be deleted.


  • One template per page size and orientation will be needed: This is

    because DJ knows how to arrange the element he creates, but not the

    existing ones.



2º You call setTemplateFile method:



 public DynamicReportBuilder setTemplateFile(String path,
boolean importFields,
boolean importVariables,
boolean importParameters,
boolean importDatasets)


With the required boolean flags. Those boolean flags will allow you to load or not load the parameters,fields,variables and dataset that you set on your jrxml.



And below I attach a mock example. However, you are going to need your own jrxml file to test.



public class TestReport {

protected static JasperPrint jp;
protected static JasperReport jr;
protected static Map params = new HashMap();
protected static DynamicReport dr;

public static void main(String args) throws SQLException, ColumnBuilderException, ClassNotFoundException {

TestReport t = new TestReport();
t.createReport();

}

public void createReport() throws SQLException, ColumnBuilderException, ClassNotFoundException {

ArrayList<Fruit> createMockDataset = createMockDataset();

Style titleStyle = new Style();
titleStyle.setHorizontalAlign(HorizontalAlign.CENTER);
titleStyle.setFont(Font.ARIAL_SMALL_BOLD);

Style dataStyle = new Style();
dataStyle.setHorizontalAlign(HorizontalAlign.CENTER);
dataStyle.setFont(Font.ARIAL_SMALL);
dataStyle.setBlankWhenNull(true);

final List items = SortUtils.sortCollection(createMockDataset, Arrays.asList(new String{"name", "description"}));

FastReportBuilder drb = new FastReportBuilder();
drb.setTemplateFile("templatePortrait.jrxml", true, true, true, true);
drb.addColumn("name", "name", String.class.getName(), 30, dataStyle)
.addColumn("description", "description", String.class.getName(), 50, dataStyle)
.setTitle("Report")
.setSubtitle("")
.setPrintBackgroundOnOddRows(true)
.setUseFullPageWidth(true);



DynamicReport dynamicReport = drb.build();

dynamicReport.setTitleStyle(titleStyle);

HashMap parametros = new HashMap();
parametros.put("dataRelatorio", MyTools.getDataPorExtenso());

doReport(dynamicReport, items, parametros);
}

public void doReport(final DynamicReport _report, final Collection _data, HashMap parametros) {
try {
JRDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(_data);

JasperPrint jasperPrint = DynamicJasperHelper.generateJasperPrint(_report, new ClassicLayoutManager(), beanCollectionDataSource, parametros);

JasperViewer.viewReport(jasperPrint);
} catch (JRException ex) {
ex.printStackTrace();
}
}


public ArrayList<Fruit> createMockDataset() {
ArrayList<Fruit> fruits = new ArrayList<>();

Fruit f1 = new Fruit();
f1.name = "Apple X1";
f1.description = "Yummy yummy apple for the stackoverflow readers 1";

Fruit f2 = new Fruit();
f2.name = "Apple Ag";
f2.description = "Yummy yummy apple for the stackoverflow readers 2";

Fruit f3 = new Fruit();
f3.name = "Apple Mn";
f3.description = "Yummy yummy apple for the stackoverflow readers 3";

Fruit f4 = new Fruit();
f4.name = "Apple O2";
f4.description = "Yummy yummy apple for the stackoverflow readers 4";

//Evaluations for f1
for (int i = 0; i < 4; i++) {
Evaluation e = new Evaluation();
e.id = i;
e.score = Math.random() * 10;
f1.evaluations.add(e);
}

//evaluations for f4
for (int i = 0; i < 4; i++) {
Evaluation e = new Evaluation();
e.id = i;
e.score = Math.random() * 10;
f4.evaluations.add(e);
}

fruits.add(f1);
fruits.add(f2);
fruits.add(f3);
fruits.add(f4);

return fruits;

}

public class Fruit {

public String name;
public String description;
public ArrayList<Evaluation> evaluations = new ArrayList<Evaluation>();

public Fruit() {

}

public Fruit(String name, String description) {
this.name = name;
this.description = description;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public ArrayList<Evaluation> getEvaluations() {
return evaluations;
}

public void setEvaluations(ArrayList<Evaluation> evaluations) {
this.evaluations = evaluations;
}

}

public class Evaluation {

public int id;
public double score;

public Evaluation() {

}

public Evaluation(int id, double score) {
this.id = id;
this.score = score;
}

public int getId() {
return id;
}

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

public double getScore() {
return score;
}

public void setScore(double score) {
this.score = score;
}

}

}





share|improve this answer
























  • thanks for this! any ideas on this

    – juju
    Feb 18 at 21:19














1












1








1







So to answer my own question, here's a recipe.



1º You take your jrxml and clean it according to :
http://dynamicjasper.com/2010/10/06/how-to-use-custom-jrxml-templates/



Which basically requires:




  • The template must not have groups, DynamicJAsper will create them if
    necessary.


  • The detail band must be empty: DynamicJasper will work in the detail
    band, any previously existing element will be deleted.


  • One template per page size and orientation will be needed: This is

    because DJ knows how to arrange the element he creates, but not the

    existing ones.



2º You call setTemplateFile method:



 public DynamicReportBuilder setTemplateFile(String path,
boolean importFields,
boolean importVariables,
boolean importParameters,
boolean importDatasets)


With the required boolean flags. Those boolean flags will allow you to load or not load the parameters,fields,variables and dataset that you set on your jrxml.



And below I attach a mock example. However, you are going to need your own jrxml file to test.



public class TestReport {

protected static JasperPrint jp;
protected static JasperReport jr;
protected static Map params = new HashMap();
protected static DynamicReport dr;

public static void main(String args) throws SQLException, ColumnBuilderException, ClassNotFoundException {

TestReport t = new TestReport();
t.createReport();

}

public void createReport() throws SQLException, ColumnBuilderException, ClassNotFoundException {

ArrayList<Fruit> createMockDataset = createMockDataset();

Style titleStyle = new Style();
titleStyle.setHorizontalAlign(HorizontalAlign.CENTER);
titleStyle.setFont(Font.ARIAL_SMALL_BOLD);

Style dataStyle = new Style();
dataStyle.setHorizontalAlign(HorizontalAlign.CENTER);
dataStyle.setFont(Font.ARIAL_SMALL);
dataStyle.setBlankWhenNull(true);

final List items = SortUtils.sortCollection(createMockDataset, Arrays.asList(new String{"name", "description"}));

FastReportBuilder drb = new FastReportBuilder();
drb.setTemplateFile("templatePortrait.jrxml", true, true, true, true);
drb.addColumn("name", "name", String.class.getName(), 30, dataStyle)
.addColumn("description", "description", String.class.getName(), 50, dataStyle)
.setTitle("Report")
.setSubtitle("")
.setPrintBackgroundOnOddRows(true)
.setUseFullPageWidth(true);



DynamicReport dynamicReport = drb.build();

dynamicReport.setTitleStyle(titleStyle);

HashMap parametros = new HashMap();
parametros.put("dataRelatorio", MyTools.getDataPorExtenso());

doReport(dynamicReport, items, parametros);
}

public void doReport(final DynamicReport _report, final Collection _data, HashMap parametros) {
try {
JRDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(_data);

JasperPrint jasperPrint = DynamicJasperHelper.generateJasperPrint(_report, new ClassicLayoutManager(), beanCollectionDataSource, parametros);

JasperViewer.viewReport(jasperPrint);
} catch (JRException ex) {
ex.printStackTrace();
}
}


public ArrayList<Fruit> createMockDataset() {
ArrayList<Fruit> fruits = new ArrayList<>();

Fruit f1 = new Fruit();
f1.name = "Apple X1";
f1.description = "Yummy yummy apple for the stackoverflow readers 1";

Fruit f2 = new Fruit();
f2.name = "Apple Ag";
f2.description = "Yummy yummy apple for the stackoverflow readers 2";

Fruit f3 = new Fruit();
f3.name = "Apple Mn";
f3.description = "Yummy yummy apple for the stackoverflow readers 3";

Fruit f4 = new Fruit();
f4.name = "Apple O2";
f4.description = "Yummy yummy apple for the stackoverflow readers 4";

//Evaluations for f1
for (int i = 0; i < 4; i++) {
Evaluation e = new Evaluation();
e.id = i;
e.score = Math.random() * 10;
f1.evaluations.add(e);
}

//evaluations for f4
for (int i = 0; i < 4; i++) {
Evaluation e = new Evaluation();
e.id = i;
e.score = Math.random() * 10;
f4.evaluations.add(e);
}

fruits.add(f1);
fruits.add(f2);
fruits.add(f3);
fruits.add(f4);

return fruits;

}

public class Fruit {

public String name;
public String description;
public ArrayList<Evaluation> evaluations = new ArrayList<Evaluation>();

public Fruit() {

}

public Fruit(String name, String description) {
this.name = name;
this.description = description;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public ArrayList<Evaluation> getEvaluations() {
return evaluations;
}

public void setEvaluations(ArrayList<Evaluation> evaluations) {
this.evaluations = evaluations;
}

}

public class Evaluation {

public int id;
public double score;

public Evaluation() {

}

public Evaluation(int id, double score) {
this.id = id;
this.score = score;
}

public int getId() {
return id;
}

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

public double getScore() {
return score;
}

public void setScore(double score) {
this.score = score;
}

}

}





share|improve this answer













So to answer my own question, here's a recipe.



1º You take your jrxml and clean it according to :
http://dynamicjasper.com/2010/10/06/how-to-use-custom-jrxml-templates/



Which basically requires:




  • The template must not have groups, DynamicJAsper will create them if
    necessary.


  • The detail band must be empty: DynamicJasper will work in the detail
    band, any previously existing element will be deleted.


  • One template per page size and orientation will be needed: This is

    because DJ knows how to arrange the element he creates, but not the

    existing ones.



2º You call setTemplateFile method:



 public DynamicReportBuilder setTemplateFile(String path,
boolean importFields,
boolean importVariables,
boolean importParameters,
boolean importDatasets)


With the required boolean flags. Those boolean flags will allow you to load or not load the parameters,fields,variables and dataset that you set on your jrxml.



And below I attach a mock example. However, you are going to need your own jrxml file to test.



public class TestReport {

protected static JasperPrint jp;
protected static JasperReport jr;
protected static Map params = new HashMap();
protected static DynamicReport dr;

public static void main(String args) throws SQLException, ColumnBuilderException, ClassNotFoundException {

TestReport t = new TestReport();
t.createReport();

}

public void createReport() throws SQLException, ColumnBuilderException, ClassNotFoundException {

ArrayList<Fruit> createMockDataset = createMockDataset();

Style titleStyle = new Style();
titleStyle.setHorizontalAlign(HorizontalAlign.CENTER);
titleStyle.setFont(Font.ARIAL_SMALL_BOLD);

Style dataStyle = new Style();
dataStyle.setHorizontalAlign(HorizontalAlign.CENTER);
dataStyle.setFont(Font.ARIAL_SMALL);
dataStyle.setBlankWhenNull(true);

final List items = SortUtils.sortCollection(createMockDataset, Arrays.asList(new String{"name", "description"}));

FastReportBuilder drb = new FastReportBuilder();
drb.setTemplateFile("templatePortrait.jrxml", true, true, true, true);
drb.addColumn("name", "name", String.class.getName(), 30, dataStyle)
.addColumn("description", "description", String.class.getName(), 50, dataStyle)
.setTitle("Report")
.setSubtitle("")
.setPrintBackgroundOnOddRows(true)
.setUseFullPageWidth(true);



DynamicReport dynamicReport = drb.build();

dynamicReport.setTitleStyle(titleStyle);

HashMap parametros = new HashMap();
parametros.put("dataRelatorio", MyTools.getDataPorExtenso());

doReport(dynamicReport, items, parametros);
}

public void doReport(final DynamicReport _report, final Collection _data, HashMap parametros) {
try {
JRDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(_data);

JasperPrint jasperPrint = DynamicJasperHelper.generateJasperPrint(_report, new ClassicLayoutManager(), beanCollectionDataSource, parametros);

JasperViewer.viewReport(jasperPrint);
} catch (JRException ex) {
ex.printStackTrace();
}
}


public ArrayList<Fruit> createMockDataset() {
ArrayList<Fruit> fruits = new ArrayList<>();

Fruit f1 = new Fruit();
f1.name = "Apple X1";
f1.description = "Yummy yummy apple for the stackoverflow readers 1";

Fruit f2 = new Fruit();
f2.name = "Apple Ag";
f2.description = "Yummy yummy apple for the stackoverflow readers 2";

Fruit f3 = new Fruit();
f3.name = "Apple Mn";
f3.description = "Yummy yummy apple for the stackoverflow readers 3";

Fruit f4 = new Fruit();
f4.name = "Apple O2";
f4.description = "Yummy yummy apple for the stackoverflow readers 4";

//Evaluations for f1
for (int i = 0; i < 4; i++) {
Evaluation e = new Evaluation();
e.id = i;
e.score = Math.random() * 10;
f1.evaluations.add(e);
}

//evaluations for f4
for (int i = 0; i < 4; i++) {
Evaluation e = new Evaluation();
e.id = i;
e.score = Math.random() * 10;
f4.evaluations.add(e);
}

fruits.add(f1);
fruits.add(f2);
fruits.add(f3);
fruits.add(f4);

return fruits;

}

public class Fruit {

public String name;
public String description;
public ArrayList<Evaluation> evaluations = new ArrayList<Evaluation>();

public Fruit() {

}

public Fruit(String name, String description) {
this.name = name;
this.description = description;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public ArrayList<Evaluation> getEvaluations() {
return evaluations;
}

public void setEvaluations(ArrayList<Evaluation> evaluations) {
this.evaluations = evaluations;
}

}

public class Evaluation {

public int id;
public double score;

public Evaluation() {

}

public Evaluation(int id, double score) {
this.id = id;
this.score = score;
}

public int getId() {
return id;
}

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

public double getScore() {
return score;
}

public void setScore(double score) {
this.score = score;
}

}

}






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 4 '18 at 14:55









KenobiShanKenobiShan

2391527




2391527













  • thanks for this! any ideas on this

    – juju
    Feb 18 at 21:19



















  • thanks for this! any ideas on this

    – juju
    Feb 18 at 21:19

















thanks for this! any ideas on this

– juju
Feb 18 at 21:19





thanks for this! any ideas on this

– juju
Feb 18 at 21:19




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53526035%2fjasperreport-using-dynamicjasper-after-having-a-lot-of-jrxml-reports-built%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks