1
0

Basic implementation for notes app

This commit is contained in:
2022-08-25 17:14:37 +02:00
parent a0239ecda6
commit 2ab4497bd1
22 changed files with 671 additions and 171 deletions

View File

@@ -0,0 +1,43 @@
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);
}
}