Jump to content
We've recently updated our Privacy Statement, available here ×

Change Page Height dynamically during runtime


cheeka

Recommended Posts

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

 

I think this would require you to dinamically modify the report template and probably recompile it on-the-fly.

This is because when changing the page size, you would also need to move content around to better fit into the new page layout. And layout changes requires report template re-validation, thus forcing a recompile.

 

Report compilation at runtime should not be an issue anymore since the JDT-based compiler is pretty fast and does not require any special configuration, just making sure the jdt-compiler.jar is in the classpath.

 

You would load a JasperDesign object, use the JasperReports API to make modifications on it, compile it and then fill it with data.

 

You can take a look at our /demo/samples/alterdesign sample provided with the project, but note that it only shows what modifications could be made on a compiled report template without need for re-compilation. But it will give you an idea about how modifications could be made on a report using the API.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

I ve been working on a case similar to this.I m trying to find a way to change the height value of any element or band, in RUNTIME. Can i use any method something like textField-5.setHeight="20" .So far i couldn't make it.

 

by now i m able to design a report which generates the varying elements using conditional expresions with parameters and printWhen expressions.

 

But i need to modify ALL element attiributes during RUNTIME according to data. I wonder if it is possible to have one element that can be modified completely in runtime by using scriptlets methods like beforeColumnInit();

 

Any idea, comment or solution is appreciated.

 

Thanks.:blush:

 

Post edited by: SoS, at: 2006/07/27 08:51

Post edited by: SoS, at: 2006/07/27 10:29

Link to comment
Share on other sites

Hi,

 

There are two types of modifications that can be made on a report template.

 

1. Modifications that do not require validation or report compilation.

Such modification is changing the color of an element, or changing its X coordinate or the width. The color, the X position and the width are not things that need to be validated and they are not involved in any way during report template compilation.

So the the JasperReports API has the setter methods even in the compiled object model (JasperReport as top level object). You can see such modifications being made in the /demo/samples/alterdesign sample provided with the project.

 

2. Modifications that require report template revalidation or recompilation.

If you want to alter the Y coordinate of an element or its height, then your modifications have to be revalidated because they could render your report template invalid. If an element reaches outside the bottom of its parent band, it will not appear during report rendering and this is something that we check for consistency during report compilation.

Or, if you modify the expression of a text field or any other expression for that matter. We'll need to recompile the whole report template (JasperDesign object) and produce the byte code and all (produce a JasperReport object).

 

It looks like you need to do a type 2. modification, so you'll work with uncompiled report template (JasperDesign is top level object) and you'll find all your setter methods on the classes placed in the "net.sf.jasperreports.engine.design" package which make up this part of the API.

 

Once you are done with your report template modifications, you need to recompile it before using it for filling with data.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

teodord wrote:

You can take a look at our /demo/samples/alterdesign sample provided with the project, but note that it only shows what modifications could be made on a compiled report template without need for re-compilation.

 

I tried to modify a textField element in a JSP with the same approach in alterdesign sample. When i try to set an attribute to an element with the proper method call. I m always getting an error pointing at the method trying to modify the object. Something like that.

 

org.apache.jasper.JasperException: Exception in JSP: /jasper/raporla.jsp:35

32:
33:
34: JREllipse jrell=(JREllipse)jr.getTitle().getElementByKey("ellipse-1");
35: jrell.setBackcolor(new Color((int)(16000000 * Math.random())));;
36:
37:
38:

 

teodord, could you please enlighten me about element modification in report scriptlet and JSP?

 

I really need it.

(preparing a prototype web application aiming to show JasperReports capabilities and this topic is my last requirement to make people impressed.)

Link to comment
Share on other sites

teodord wrote:

so you'll work with uncompiled report template (JasperDesign is top level object) and you'll find all your setter methods on the classes placed in the "net.sf.jasperreports.engine.design" package which make up this part of the API.

 

Actually i noticed this necessity of recompilation some time ago. I just wanted to be SURE if i must redesign and recompile. Height attiributes will make me recompile the template design. Moreover as i mentioned in my previous post i need that info in order to complete my objectives on JasperReports.

Link to comment
Share on other sites

Hi,

 

It is not clear to me what your JSP error really is.

So I don't think I could help there. You probably need to catch it better and even do some debug to find the cause. The error message you posted does not say much.

 

As for the scriptlets, note that modifications to the report template are not meant to be done during report filling, even though you could pass the report template as a parameter itself and be able to do alterations on it while filling. But this is not something we recommend as you might get unexpected results.

 

All modifications should be done prior to launching the report filling process. Otherwise you should consider using conditional styles or styled text functionality.

 

I hope this helps.

Teodor

Link to comment
Share on other sites

  • 2 years later...

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