Solved

JSP - pdf generation

Posted on 2006-07-21
8
1,057 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 1

Author Comment

by:altima4u
ID: 17155025
server side.  Iam writing java code for it.
0
 
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 Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

839 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