-
Notifications
You must be signed in to change notification settings - Fork 329
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
vraptor-core/src/main/java/br/com/caelum/vraptor/validator/MessagesProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package br.com.caelum.vraptor.validator; | ||
|
||
import static com.google.common.base.Objects.firstNonNull; | ||
|
||
import javax.enterprise.context.RequestScoped; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Inject; | ||
|
||
import br.com.caelum.vraptor.Result; | ||
|
||
@RequestScoped | ||
public class MessagesProducer { | ||
|
||
private static final String MESSAGES_KEY = "vmessages"; | ||
|
||
private final Result result; | ||
|
||
/** | ||
* @deprecated CDI eyes only | ||
*/ | ||
protected MessagesProducer() { | ||
this(null); | ||
} | ||
|
||
@Inject | ||
public MessagesProducer(Result result) { | ||
this.result = result; | ||
} | ||
|
||
@Produces @RequestScoped | ||
public Messages create() { | ||
Messages messages = (Messages) result.included().get(MESSAGES_KEY); | ||
messages = firstNonNull(messages, new Messages()); | ||
result.include(MESSAGES_KEY, messages); | ||
return messages; | ||
} | ||
|
||
} |