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 final String ARGS = "alertArgs";
public static ModelAndView showAlert(ModelAndView mav, AlertType alertType, String alertMessage, Object...args) { public static ModelAndView showAlert(ModelAndView mav, AlertType alertType, String alertMessage, Object...args) {
// TODO alerts with args? Map<String, Object> alerts = (Map<String, Object>) mav.getModelMap().getAttribute("alerts");
Map<String, String> alerts = (Map<String, String>) mav.getModelMap().getAttribute("alerts");
if (alerts == null) { if (alerts == null) {
alerts = new HashMap<>(); 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); mav.addObject("alerts", alerts);
return mav; return mav;
} }

View File

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