• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

web dynpro application coding

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

I am developing a application in web dynpro, I want the output to be displayed in html format.
earlier the program has a third party tool used for printing the output in pdf format ie itext.
I am posting the code also so please suggest me how to go forward in order to get the output displayed in html format, by removing the third party tool.(itext)

thanks
rk

package com.lii.wwhc.adp.warranty;

import java.awt.Color;
import java.io.IOException;
//import java.io.ByteArrayOutputStream;
import java.util.Iterator;
//import javax.servlet.ServletOutputStream;

import javax.servlet.http.HttpServletResponse;

import com.lii.wwhc.adp.warranty.util.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import com.sapportals.htmlb.rendering.IPageContext;
import com.sapportals.htmlb.rendering.PageContextFactory;
import com.sapportals.portal.prt.component.*;

public class Print extends AbstractPortalComponent
{

PrintBean pBean = new PrintBean();
SystemFactory sys;
public void doContent(IPortalComponentRequest request, IPortalComponentResponse response)
{

try {

//context
IPageContext myContext = PageContextFactory.createPageContext(request, response);
//component profile.
IPortalComponentProfile profile = request.getComponentContext().getProfile();
//session.
IPortalComponentSession componentSession = request.getComponentSession();
//system object from session.
sys = (SystemFactory)componentSession.getHttpSession().getAttribute("system");
//get tag from request.
String tagNo = request.getParameter("tagNo");
//get claim from database.
ClaimHeader claim = sys.getClaimForTagNumber(tagNo);
//get status list and failure list from database.
java.util.List statusList = sys.getClaimStatusCodes();
java.util.List failureList = sys.getFailureCodes();

//ADP INOF
AdpInfoBean adpInfo = sys.retrieveAdpInfo(claim.getCustomerId());
pBean.setAdpInfo(adpInfo);
//branch address from R3.
Address branchAdr = sys.retrieveCustomerAddress(claim.getBranch());
claim.setBranchAddress(branchAdr);

//Store the info in print bean.
pBean.setClaim(claim);
pBean.setClaimStatusCodes(statusList);
pBean.setFailureCodes(failureList);
pBean.setLogo(Image.getInstance(request.getPublicResourcePath()+"\\images\\logo.jpg"));

//create a document with certain page size
Document document = new Document(PageSize.A4,25,25,60,25);

//ByteArrayOutputStream baos = new ByteArrayOutputStream();
//PdfWriter writer = PdfWriter.getInstance(document, baos);

HttpServletResponse res = request.getServletResponse(true);
//set the mimetype
res.setContentType("application/pdf");
res.setHeader("Expires", "0");
res.setHeader("Cache-Control",
"must-revalidate, post-check=0, pre-check=0");
res.setHeader("Pragma", "public");

PdfWriter writer = PdfWriter.getInstance(document, res.getOutputStream());
writer.setPageEvent(new PageEventImpl(pBean));
//open the document for adding stuff
document.open();
//DocumentTitle
document.add(getTitleTable());
//End DocumentTitle
//Begin Address table
document.add(getAddressTable());
//End Address table
document.add(getClaimHeaderTable());
if(claim.isClaimCredit() && isUnitFailure(claim))
{

document.add(getLineItemForUnitFailTable());
}
else if( ( claim.isClaimCredit() &&
isPartsFailure(claim) ) ||
claim.isClaimGratis())
{
document.add(getLineItemForParts());
}

//Start second part of body
document.close();
/*HttpServletResponse res = request.getServletResponse(true);
//set the mimetype
res.setHeader("Expires", "0");
res.setHeader("Cache-Control",
"must-revalidate, post-check=0, pre-check=0");
res.setHeader("Pragma", "public");
res.setContentType("application/pdf");
res.setContentLength(baos.size());
ServletOutputStream out = res.getOutputStream();
baos.writeTo(out);
out.flush();*/
} catch (Exception e) {
System.out.println(e);
HttpServletResponse res = request.getServletResponse(true);
//set the mimetype
res.setContentType("text/html");
String error = "<span style='color:red'>There was a problem with the application. Please contact Help Desk </span>";
if(pBean.getAdpInfo().getHelpDeskNumber() != "")
error = error + "<span style='color:red'>at "+pBean.getAdpInfo().getHelpDeskNumber()+"</span>";

try {
res.getWriter().write(error);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}

}

/*
* Out puts title of the page.
*/
public PdfPTable getTitleTable()
{
//HEADER TABLE
Phrase p;
PdfPCell cell;

float widths[] = {50,50};
PdfPTable tableTop = new PdfPTable(widths);
tableTop.setWidthPercentage(100);


if(pBean.getClaim().isClaimGratis())
p = new Phrase("Gratis Memo", new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.BLACK) );
else
p = new Phrase("Credit Memo", new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.BLACK) );
cell = new PdfPCell(p);
cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
cell.setColspan(2);
cell.setPaddingTop(75);
if(pBean.getClaim().getStatus() != SystemFactory.SAVE)
{
cell.setPaddingBottom(10);
}
//cell.setBackgroundColor(new Color(23,23,23));
cell.setBorder(0);
tableTop.addCell(cell);

if(pBean.getClaim().getStatus() == SystemFactory.SAVE)
{
p=new Phrase("Claim not yet submitted", new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.RED) );
cell = new PdfPCell(p);
cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);
cell.setPaddingBottom(10);
cell.setBorder(0);
cell.setColspan(2);

