Skip to content

Commit

Permalink
Adding messages to request attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
garcia-jj committed Sep 17, 2014
1 parent 780bb91 commit b612555
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public <T extends View> T onErrorUse(Class<T> view) {
}

result.include("errors", getErrors());
result.include(Messages.ATTRIBUTE_KEY, messages);
outjector.outjectRequestMap();

logger.debug("there are errors on result: {}", getErrors());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;

Expand All @@ -49,6 +52,29 @@ public class Messages {
private Map<Severity, List<Message>> messages = new HashMap<>();
private boolean unhandledErrors = false;

private final HttpServletRequest request;

/**
* @deprecated CDI eyes only
*/
protected Messages() {
this(null);
}

@Inject
public Messages(HttpServletRequest request) {
this.request = request;
}

/**
* Put this instance into request attributes to allow this instance survive between requests using flash
* scope.
*/
@PostConstruct
public void init() {
request.setAttribute(ATTRIBUTE_KEY, this);
}

public Messages add(Message message) {
get(message.getSeverity()).add(message);
if(Severity.ERROR.equals(message.getSeverity())) {
Expand Down

0 comments on commit b612555

Please sign in to comment.