vivek_1 Posted July 13, 2013 Share Posted July 13, 2013 I am using jasper report to generate pdf and docx . for design I am using ireport. Suppose I have two subreport sub1 and sub2 . Now I need to swap position of these two subreport from each other.I am using jasper plugin in grails. now my problem is that how can I change the position of these two sub report from my controller.If there is any confusion to understand question, feel free to ask me.Thanks.Vivek Link to comment Share on other sites More sharing options...
Ankur Gupta Posted July 15, 2013 Share Posted July 15, 2013 Hi vivek ,Firstly I want to state that I don't have an idea of grails, but in general I could tell you how to fix this.See you can put condition in the subreport expressions for the two elements of subreport in the main report.(Subreport expression here means the path of the subreport on the local machine ) and if this path in both the elements is varied on the basis of condition then you would be able to swap the subreports dynamically. Have tested the same in iReports it is working fine. Hope that it helps.Thanks,Ankur Gupta Link to comment Share on other sites More sharing options...
vivek_1 Posted July 15, 2013 Author Share Posted July 15, 2013 Hi Ankur Thanks for your reply. can you please send me a piece of code, I did not get exactly that how you swap two or more sub report with each other. Link to comment Share on other sites More sharing options...
Ankur Gupta Posted July 15, 2013 Share Posted July 15, 2013 Hi.Suppose there are two subreport elements suppose sub1 and sub2for sub1 the Subreport expression will be( I am putting a static path for the subreport on local disk)condition?"D://Reports//sub1.jasper":"D://Reports//sub2.jasper"for sub2 condition?"D://Reports//sub2.jasper":"D://Reports//sub1.jasper"The condition will be the dynamic value which triggers the swapping of the subreports Hope that the above description helps.Thanks,Ankur Gupta Link to comment Share on other sites More sharing options...
vivek_1 Posted July 15, 2013 Author Share Posted July 15, 2013 Hi, Thanks for this awesome answer. I have 9 sub report.And my requirement is that I can switch any sub report with any other sub report. Is there any possibility to make a condition of this type. Link to comment Share on other sites More sharing options...
Ankur Gupta Posted July 15, 2013 Share Posted July 15, 2013 does the condition for the switching is related in any form , or precisely you could describe the condition for swapping.. Then could help you better Link to comment Share on other sites More sharing options...
vivek_1 Posted July 15, 2013 Author Share Posted July 15, 2013 No its not swapping of two sub report exactly.Its basically rearranging of sub report.Every sub report has its own look and feel and own list which I send through controller. In starting I have a order of sub report suppose 1,2,3,4,5,6,7,8,9 . after change the position of sub reports suppose I have an order like this- 5,9,8,3,2,1,6,7,4 or 8,5,1,9,4,7,6,2,3 or something like this. I have 9! possibillity to rearrange sub report. Now I How can I set path and data(List sent with sub report) to manage my sub report. Link to comment Share on other sites More sharing options...
vivek_1 Posted July 15, 2013 Author Share Posted July 15, 2013 Hi.. Is there any problem to understand my question or is it impossible to implement this type of scenario. Please clarify if possible. Thanks Link to comment Share on other sites More sharing options...
Ankur Gupta Posted July 15, 2013 Share Posted July 15, 2013 Hi ,Sorry for a late reply was occupied with some work,My try would be ,If the cases are 9! I think you can generate the sequence of 9! ways of arranging the 9 reports(eg- '987654321','987123456',..etc) , then what you can do is put a switch case with each case(1-9) defining the subreport and the every time the random arrangement string is generated , suppose '987165324' then one by one the cases will execute depending upon the generated sequence and generate the subreports also. See I am not sure you will have to try this logic.Please let me know if it works. Thanks,Ankur Gupta Link to comment Share on other sites More sharing options...
vivek_1 Posted July 16, 2013 Author Share Posted July 16, 2013 This solution was in my mind. But I am confused that how can I implement switch case in jrxml file. I searched it on google but did not find anything regarding this. Can you tell me or provide some link so that I can learn it better. Link to comment Share on other sites More sharing options...
vivek_1 Posted July 16, 2013 Author Share Posted July 16, 2013 just one more question. new datasource "path for subreport.jasper" Can I give dynamic value for x,y and width ,height, like I take a variable and put value. If possible what type of data type should I take? Link to comment Share on other sites More sharing options...
Ankur Gupta Posted July 16, 2013 Share Posted July 16, 2013 Hey I was thinking that you could do this switch case through java program , not xml so you could generate the report including the shuffled subreports Like: Map parameters = new HashMap(); //if you want this to be compiled in runtime JasperReport jasperReport = JasperCompileManager.compileReport(your JRXMLReport path file here); JasperReport subReport = JasperCompileManager.compileReport(your JRXMLSubReport path file here); //you can notice that there're a lot of overloaded mathods to compile it, you can choose //what is better in your case //if you want to use the complied file *.jasper JasperReport jasperReport = (JasperReport)JRLoader.loadObject(new File("filenameReport.jasper")); JasperReport subReport = (JasperReport)JRLoader.loadObject(new File("filenameSubReport.jasper")); //Then you add your subReport in your parameter Map parameters.put("SUBREPORT_JASPER_FILE", subReport); JasperFillManager.fillReport(jasperReport, parameters, new JRBeanCollectionDataSource(yourList)); This is the code which contains only a single subreport I was pointing that put a switch case with each case generating the subreport as above and dynamically get shuffled and added to the report. Hopwe that it helps Thanks. Ankur Gupta 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