• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1071
  • Last Modified:

JSP - pdf generation

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
altima4u
Asked:
altima4u
  • 4
  • 4
1 Solution
 
bpmurrayCommented:
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
 
altima4uAuthor Commented:
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
 
bpmurrayCommented:
Do you mean in the browser or on the server?
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
altima4uAuthor Commented:
server side.  Iam writing java code for it.
0
 
altima4uAuthor Commented:
using struts framework.
0
 
bpmurrayCommented:
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
 
altima4uAuthor Commented:
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
 
bpmurrayCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now