Solved

JSP - pdf generation

Posted on 2006-07-21
8
1,054 Views
Last Modified: 2008-03-17
Hello All,

I am having a jsp page which displays a table of columns...one column is a checkbox column.  if i select the table header column, all the checkboxes get selected.  or i can select anything particularly.  the problem is i want to generate pdf which are all selected for.  so can you pls inform me how to do it.  i heard about jasper reg. pdf generation.

thanks
0
Comment
Question by:altima4u
  • 4
  • 4
8 Comments
 
LVL 15

Expert Comment

by:bpmurray
ID: 17154690
Well, Jasper is a report generator, and perhaps not quite what you need. I suggest iText (Jasper actually uses this to generate PDF) - see http://www.lowagie.com/iText/
0
 
LVL 1

Author Comment

by:altima4u
ID: 17154793
can you inform about the logic for getting out the selected values of the checkboxes, passing the parameters as query string for it and getting printed in the pdf file.  i have a pdf icon on the top of the page.  if i click that then for which all i selected, i should be able to generate the pdf for it !
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 17154899
Do you mean in the browser or on the server?
0
 
LVL 1

Author Comment

by:altima4u
ID: 17155025
server side.  Iam writing java code for it.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:altima4u
ID: 17155027
using struts framework.
0
 
LVL 15

Expert Comment

by:bpmurray
ID: 17155761
Well, if you're using multibox, you can do something like this to get the values from the struts action:

public class CheckboxAction extends Action {
      public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                               HttpServletResponse response) throws ServletException, Exception {

                  //      Get the values in the checkboxes
                  String[] selectedDocuments = ((MyForm) form).getSelectedDocuments();

                  System.out.println("RETURNED*\n" + selectedDocuments.toString());

                  return (mapping.findForward("success"));
      }

}
0
 
LVL 1

Author Comment

by:altima4u
ID: 17156282
iam using this type of code.  kindly look at the code.

<td width="12%" class="blackRow" align="center"><b><input type="checkbox" name="chkAllBox" onclick="checkAll()"></b></td>

***** the above is for the table header column checkbox...

<logic:iterate id="Data" property="value(StrategySearchResults)" name="SSForm">

