sumankumar_alla Posted December 13, 2006 Share Posted December 13, 2006 Hi all. I am able to generate reports using ireports and jrxml's.It is going fine. In my requirement no of output fields will change dynamically according to the user requirement. I hope it is not possible to change fields dynamically. Is there is a solution for this issue. Thanks in advance.Sumankumar alla Link to comment Share on other sites More sharing options...
Apemant Posted December 13, 2006 Share Posted December 13, 2006 Yes, it is possible, but (I think) not with compiled reports, but with reports in design stage. What you need is JasperDesign class and other JRDesignXXX classes from the package net.sf.jasperreports.engine.design. An instance of JasperDesign can be programatically built from scratch, then you don't even need .jrxml files, but they can also be loaded from a .jrxml file (created with iReport for example) with JRXmlLoader. JasperDesign is actually a memory model with the sctucture equivalent to the corresponding .jrxml file. You can freely modify fields, elements, groups, variables, anything; but once you are finished you need to compile that JasperDesign object (either using JasperCompileManager or a compiler of your preference, I personally use JRJdk13Compiler) in order to get an instance of JasperPrint (which you normally load directly from a compiled .jasper file). It does create a small overhead, but in return you have practically endless possibilities of adjusting the final report to user requests. Of course, all of this assumes you use Java for modifying your reports. :) Hope this helps, if you have more questions, I'll be happy to answer. Link to comment Share on other sites More sharing options...
sumankumar_alla Posted December 14, 2006 Author Share Posted December 14, 2006 HiThanks for your reply.I have understood your explanation.I think it is better to eliminate the .jrxml file for design.But I think it is very long process to design a report using a huge code. And I have studied api document of jasper report. If u doesn’t mind can u please explain me by a sample example? Thankssumankumar Link to comment Share on other sites More sharing options...
Apemant Posted December 14, 2006 Share Posted December 14, 2006 Yes, .jrxml files are not required at all, but on the other hand, there might be some default report sections which don't need to be changed, so why not design those using iReport, load them with JRXmlLoader and then modify the resulting JasperDesign object? Anyway, there are static methodsJRXmlLoader.load() which take either a File object, an InputStream or a String (name of a .jrxml file), which return a JasperDesign object that contains all the attributes and elements of the xml file. You could also just instantiate JasperDesign manually and then fill it with appropriate content. It does involve a lot of work but it is not complex or hard to understand. If you understand the elements and attributes from the Jasper XML scheme, then all the classes from net.sf.jasperreports.engine.design.* should be rather self-explanatory. For example, if you have a JasperDesign object like this JasperDesign jdes = new JasperDesign(); then you can add fields from your datasource like this:JRDesignField field = new JRDesignField();field.setName("ADDRESS");field.setValueClassName("java.lang.String"); jdes.addField(field); All the sections of a report (headers, footers, detail, title, summary) are defined by instantiating JRDesignBand object, set ting its height and adding report elements to it (JRDesignTextField, JRDesignLine, JRDesignWhatever) like this: JRDesignBand detail = new JRDesignBand();detail.setHeight(16); // in points, 1/72 of an inch JRDesignTextField tf = new JRDesignTextField();tf.setXXX(...); // set its various atributes detail.addElement(tf); // add the field to the bandjas.setDetail(detail); // set the band as report detail section Anyway, there is a lot more to this, but you need to experiment on your own. Or buy the JasperReports Ultimate Guide. :) (I didn't buy it myself though, as reading API documentation or even source code seems enough for my needs) Have fun. Link to comment Share on other sites More sharing options...
sumankumar_alla Posted December 17, 2006 Author Share Posted December 17, 2006 HiThanks for your reply. I have succeeded in generating reports using java code. but now i have fallen in another problem is.i am passing image to jasper design object as JRDesignImage image=new JRDesignImage(jasperDesign); image.setX(0); image.setY(10); image.setHeight(30); image.setWidth(200); expression = new JRDesignExpression(); expression.setValueClass(String.class); expression.setText("C:/logo11.gif"); image.setExpression(expression); band.addElement(image); i have placed my image file as C:/logo11.gif but i am getting exception as 1. Syntax error on token ":", invalid AssignmentOperator value = (java.lang.String)(C:/logo11.gif); ^2. Syntax error on token ":", invalid AssignmentOperator value = (java.lang.String)(C://logo11.gif); ^3. Syntax error on token ":", invalid AssignmentOperator value = (java.lang.String)(C:/logo11.gif); Can any body give me the solution? Thanks Link to comment Share on other sites More sharing options...
joeycn Posted December 18, 2006 Share Posted December 18, 2006 I think the expression text must be inclosed by quotation marks.Please try this : expression.setText(""C:/logo11.gif""); Good luck.:blink: Link to comment Share on other sites More sharing options...
sumankumar_alla Posted December 18, 2006 Author Share Posted December 18, 2006 hithanks for your reply. when i give absolute path of the image it is workingfine. but i have to get it from my web application context path.i am using jboss as my application server. i have given path of the image as url like. JRDesignImage image=new JRDesignImage(jasperDesign); image.setX(0); image.setY(10); image.setHeight(30); image.setWidth(200); expression = new JRDesignExpression(); expression.setValueClass(java.net.URL.class); expression.setText(""http://192.168.0.92:9999/ProcessTracker/view/images/logo11.gif""); image.setExpression(expression); band.addElement(image); but it is giving exception as 1. Cannot cast from String to URL value = (java.net.URL)("http://192.168.0.92:9999/ProcessTracker/view/images/logo11.gif"); <------------------------------------------------------------------------------>2. Cannot cast from String to URL value = (java.net.URL)("http://192.168.0.92:9999/ProcessTracker/view/images/logo11.gif"); <------------------------------------------------------------------------------>3. Cannot cast from String to URL value = (java.net.URL)("http://192.168.0.92:9999/ProcessTracker/view/images/logo11.gif"); <------------------------------------------------------------------------------> thanks Link to comment Share on other sites More sharing options...
seshasaib Posted December 19, 2006 Share Posted December 19, 2006 Hi Apemant/Suman, I have a similar requirement and have been tryin for long to find a soluton for this. I have the number of columns to be added to the report will be genrerated dynamically , i mean I wouldnt be knowing how many params are gonna come by which i would be showing in the jsp before selecting them and adding them to the design. Suppose there is one user who has got the privilige to c only 2 columns he can c only 2 column names in the Available list of params another user may add n number of columns to in the available list. In the messages posted below u were setting the field size as 16. Wat do u do if the number of fields are like close to 20 or 25. In my case it may go up to 30 thats why i wonder how do we design the template if there are more number of columns.. Help appreciated. Thanks and regards, sesha sai b.seshasai@gmail.com Link to comment Share on other sites More sharing options...
seshasaib Posted January 2, 2007 Share Posted January 2, 2007 seshasaib wrote:Hi Apemant/Suman,I have a similar requirement and have been tryin for long to find a soluton for this.I have the number of columns to be added to the report will be genrerated dynamically , i mean I wouldnt be knowing how many params are gonna come by which i would be showing in the jsp before selecting them and adding them to the design.Suppose there is one user who has got the privilige to c only 2 columns he can c only 2 column names in the Available list of params another user may add n number of columns to in the available list. In the messages posted below u were setting the field size as 16. Wat do u do if the number of fields are like close to 20 or 25. In my case it may go up to 30 thats why i wonder how do we design the template if there are more number of columns..Help appreciated.Thanks and regards,sesha saib.seshasai@gmail.com Waiting for reply..Can u guys help me in this case. Link to comment Share on other sites More sharing options...
michelr Posted March 17, 2009 Share Posted March 17, 2009 Hello please ,if i want remove field I use the function removefield but not working,give me error I dont know why?? my code: $JRXmlLoader = new Java ('net.sf.jasperreports.engine.xml.JRXmlLoader'); $JasperDesign = $JRXmlLoader->load('C:Archivos de programaApache GroupApache2htdocswebCopia de reporte3.jrxml'); $query = "Select nombre,Ci,telef from empleados"; $JRDesignQuery->setText($query); $JasperDesign->setQuery($JRDesignQuery); $JRField = new Java ('net.sf.jasperreports.engine.JRField'); $JasperDesign->removeField('nombre'); $compileManager = new JavaClass("net.sf.jasperreports.engine.JasperCompileManager"); $report = $compileManager->compileReport($JasperDesign);...... Cant ,some budy help me please michel Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now