Commit | Line | Data |
---|---|---|
1efa4016 MS |
1 | /* |
2 | * To change this template, choose Tools | Templates | |
3 | * and open the template in the editor. | |
4 | */ | |
5 | package org.ufcspa.simdecs.diagram.mb; | |
6 | ||
7 | import java.util.Locale; | |
8 | import javax.el.ExpressionFactory; | |
9 | import javax.faces.application.FacesMessage; | |
10 | import javax.faces.application.FacesMessage.Severity; | |
11 | import javax.faces.component.UIComponent; | |
12 | import javax.faces.context.FacesContext; | |
13 | import org.ufcspa.simdecs.diagram.util.MessageResourceUtils; | |
14 | ||
15 | /** | |
16 | * | |
17 | * @author Maroni | |
18 | */ | |
19 | public abstract class DefaultManagedBean { | |
20 | ||
21 | public Locale getLocale() { | |
22 | return getFacesContext().getViewRoot().getLocale(); | |
23 | } | |
24 | ||
25 | public void addMessage(String componentID, Severity severity, String i18nTitle, String i18nMessage) { | |
26 | FacesContext.getCurrentInstance().addMessage(componentID, new FacesMessage(severity, getResourceMessage(i18nTitle), getResourceMessage(i18nMessage))); | |
27 | } | |
28 | ||
29 | public void addInfoMessage(String componentID, String i18nTitle, String i18nMessage) { | |
30 | addMessage(componentID, FacesMessage.SEVERITY_INFO, i18nTitle, i18nMessage); | |
31 | } | |
32 | ||
33 | public void addInfoMessage(String i18nTitle, String i18nMessage) { | |
34 | addInfoMessage(null, i18nTitle, i18nMessage); | |
35 | } | |
36 | ||
37 | public void addWarnMessage(String componentID, String i18nTitle, String i18nMessage) { | |
38 | addMessage(componentID, FacesMessage.SEVERITY_WARN, i18nTitle, i18nMessage); | |
39 | } | |
40 | ||
41 | public void addWarnMessage(String i18nTitle, String i18nMessage) { | |
42 | addWarnMessage(null, i18nTitle, i18nMessage); | |
43 | } | |
44 | ||
45 | public void addErrorMessage(String componentID, String i18nTitle, String i18nMessage) { | |
46 | addMessage(componentID, FacesMessage.SEVERITY_ERROR, i18nTitle, i18nMessage); | |
47 | } | |
48 | ||
49 | public void addErrorMessage(String i18nTitle, String i18nMessage) { | |
50 | addErrorMessage(null, i18nTitle, i18nMessage); | |
51 | } | |
52 | ||
53 | protected String getTextParameter(String paramName) { | |
54 | return (String) getFacesContext().getExternalContext().getRequestParameterMap().get(paramName); | |
55 | } | |
56 | ||
57 | protected Object getParameter(String paramName) { | |
58 | return getFacesContext().getExternalContext().getRequestParameterMap().get(paramName); | |
59 | } | |
60 | ||
61 | protected FacesContext getFacesContext() { | |
62 | return FacesContext.getCurrentInstance(); | |
63 | } | |
64 | ||
65 | ||
66 | protected UIComponent getComponentById(String componentId) { | |
67 | return getFacesContext().getViewRoot().findComponent(componentId); | |
68 | } | |
69 | ||
70 | protected String getMessageBundle() { | |
71 | return getFacesContext().getApplication().getMessageBundle(); | |
72 | } | |
73 | ||
74 | protected String getResourceMessage(String key, Object params[]) { | |
75 | return MessageResourceUtils.getMessageResourceString(getMessageBundle(), key, params, getFacesContext().getViewRoot() | |
76 | .getLocale()); | |
77 | } | |
78 | ||
79 | protected String getResourceMessage(String key) { | |
80 | return getResourceMessage(key, null); | |
81 | } | |
82 | ||
83 | protected ExpressionFactory getExpressionFactory() { | |
84 | return getFacesContext().getApplication().getExpressionFactory(); | |
85 | } | |
86 | } |