Skip to content

Commit

Permalink
checking included before including
Browse files Browse the repository at this point in the history
  • Loading branch information
Turini committed Sep 17, 2014
1 parent 1dd7e4e commit 753b2da
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;

import br.com.caelum.vraptor.Result;

/**
* Managed class that stores all application messages like errors, warnings and info. This
* class is useful to display messages categorized by severity in your view. To choose a severity
Expand All @@ -52,27 +53,25 @@ public class Messages {
private Map<Severity, List<Message>> messages = new HashMap<>();
private boolean unhandledErrors = false;

private final HttpServletRequest request;
private final Result result;

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

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

/**
* 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);
protected void init() {
if(!result.included().containsKey(ATTRIBUTE_KEY)){
result.include(ATTRIBUTE_KEY, this);
}
}

public Messages add(Message message) {
Expand Down

0 comments on commit 753b2da

Please sign in to comment.