Solved

Java Report Alignment problem

Posted on 2011-09-26
12
199 Views
Last Modified: 2012-05-12
Hi Experts...
I have the code below which i use to send mail in html format.

The html report is getting prepared properly and the mail feature is working too.
The problem is :Say for example in my html report i have three HTML tables to be displayed they all take center alignment by default and appear one below the other.

When i explicitly add the left alignment code all the tables appear next to one another instead of one below the other.
Please help...
Code for html report:
                           String htmlString = "";
  htmlString += "<html>" + sep;
htmlString += "<head>" + sep;

htmlString += "<title>Your title</title></head><body>";


htmlString += "<table> <tr> <td> stuff</td><td>antother cell</td> </tr>" +
"<tr> <td> stuff</td><td>antother cell</td> </tr>" +
" <tr> <td> stuff</td><td>antother cell</td> </tr></table></body></html>";

Open in new window

Code for mailing:
public void sendEmail(String htmlString, Vector OAEmailAddresses,
                      Vector emailAddressesCC, String userAddress, String subject)
   {


 String adrFrom = userAddress;
      String signature = "";
     String sepp = System.getProperty("line.separator");


       String body = bodyText;

   InternetAddress [] intAdd;
    InternetAddress [] intAddcc;


  intAdd = new InternetAddress[OAEmailAddresses.size()];

    intAddcc = new InternetAddress[emailAddressesCC.size()];



       try {
  for(int j=0; j<OAEmailAddresses.size(); j++)
    intAdd[j] = new InternetAddress((String)OAEmailAddresses.elementAt(j));

    for(int j=0; j<emailAddressesCC.size(); j++)
    intAddcc[j] = new InternetAddress((String)emailAddressesCC.elementAt(j));



    Properties props = new Properties();

	
	props.put("mail.smtp.host", "mailhub.company.com");
	Session session = Session.getDefaultInstance(props, null);
	    Message msg = new MimeMessage(session);
	    msg.setFrom(new InternetAddress(adrFrom));
 

	    msg.setRecipients(Message.RecipientType.TO, intAdd);
            msg.setRecipients(Message.RecipientType.CC, intAddcc);
             msg.setSubject(subject );


        msg.setSentDate(new java.util.Date());

	    msg.setText(htmlString);
           msg.setHeader("Content-Type","text/html");  // this is important header

	    Transport.send(msg);
           }
       catch (Exception e) {System.out.println("Error sending e-mail : " + e.toString()); e.printStackTrace(); }
     System.out.println("E-mail message sent!");


}

Open in new window

0
Comment
Question by:gaugeta
  • 7
  • 3
12 Comments
 
LVL 3

Expert Comment

by:anjos
ID: 36597777
Have you tried just adding a <br /> after each table?
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36597852
In what place do you add left alignement code?
0
 

Author Comment

by:gaugeta
ID: 36597962
@for_yan:For example i have 2 tables i added the alignment code as shown.
Please help...
htmlString += "<table align=\"left\"> <tr> <td> stuff</td><td>antother cell</td> </tr>" +
"<tr> <td> stuff</td><td>antother cell</td> </tr>" +
" <tr> <td> stuff</td><td>antother cell</td> </tr></table></body></html>"; 

htmlString += "<table align=\"left\"> <tr> <td> stuff</td><td>antother cell</td> </tr>" +
"<tr> <td> stuff</td><td>antother cell</td> </tr>" +
" <tr> <td> stuff</td><td>antother cell</td> </tr></table></body></html>";

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36597978
In general you should not have </body></html> after each table - these usually come only in the end of the whole web page
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36597982
Why do you need to add align - what is it that you wanted to achieve with it?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:gaugeta
ID: 36598057
@for_yan:Sorry for the above code.I just gave a sample of how it will look.
Each table does not have a </body></html> with it.

The valid code is shown below.

The effect i want to achieve is display table left aligned and and one below the other and not next to one another which is happening now.
Please help...
htmlString +="<left><table align=\"left\"><tr><td><h3>Final Status: Pass</h5></h3></td></tr></table></left>"; htmlString +="<left><table align=\"left\"><tr><td><h3>Final Status2: Pass</h5></h3></td></tr></table></left>";

Open in new window

0
 

Author Comment

by:gaugeta
ID: 36598274
@anjos:Yes i've added thr <br/> after each table.
Yet its not going to the next line.
Please help...
0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 36602396
<div align="center"> before the firs <table>

then </div> after the </table>

then again <div align="center">  before the next <table>

and then again </div> after the last </table>

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36602409
Does it send email ain any form?

If it does go to your emal - double click on it, then right-click in the middle and slecet "ViewSource"

Then you'll see notepad (or other editor ) window with html code.
Save the contents of that window to any .txt or .html file and post this file here - I'll correct your html
and tell you how to modify it to have them one under another

This deivision recommendation above shoudll work - if you understadn it from what I wrote above - you can give it a try
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36602417
Of course remove tehse tags <left> - theye dhouldf not be there <table align=\"left\"> - these should stay

htmlString +="<table align=\"left\"><tr><td><h3>Final Status: Pass</h5></h3></td></tr></table>"; htmlString +="<table align=\"left\"><tr><td><h3>Final Status2: Pass</h5></h3></td></tr></table>";

Open in new window

0
 
LVL 47

Expert Comment

by:for_yan
ID: 36602425
if the above post does not help then add disvisions like that:

htmlString +="<div><table align=\"left\"><tr><td><h3>Final Status: Pass</h5></h3></td></tr></table></div>"; htmlString +="<div><table align=\"left\"><tr><td><h3>Final Status2: Pass</h5></h3></td></tr></table></div>";

Open in new window



0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

895 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

20 Experts available now in Live!

Get 1:1 Help Now