tableTop.addCell(cell);
}

return tableTop;
}

/*
* returns the address portion on the page
* branch, dealer and ship to address.
*/
private PdfPTable getAddressTable()
{
ClaimHeader claim = pBean.getClaim();
Phrase p;
PdfPCell cell;

float[] columnDefinitionSize = { 33, 33, 33 };
//create a table with 3 columns
PdfPTable table = new PdfPTable(3);
table.setWidthPercentage(100);
table.setSpacingBefore(20);


p = new Phrase();
p.font().setSize(8);
p.add(getBoldPhrase("Branch:"));
p.add(new Phrase("\r"+claim.getBranchAddress().getName()+" - "+
GeneralHelper.removeLeadingZeros( claim.getBranch()) ));
p.add(new Phrase("\r"+claim.getBranchAddress().getLine1()));
p.add(new Phrase("\r"+claim.getBranchAddress().toStringCityState()));
cell = new PdfPCell(p);
cell.setBorder(0);
table.addCell(cell);

p = new Phrase();
p.font().setSize(8);
p.add( getBoldPhrase("Dealer:"));
p.add(new Phrase("\r"+claim.getDealerAddress().getName()));
p.add(new Phrase("\r"+claim.getDealerAddress().getLine1()));

p.add(new Phrase("\r"+claim.getDealerAddress().toStringCityState() ));
cell = new PdfPCell(p);
cell.setBorder(0);
table.addCell(cell);

if(claim.isClaimGratis())
{

p = new Phrase();
p.font().setSize(8);
p.add(new Phrase("Ship To:" , new Font(Font.TIMES_ROMAN, 10, Font.BOLD, Color.BLACK)));
p.add(new Phrase("\r"+claim.getShipToAddress().getName()));
p.add(new Phrase("\r"+claim.getShipToAddress().getLine1()));
if(!claim.getShipToAddress().getLine2().trim().equals(""))
p.add(new Phrase("\r"+claim.getShipToAddress().getLine2()));
p.add(new Phrase("\r"+claim.getShipToAddress().toStringCityState()));
cell = new PdfPCell(p);
cell.setBorder(0);
table.addCell(cell);

table.addCell(getEmptyCell());
table.addCell(getEmptyCell());

p = new Phrase();
p.font().setSize(8);
p.add(new Phrase("Shiping Method:" , new Font(Font.TIMES_ROMAN, 10, Font.BOLD, Color.BLACK)));
if(claim.getIncoBean() != null)
p.add(new Phrase("\r"+claim.getIncoBean().getDescription()));
cell = new PdfPCell(p);
cell.setBorder(0);
table.addCell(cell);
}
else
{
table.addCell(getEmptyCell());
}

return table;

}