<%
            if (i % 2 == 0)
            {
      %>            
                  <tr class="TABLE_EVEN_ROW">
      <%                  
            }
            else
            {
      %>            
                  <tr class="TABLE_ODD_ROW">
      <%                  
            }
            i++;
      %>

                <td class="td" align="center">
                    <a class="bluelink" href="/HFSPortal/EditStrategy.do?strategy_id=<bean:write name="Data"
                         property="value(TradeCode)"/>"><u>Edit</u></a>
                </td>
               
       
            <!-- Strategy Name -->      
            <logic:notEmpty property="value(StrategyName)" name="Data">            
                  <td class="td">
                  <a class="bluelink" href="./ShowCharts.do?tradeCode=<bean:write name="Data" property="value(TradeCode)"/>&Rating=<bean:write name="Data" property="value(StrategyRating)"/>&StratName=<bean:write name="Data" property="value(StrategyName)"/>" />
                        <bean:write name="Data" property="value(StrategyName)"/>
                  </a></td>
            </logic:notEmpty>
            <logic:empty property="value(StrategyName)" name="Data">
                  <td class="td">&nbsp;</td>            
            </logic:empty>
            <!-- Strategy Name -->                  
            
            <!-- check if StrategySector is null -->
            <logic:notEmpty property="value(StrategySector)" name="Data">            
                  <td class="td"><bean:write name="Data" property="value(StrategySector)"/></td>
            </logic:notEmpty>
            <logic:empty property="value(StrategySector)" name="Data">
                  <td class="td">&nbsp;</td>            
            </logic:empty>
            <!-- check if StrategySector is null -->

            <!-- check if StrategyRating is null -->
            <logic:notEmpty property="value(StrategyRating)" name="Data">
                  <td class="td"><bean:write name="Data" property="value(StrategyRating)"/></td>            
            </logic:notEmpty>
            <logic:empty property="value(StrategyRating)" name="Data">
                  <td class="td">&nbsp;</td>            
            </logic:empty>
            <!-- check if StrategyRating is null -->            

            <bean:define name="Data" property="value(TradeCode)" id="TradCode" />
            <bean:define name="Data" property="value(StrategyName)" id="StrategyName" />
            
            
            
            <!-- check if StrategyNav is null -->
            <logic:notEmpty property="value(StrategyNav)" name="Data">
                  <td class="td" align="right">
                  <a class="bluelink" onClick="return ShowAUMBreakup('<%=TradCode%>', '<%=StrategyName%>','<%=businessDate%>')" href="">
                        <bean:write name="Data" property="value(StrategyNav)"/>
                  </a></td>
            </logic:notEmpty>
            <logic:empty property="value(StrategyNav)" name="Data">
                  <td class="td">&nbsp;</td>            
            </logic:empty>
            <!-- check if StrategyNav is null -->                              

            <!-- check if Capacity is null -->
            <logic:notEmpty property="value(Capacity)" name="Data">
                  <td align="right" class="td"><bean:write name="Data" property="value(Capacity)"/></td>            
            </logic:notEmpty>
            <logic:empty property="value(Capacity)" name="Data">
                  <td align="right" class="td">&nbsp;</td>            
            </logic:empty>
            <!-- check if Capacity is null -->            

            <!-- check if ErisaCapacity is null -->
            <logic:notEmpty property="value(ErisaCapacity)" name="Data">
                  <td align="right" class="td"><bean:write name="Data" property="value(ErisaCapacity)"/></td>            
            </logic:notEmpty>
            <logic:empty property="value(ErisaCapacity)" name="Data">
                  <td align="right" class="td">&nbsp;</td>            
            </logic:empty>
            <!-- check if ErisaCapacity is null -->      
            
            <!-- Inception Date -->
            <logic:notEmpty property="value(inceptDate)" name="Data">
                  <td align="center" class="td"><bean:write name="Data" property="value(inceptDate)"/></td>
            </logic:notEmpty>
            <logic:empty property="value(inceptDate)" name="Data">
                  <td align="center" class="td">&nbsp;</td>
            </logic:empty>
            <!--Inception Date-->      
            
======= here comes the check box =========

            <!--Check Box-->
            <td align="center"><input type="checkbox"/></td>
        <!--Check Box-->
       </td>
       
      </tr>            
      </logic:iterate>
</table>


i have a pdf icon above table, for the selected check boxes, if i click the icon , i have to pass some values for each pdf generation.. i dont know how to do that..the link for the pdf icon is some.java..do i have to write all the logic in the java file..like getting the selection and able to print them in a pdf file.
pls let me know about this..
0
 
LVL 15

Accepted Solution

by:
bpmurray earned 200 total points
ID: 17156562
I don't know how your PDF icon works. I can only assume it does a submit, in which case, it will send the name-value pairs of the various input fields into the servlet. Now, there's a little problem here - you don't have an ID or a NAME on the checkbox. Perhaps you could do it like this:
             <td align="center"><input type="checkbox" id=<% generateID(i); %>/></td>

Just to verify that the PDF icon does the submit, check what it generates when it displays on the browser. It probably has something like
            onclick="SSform.submit();"

When the form is submitted, all the ticked generated checkboxes are sent on the request, and you cal identify these using the same techniques as you used to display the page, but this time in the action:
      public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                             HttpServletResponse response) throws ServletException, Exception {
            
            // Get the results that were used as a basis for the table on the page
            String[] foo = SSForm.getStrategySearchResults();
            int chkCount = foo.length;
            
            // Print report if the checkbox is ticked
            for (int iX=0; iX<chkCount; iX++) {
                  if (null != request.getParameter(generateID(iX))) {  // Use identical technique to generate the ID
                        generatePDFDocument(foo[iX]);
                  }
            }

            return (mapping.findForward("success"));
      }
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now