Implemented changes regarding the latest review.

This commit is contained in:
oreva 2016-11-06 12:07:51 +02:00
parent 4d46d52733
commit 807a4d2db9
3 changed files with 86 additions and 36 deletions

View File

@ -13,7 +13,12 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
/**
* Created by Olga on 7/20/2016.
@ -31,8 +36,50 @@ public class MailController {
@Qualifier("templateSimpleMessage")
public SimpleMailMessage template;
private static final Map<String, Map<String, String>> labels;
static {
labels = new HashMap<>();
//Simple email
Map<String, String> props = new HashMap<>();
props.put("headerText", "Send Simple Email");
props.put("messageLabel", "Message");
props.put("additionalInfo", "");
labels.put("send", props);
//Email with template
props = new HashMap<>();
props.put("headerText", "Send Email Using Template");
props.put("messageLabel", "Template Parameter");
props.put("additionalInfo",
"The parameter value will be added to the following message template:<br>" +
"<b>This is the test email template for your email:<br>'Template Parameter'</b>"
);
labels.put("sendTemplate", props);
//Email with attachment
props = new HashMap<>();
props.put("headerText", "Send Email With Attachment");
props.put("messageLabel", "Message");
props.put("additionalInfo", "To make sure that you send an attachment with this email, change the value for the 'attachment.invoice' in the application.properties file to the path to the attachment.");
labels.put("sendAttachment", props);
}
@RequestMapping(value = {"/send", "/sendTemplate", "/sendAttachment"}, method = RequestMethod.GET)
public String createMail(Model model) {
public String createMail(Model model,
HttpServletRequest request) {
String action = request.getRequestURL().substring(
request.getRequestURL().lastIndexOf("/") + 1
);
Map<String, String> props = labels.get(action);
Set<String> keys = props.keySet();
Iterator<String> iterator = keys.iterator();
while (iterator.hasNext()) {
String key = iterator.next();
model.addAttribute(key, props.get(key));
}
model.addAttribute("mailObject", new MailObject());
return "mail/send";
}

View File

@ -18,4 +18,3 @@ spring.mail.properties.mail.smtp.starttls.enable=true
# path to attachment file
attachment.invoice=path_to_file
#attachment.invoice=c:/invoice.jpg

View File

@ -13,10 +13,11 @@
</head>
<body>
<div>
<h3>Create Email</h3>
<form:form method="POST" modelAttribute="mailObject">
<h3>${headerText}</h3>
<form:form method="POST" modelAttribute="mailObject" >
<fieldset>
<table cellspacing="0">
<div style="float:left;">
<table cellspacing="0" width="300">
<tr>
<th><label for="input_to">To</label></th>
<td><form:input path="to" id="input_to" type="email"/>
@ -32,11 +33,10 @@
</td>
</tr>
<tr>
<th><label for="input_text">Message:</label></th>
<th><label for="input_text">${messageLabel}:</label></th>
<td><form:textarea path="text"
rows="5" cols="50"
id="input_text"/>
<small>Enter message text</small><br/>
<form:errors path="text" cssStyle="color:red;font-size:small"/>
</td>
</tr>
@ -47,6 +47,10 @@
</td>
</tr>
</table>
</div>
<div style="float:left; word-wrap: break-word; margin-left: 50px; width: 400px; color: grey">
${additionalInfo}
</div>
</fieldset>
</form:form>
</div>