/*
* returns header portion of the claim.
*/
private PdfPTable getClaimHeaderTable()
{
ClaimHeader claim= pBean.getClaim();

Phrase p;
PdfPCell cell;

PdfPTable table = new PdfPTable(4);
table.setWidthPercentage(100);
table.setSpacingBefore(20);

p = new Phrase();
p.font().setSize(8);
p.add(new Phrase("Failed unit:" , new Font(Font.TIMES_ROMAN, 10, Font.BOLD, Color.BLACK)));
if(claim.getSerialNumberOfFailedUnit() != null && !claim.getSerialNumberOfFailedUnit().trim().equals(""))
p.add(new Phrase("\r" +claim.getSerialNumberOfFailedUnit()+" | " +claim.getModelOfFailedUnit() ));
else
p.add(new Phrase("\r " ));
cell = new PdfPCell(p);
cell.setBorder(0);
table.addCell(cell);

p = new Phrase();
p.font().setSize(8);
p.add(new Phrase("Install Date:" , new Font(Font.TIMES_ROMAN, 10, Font.BOLD, Color.BLACK)));
p.add(new Phrase("\r"+GeneralHelper.formatDateForDisplay(claim.getInstallationDate())));
cell = new PdfPCell(p);
cell.setBorder(0);
table.addCell(cell);

p = new Phrase();
p.font().setSize(8);
p.add(new Phrase("Unit Fail Date:" , new Font(Font.TIMES_ROMAN, 10, Font.BOLD, Color.BLACK)));
p.add(new Phrase("\r"+GeneralHelper.formatDateForDisplay(claim.getUnitFailDate())));
cell = new PdfPCell(p);
cell.setBorder(0);
table.addCell(cell);

p = new Phrase();
p.font().setSize(8);
p.add(new Phrase("Reference Number:" , new Font(Font.TIMES_ROMAN, 10, Font.BOLD, Color.BLACK)));
p.add(new Phrase("\r"+claim.getReferenceNumber()));
cell = new PdfPCell(p);
cell.setBorder(0);
table.addCell(cell);

if(claim.isClaimCredit())
{

p = new Phrase();
p.font().setSize(8);
p.add(new Phrase("Failure Type:" , new Font(Font.TIMES_ROMAN, 10, Font.BOLD, Color.BLACK)));
p.add(new Phrase("\rEntire Unit"));
cell = new PdfPCell(p);
cell.setBorder(0);
table.addCell(cell);
}

p = new Phrase();
p.font().setSize(8);
p.add(new Phrase("Reason for Failure:" , new Font(Font.TIMES_ROMAN, 10, Font.BOLD, Color.BLACK)));
p.add(new Phrase("\r"+ pBean.getFailureDesc(claim.getReasonForFailure()) ));
cell = new PdfPCell(p);
cell.setBorder(0);
table.addCell(cell);

table.addCell(getEmptyCell());
table.addCell(getEmptyCell());
if(claim.isClaimGratis()) //add Aditional emply cell if gratis
table.addCell(getEmptyCell());

return table;
}

/*
* returns lineitems if unit failed for the claim.
*/
private PdfPTable getLineItemForUnitFailTable()
{
ClaimLineItem item = (ClaimLineItem) pBean.getClaim().getLineItem(0);

Phrase p;
PdfPCell cell;
float widths[] = {15,45,20,20};

PdfPTable table = new PdfPTable(widths);
table.setWidthPercentage(100);
table.setSpacingBefore(20);
//HEADERcell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);

table.addCell(getDataCell("Quantity:",true, null));
table.addCell(getDataCell("Replacment Unit:",true, null));
table.addCell(getDataCell("Status:",true, null));
table.addCell(getDataCell("$ Amount:",true, null));

//LINE ITEM
cell =getDataCell(item.getQuantity(),false, null) ;
cell.setPaddingLeft(15);//HorizontalAlignment(Rectangle.ALIGN_CENTER);
table.addCell(cell);
if(item.getSerialNumberOfReplacementUnit() != null && !item.getSerialNumberOfReplacementUnit().trim().equals(""))
table.addCell(getDataCell(item.getSerialNumberOfReplacementUnit()+ " | "+
item.getModelOfReplacementUnit(),false, null));
else
table.addCell(getDataCell( " ",false, null));
table.addCell(getDataCell(pBean.getClaimStatusDesc(item.getStatus()),false, null));
table.addCell(getDataCell(item.getInvoiceAmt(),false, null));

return table;
}

