Issue
Hello I have a mail batch and inside the mail text I have an html block. I have a table and inside I am giving data with a for loop. But I want to add inside not only one row of data, but also if there are more records I also want to include them. I am adding screenshot and code below. When you look at the pictures it will be more clear I think. Thank you from now for your advices.
public String createMailBody(List<VposNotificationBatchDto> notificationList) {
String mailBody = "Merhaba,<br/><br/>Güvenlik Raporu için günlük işlem sayıları detayları aşağıdaki gibidir.";
String errorBody = "errorBody";
mailBody += errorBody;
mailBody += "<br/><br/><br/>";
mailBody += "<html><head><style>table{font-family: arial, sans-serif;border-collapse: collapse;width: 75%;}th{background-color: #9A9A9A;}";
mailBody += "td,th{border: 1px solid #dddddd;text-align: left;padding: 8px;}tr:nth-child(even){background-color: #dddddd;}</style>";
mailBody += "</head><body><h3>Job Çalışma Detayları : </h3><table><tr><th>MID</th><th>MD STATUS</th><th>BIN</th><th>COUNT</th><th>RATIO</th><th>MERCHANT NAME</th></tr>";
for (int i = 0; i < notificationList.size(); i++) {
mailBody += "<tr><td>" + notificationList.get(i).getMid() + "</td>";
mailBody += "<td>" + notificationList.get(i).getMdStatus() + "</td>";
mailBody += "<td>" + notificationList.get(i).getBin() + "</td>";
mailBody += "<td>" + notificationList.get(i).getCount() + "</td>";
mailBody += "<td>" + notificationList.get(i).getRatio() + "</td>";
mailBody += "<td>" + notificationList.get(i).getMerchantName() + "</td></tr>";
mailBody += endOfHtmlString;
//mailBody += "<br/><br/><br/><br/>";
//mailBody += createMetricDetails(vposNotificationBatchDtoList,i);
String currentMailSubject = batchProps.getJobProps().get(jobName).getAlertProps().getMailSubject();
if (severity == Constants.SEVERITY_SUCCESS) {
mailBody = mailBody.replace("th{background-color: #9A9A9A;}","th{background-color: #5FA8CC;}");
mailBody = mailBody.replace("errorBody","");
} else if (severity == Constants.SEVERITY_ERROR) {
mailBody = mailBody.replace("th{background-color: #9A9A9A;}","th{background-color: #DE0202;}");
mailBody = mailBody.replace("errorBody","<br/><br/><br/><div style=\"width: 75%;\">"
+ "<h4 style=\"background-color:yellow; color:#701500; border: 1px solid\">Lütfen aşağıda belirtilen "
+ "metrikleri kontrol ediniz : <br/><br/>" + reportErrorMessage + "</h4></div>");
} else if (severity == Constants.SEVERITY_WARNING) {
mailBody = mailBody.replace("th{background-color: #9A9A9A;}","th{background-color: #E96A06;}");
mailBody = mailBody.replace("errorBody","<br/><br/><br/><div style=\"width: 75%;\">"
+ "<h4 style=\"background-color:yellow; color:#701500; border: 1px solid\">Lütfen aşağıda belirtilen metrikleri "
+ "kontrol ediniz : <br/><br/><h3>" + reportErrorMessage + "</h4></div>");
break;
}
}
mailBody += endOfHtmlString;
return mailBody;
}
Solution
remove the break
which is close to the end brakcet of the for-loop?
with the break you jump out of the for loop.
And what is the vlaue of the String variable endOfHtmlString
?
you add this twice to the mailBody
.
- once in the for loop
- another time after the for loop.
that could lead to the shown behavior in the screenshot, when for example the variable contents the closing body-tag!
Answered By - Tobias Hochgürtel
Answer Checked By - David Goodson (JavaFixing Volunteer)