44 lines
1.3 KiB
Java
44 lines
1.3 KiB
Java
package de.nbscloud.webcontainer;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.ui.Model;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@Component
|
|
public class MessageHelper {
|
|
// We have to temporarily store messages as we redirect: in some methods
|
|
// so everything we add to the model will be gone, that's why we store messages
|
|
// temporarily in here
|
|
private final List<String> errors = new ArrayList<>();
|
|
private final List<String> shareInfo = new ArrayList<>();
|
|
private final List<String> infoMessages = new ArrayList<>();
|
|
|
|
public void addAndClearAll(Model model) {
|
|
model.addAttribute("errors", getAndClear(this.errors));
|
|
model.addAttribute("infoMessages", getAndClear(this.infoMessages));
|
|
model.addAttribute("shareInfo", getAndClear(this.shareInfo));
|
|
}
|
|
|
|
private static List<String> getAndClear(List<String> source) {
|
|
final List<String> retList = new ArrayList<>(source);
|
|
|
|
source.clear();
|
|
|
|
return retList;
|
|
}
|
|
|
|
public void addError(String message) {
|
|
this.errors.add(message);
|
|
}
|
|
|
|
public void addShare(String message) {
|
|
this.shareInfo.add(message);
|
|
}
|
|
|
|
public void addInfo(String message) {
|
|
this.infoMessages.add(message);
|
|
}
|
|
}
|