asanga Posted October 18, 2007 Share Posted October 18, 2007 Hi, I'm looking for a way to add the expand / collapse functionality to my jasper reports which shows and hides the contents of set of rows when a particular image /button clicked (eg:- when "+" image is clicked it shows all the records hidden beneath it) SugarCRM sample report in jasper server 2.0.1 implements such a feature, but it doesn't explain how to implement such a report. So please tell me how to implement this feature in jasper reports. Post edited by: asanga, at: 2007/10/18 11:42Post edited by: asanga, at: 2007/11/12 03:21 Link to comment Share on other sites More sharing options...
asanga Posted November 27, 2007 Author Share Posted November 27, 2007 Found my own way of doing this B) Any way thanks for keeping my post in your forum ;) Post edited by: asanga, at: 2007/11/27 10:32 Link to comment Share on other sites More sharing options...
asanga Posted November 27, 2007 Author Share Posted November 27, 2007 Found my own solution B) Any way thanks for keeping my post in your forum ;) Link to comment Share on other sites More sharing options...
svenn Posted November 28, 2007 Share Posted November 28, 2007 Could you share your solution with the rest of us? Link to comment Share on other sites More sharing options...
asanga Posted November 28, 2007 Author Share Posted November 28, 2007 well what I did was totally based on jasper parameters, print when condition of the bands and JSP sessions, and this may be a lengthy and complex way to implement this functionality but I couldn't find any other way and little hard to explain :(. well I've included an label("+") and it is a HTML link to the .JSP page which exports the .jasper file and display it in HTML format (which means that this link refers to the .JSP files which export the .jasper file of the current .jrxml file being designed) AccountName (group1) ProjectName (group 2) + LanguageName (group3) -----(hidden raw(s))---------- + LanguageName (group3) -----(hidden raw(s))---------- ProjectName (group 2) + LanguageName (group3) -----(hidden raw(s))---------- - LanguageName (group3) --C#------- --Java----- --PHP------ Above shown is the format of my report in brief. By default the row(s) which should come under the Language Name are being hidden they will be visible only when the (+) sign is clicked. Print when condition has been applied to the hidden set of band in my case it is the details band. print when condition of the details band has to determine which + sign user has clicked as there are many records in the report So it does this by the group values which are unique (im my case it uses languageName and projectname together which are being sent via the HTML link (+) to JSP page which exports the report) Print when conditionnew Boolean (!$F{latest_matrices3_ProjectName}.equals( "-" ) && $P{param_set}.indexOf($F{latest_matrices3_ProjectName}+" "+$F{latest_matrices3_LanguageName}.toString()+" "+"n")>-1) HyperLink Reference being sent when (+) clicked"report_new_test.jsp?proj_name="+$F{latest_matrices3_ProjectName}+"&lang_name="+URLEncoder.encode($F{latest_matrices3_LanguageName},"UTF-8") at the JSP file it keeps these set of variables in a session created previously in a JSP page which directs user to this perticular JSP which hosts the Jasper report. This is what happens in the JSP file<% Map parameters = new HashMap(); //recive the query string parameters being sent//projectName, LanguageName, and parameter setString prj=request.getParameter("proj_name");String lng=request.getParameter("lang_name"); String param_set=(String)session.getAttribute("param_set"); //Name of the Jasper report to be filled and exportedString filename = "ERA_5.jasper";String reporttype ="html"; //get the Database connection created in the test.jsp via the sessionClass.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection conn =(Connection)session.getAttribute("con");System.out.println("Connection Established"); //Path which consist of the jasper reportsString path = application.getRealPath("/jaspers"); //processing the param_set which keep the status of each project and language pare related to a perticular Accountint start=-1;start=param_set.indexOf(prj+" "+lng); //if currently selected projects language has not been selected within this session before add it to the param_set//ProjectName, Language_Name, expantion status(y/n) is being addedif(start<0){param_set=param_set+" "+prj+" "+lng+" "+"n"+" ";parameters.put("tree",new Boolean("true")); }//if currently selected project language pare exist already in the param_set variable (which implies that they have//been selected before) there expantion status will be checked and alterd to the opposite value from thw current value//tree parameter is being set as it is used in the printwhen condition of +/- labels in the reportelse{String subVal=param_set.substring(start,start+(prj+" "+lng+" ").length()+1);String subarr[]=subVal.split(" ");if(subarr[2].equals("y")){ param_set=param_set.replaceAll(prj+" "+lng+" "+"y",prj+" "+lng+" "+"n");parameters.put("tree",new Boolean("true"));}else{param_set=param_set.replaceAll(prj+" "+lng+" "+"n",prj+" "+lng+" "+"y");parameters.put("tree",new Boolean("false"));} } //add the parameter values to reportparameters.put("tree_proj_name",prj);parameters.put("tree_lang_name",lng);parameters.put("param_set",param_set); //report is being filledJasperPrint jasperPrint = JasperFillManager.fillReport(path+"/"+filename,parameters, conn);System.out.println("Report Created...");//OutputStream ouputStream = response.getOutputStream(); //set the values included in the param_set variable to a session which preserves the status to next page on next clicksession.setAttribute("param_set",param_set); JRExporter exporter = null;OutputStream ouputStream = response.getOutputStream(); //set the reports export parametersif( "html".equalsIgnoreCase(reporttype) ){exporter = new JRHtmlExporter();request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);PrintWriter printWriter = new PrintWriter(response.getOutputStream());exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,"image?image=");} try{exporter.exportReport();}catch (JRException e){throw new ServletException(e);} %> forgive me this may confuse you but I have no way of explaining this much more simpler:( :( :( Link to comment Share on other sites More sharing options...
asanga Posted November 28, 2007 Author Share Posted November 28, 2007 well what I did was totally based on jasper parameters, print when condition of the bands and JSP sessions, and this may be a lengthy and complex way to implement this functionality but I couldn't find any other way and little hard to explain :(. well I've included an label("+") and it is a HTML link to the .JSP page which exports the .jasper file and display it in HTML format (which means that this link refers to the .JSP files which export the .jasper file of the current .jrxml file being designed) AccountName (group1) ProjectName (group 2) + LanguageName (group3) -----(hidden raw(s))---------- + LanguageName (group3) -----(hidden raw(s))---------- ProjectName (group 2) + LanguageName (group3) -----(hidden raw(s))---------- - LanguageName (group3) --C#------- --Java----- --PHP------ Above shown is the format of my report in brief. By default the row(s) which should come under the Language Name are being hidden they will be visible only when the (+) sign is clicked. Print when condition has been applied to the hidden set of band in my case it is the details band. print when condition of the details band has to determine which + sign user has clicked as there are many records in the report So it does this by the group values which are unique (im my case it uses languageName and projectname together which are being sent via the HTML link (+) to JSP page which exports the report) Print when conditionnew Boolean (!$F{latest_matrices3_ProjectName}.equals( "-" ) && $P{param_set}.indexOf($F{latest_matrices3_ProjectName}+" "+$F{latest_matrices3_LanguageName}.toString()+" "+"n")>-1) HyperLink Reference being sent when (+) clicked"report_new_test.jsp?proj_name="+$F{latest_matrices3_ProjectName}+"&lang_name="+URLEncoder.encode($F{latest_matrices3_LanguageName},"UTF-8") at the JSP file it keeps these set of variables in a session created previously in a JSP page which directs user to this perticular JSP which hosts the Jasper report. This is what happens in the JSP file<% Map parameters = new HashMap(); //recive the query string parameters being sent//projectName, LanguageName, and parameter setString prj=request.getParameter("proj_name");String lng=request.getParameter("lang_name"); String param_set=(String)session.getAttribute("param_set"); //Name of the Jasper report to be filled and exportedString filename = "ERA_5.jasper";String reporttype ="html"; //get the Database connection created in the test.jsp via the sessionClass.forName("sun.jdbc.odbc.JdbcOdbcDriver");Connection conn =(Connection)session.getAttribute("con");System.out.println("Connection Established"); //Path which consist of the jasper reportsString path = application.getRealPath("/jaspers"); //processing the param_set which keep the status of each project and language pare related to a perticular Accountint start=-1;start=param_set.indexOf(prj+" "+lng); //if currently selected projects language has not been selected within this session before add it to the param_set//ProjectName, Language_Name, expantion status(y/n) is being addedif(start<0){param_set=param_set+" "+prj+" "+lng+" "+"n"+" ";parameters.put("tree",new Boolean("true")); }//if currently selected project language pare exist already in the param_set variable (which implies that they have//been selected before) there expantion status will be checked and alterd to the opposite value from thw current value//tree parameter is being set as it is used in the printwhen condition of +/- labels in the reportelse{String subVal=param_set.substring(start,start+(prj+" "+lng+" ").length()+1);String subarr[]=subVal.split(" ");if(subarr[2].equals("y")){ param_set=param_set.replaceAll(prj+" "+lng+" "+"y",prj+" "+lng+" "+"n");parameters.put("tree",new Boolean("true"));}else{param_set=param_set.replaceAll(prj+" "+lng+" "+"n",prj+" "+lng+" "+"y");parameters.put("tree",new Boolean("false"));} } //add the parameter values to reportparameters.put("tree_proj_name",prj);parameters.put("tree_lang_name",lng);parameters.put("param_set",param_set); //report is being filledJasperPrint jasperPrint = JasperFillManager.fillReport(path+"/"+filename,parameters, conn);System.out.println("Report Created...");//OutputStream ouputStream = response.getOutputStream(); //set the values included in the param_set variable to a session which preserves the status to next page on next clicksession.setAttribute("param_set",param_set); JRExporter exporter = null;OutputStream ouputStream = response.getOutputStream(); //set the reports export parametersif( "html".equalsIgnoreCase(reporttype) ){exporter = new JRHtmlExporter();request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);PrintWriter printWriter = new PrintWriter(response.getOutputStream());exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, ouputStream);exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI,"image?image=");} try{exporter.exportReport();}catch (JRException e){throw new ServletException(e);} %> forgive me this may confuse you but I have no way of explaining this much more simpler:( :( :( Link to comment Share on other sites More sharing options...
kcsekhar25 Posted December 11, 2013 Share Posted December 11, 2013 Hi, i appreaciate you that you could able to find solution for this. i also have same requirement but did not understand how u r using label + as it is a static content which cannot be applied hyperlink and how to use html component.if you have any any process listed for this which can better explains how to use it report and the jsps. can you please share the jrxml that you have created. r u using this report in your eclipse environment?i want this report to work in jasper server. please let me know how can i achieve this. your support is highly appreciated. 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