Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Messages as request attribute to enforce flash scope when redirect #799

Merged
merged 2 commits into from
Sep 17, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import java.util.List;
import java.util.Map;

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

import org.slf4j.Logger;

Expand All @@ -40,15 +42,39 @@
* @since 4.1
* @author Otávio S Garcia
*/
@Named("vmessages")
@RequestScoped
public class Messages {

public static final String ATTRIBUTE_KEY = "vmessages";

private final static Logger log = getLogger(Messages.class);

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