/*
* returns lineitems if one or more parts failed for the claim.
*/
private PdfPTable getLineItemForParts()
{
//ClaimLineItem item = (ClaimLineItem) pBean.getClaim().getLineItem(0);

Phrase p;
PdfPCell cell;
float widths[] = {10,30,30,15,15};

PdfPTable table = new PdfPTable(widths);
table.setWidthPercentage(100);
table.setSpacingBefore(20);
//HEADERcell.setHorizontalAlignment(Rectangle.ALIGN_CENTER);

table.addCell(getDataCell("Quantity:",true, null));
table.addCell(getDataCell("Failed Part:",true, null));
table.addCell(getDataCell("Replacement Part:",true, null));
table.addCell(getDataCell("Status:",true, null));
if(pBean.getClaim().isClaimCredit())
table.addCell(getDataCell("$ Amount:",true, null));
else
table.addCell(getDataCell("Ship Date:",true, null));

Iterator it = pBean.getClaim().getLineItems().iterator();

Color background = null;
while(it.hasNext())
{

ClaimLineItem item = (ClaimLineItem)it.next();
//LINE ITEM
cell =getDataCell(item.getQuantity(),false, background) ;
cell.setPaddingLeft(15);//HorizontalAlignment(Rectangle.ALIGN_CENTER);
table.addCell(cell);
if(item.getFailedPartNumber() != null && !item.getFailedPartNumber().trim().equals(""))
table.addCell(getDataCell(item.getFailedPartNumber()+ " | "+
item.getFailedPartDesc(),false, background));
else
table.addCell(getDataCell(" ",false, background));

if(item.getReplacementPartNumber() != null && !item.getReplacementPartNumber().trim().equals(""))
table.addCell(getDataCell(item.getReplacementPartNumber()+ " | "+
item.getReplacementPartDesc(),false, background));
else
table.addCell(getDataCell(" ",false, background));

table.addCell(getDataCell(pBean.getClaimStatusDesc(item.getStatus()),false, background));
if(pBean.getClaim().isClaimCredit())
table.addCell(getDataCell(item.getInvoiceAmt(),false, background));
else
table.addCell(getDataCell(item.getShipDate(),false, background));

if( background == null)
background = new Color(225,225,225);
else
background = null;
}



return table;
}

/*
* helper method to check if claim is for parts failure.
*/
private boolean isPartsFailure(ClaimHeader claim)
{
//ClaimHeader claim= pBean.getClaim();

String failureType = claim.getLineItem(0).getFailureType();

if(failureType.equals(ClaimHeader.FAILURE_TYPE_PART))
return true;
else
return false;
}
/*
* helper method to check if claim is for unit failure.
*/
private boolean isUnitFailure(ClaimHeader claim)
{
//ClaimHeader claim= pBean.getClaim();

String failureType = claim.getLineItem(0).getFailureType();

if(failureType.equals(ClaimHeader.FAILURE_TYPE_UNIT))
return true;
else
return false;
}

/*
* returns a PdfPcell.
*/
private PdfPCell getDataCell(String data, boolean headerCell, Color background)
{
Phrase p;
PdfPCell cell;

p = new Phrase();
p.font().setSize(8);
if(headerCell)
p.add(new Phrase(data , new Font(Font.TIMES_ROMAN, 10, Font.BOLD, Color.BLACK)));
else
p.add(new Phrase(data));
cell = new PdfPCell(p);
cell.setBorder(0);
if(background != null)
cell.setBackgroundColor(background);

return cell;
}

/*
* returns an empty cell.
*/
private PdfPCell getEmptyCell()
{

PdfPCell c = new PdfPCell(new Phrase(""));
c.setBorder(0);
return c;
}

/*
* returns a phrase as bold.
*/
private Phrase getBoldPhrase(String data)
{
return new Phrase(data,new Font(Font.TIMES_ROMAN, 10, Font.BOLD, Color.BLACK));
}




}
 
author and iconoclast
Posts: 24206
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This looks like a continuation of your other post, now in Java in General (Beginner). Please change your display name as I asked you in that previous thread; if you post again without changing it, your account will be closed. Thanks.

No idea what "web dynpro" is, but now I see that your question is basically "How do I emit HTML instead of PDF using iText?" The last I checked, iText supported HTML output, so it's just a matter of checking the iText documentation and making a few small changes to your code.

If you don't want to use iText at all, well, then you just have to print HTML, or use some other library -- or forward the query results to a JSP, which is by far the preferred way to do this.

I'm closing this thread and moving it to servlets, in the hopes that someone there will help you understand what I said above.

Please do not start yet another thread; continue this conversation in this same thread in the Servlets forum, after I move it.
 
rk
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
As per my earlier query to print the output in HtML format, I was using the itext third party tool, I don't want to use iText at all, well, just have to print output in HTML format, kindly suggest me the logic of coding.

thanks
rk
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24206
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bye.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually I did see what the problem was, and then I scrolled down - that was a big mistake. When I looked again after scrolling up it was gone - I think.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"rk"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


OK, now about your post up there. There are these cool "CODE" tags that you can place around your code and it will keep your formatting. It will keep the indentation, which will make your code readable.

There is so much code posted up there that it is difficult to spend the time reading it, especially when it isn't formatted.

Next time try to just post the necessary code that will make the point or show where an error might be. It will help everyone out and we can better help you.
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic