added the option to have arguments with the alerts

This commit is contained in:
realDragonium 2020-08-22 12:34:43 +02:00 committed by MiniDigger
parent 2ed3100550
commit db9cb04792
2 changed files with 12 additions and 5 deletions

View File

@ -21,12 +21,14 @@ public class AlertUtil {
public static final String ARGS = "alertArgs";
public static ModelAndView showAlert(ModelAndView mav, AlertType alertType, String alertMessage, Object...args) {
// TODO alerts with args?
Map<String, String> alerts = (Map<String, String>) mav.getModelMap().getAttribute("alerts");
Map<String, Object> alerts = (Map<String, Object>) mav.getModelMap().getAttribute("alerts");
if (alerts == null) {
alerts = new HashMap<>();
}
alerts.put(alertType.name().toLowerCase(), alertMessage);
Map<String, Object> thisAlert = new HashMap<>();
thisAlert.put("message", alertMessage);
thisAlert.put("args", args);
alerts.put(alertType.name().toLowerCase(), thisAlert);
mav.addObject("alerts", alerts);
return mav;
}

View File

@ -16,9 +16,14 @@
</#macro>
<#macro normalAlert alertType>
<#assign message=alerts[alertType]>
<#assign message=alerts[alertType]["message"]>
<#assign args=alerts[alertType]["args"]>
<#if message??>
<@spring.message message />
<#if args??>
<@spring.messageArgs message args />
<#else>
<@spring.message message />
</#if>
</#if>
</#macro>