01: package ru.emdev.EmForge.web.bean;
02:
03: import javax.faces.application.FacesMessage;
04: import javax.faces.application.FacesMessage.Severity;
05: import javax.faces.context.FacesContext;
06:
07: import org.apache.commons.lang.StringUtils;
08: import org.apache.commons.logging.Log;
09: import org.apache.commons.logging.LogFactory;
10:
11: /** Bean responsible for displaying Page Messages
12: */
13: public class PageMessages {
14: private final Log log = LogFactory.getLog(getClass());
15:
16: private String messageHeader;
17: private String messageImage;
18: private Severity severityLevel;
19:
20: /**
21: * Creates a new PageMessages object.
22: */
23: public PageMessages() {
24: messageHeader = null;
25:
26: // See if there are messages queued for the page
27: severityLevel = FacesContext.getCurrentInstance()
28: .getMaximumSeverity();
29:
30: if (null != severityLevel) {
31: log.debug("Severity Level Trapped: level = '"
32: + severityLevel.toString() + "'");
33:
34: if (severityLevel.compareTo(FacesMessage.SEVERITY_ERROR) == 0) {
35: messageHeader = "Error";
36: messageImage = "resources/images/warning.png";
37: } else if (severityLevel
38: .compareTo(FacesMessage.SEVERITY_INFO) == 0) {
39: messageHeader = null;
40: messageImage = "resources/images/information.png";
41: } else if (severityLevel
42: .compareTo(FacesMessage.SEVERITY_WARN) == 0) {
43: messageHeader = null;
44: messageImage = "resources/images/warning.png";
45: } else if (severityLevel
46: .compareTo(FacesMessage.SEVERITY_FATAL) == 0) {
47: messageHeader = "Fatal Error";
48: messageImage = "resources/images/error.png";
49: }
50: } else {
51: log.debug("Severity Level Trapped: level = 'null'");
52: }
53: }
54:
55: /**
56: * DOCUMENT ME!
57: *
58: * @return DOCUMENT ME!
59: */
60: public Boolean getRenderMessage() {
61: return new Boolean(StringUtils.isNotBlank(getMessageHeader()));
62: }
63:
64: /**
65: * DOCUMENT ME!
66: *
67: * @return DOCUMENT ME!
68: */
69: public String getMessageHeader() {
70: return messageHeader;
71: }
72:
73: /**
74: * DOCUMENT ME!
75: *
76: * @return DOCUMENT ME!
77: */
78: public String getMessageImage() {
79: return messageImage;
80: }
81: }
|