Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/entry/beans/AbstractBean.java @ 105:e27603a39e70
small cleanups.
author | casties |
---|---|
date | Fri, 04 Nov 2016 18:10:40 +0100 |
parents | d2cee1040062 |
children | e5d4443a1bc5 |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.entry.beans; |
2 | |
3 import java.io.IOException; | |
4 import java.io.Serializable; | |
5 import java.text.DateFormat; | |
6 import java.util.Date; | |
7 | |
8 import javax.faces.context.ExternalContext; | |
9 import javax.faces.context.FacesContext; | |
10 | |
11 import org.apache.commons.lang.StringUtils; | |
12 import org.mpi.openmind.cache.WrapperService; | |
13 | |
14 public abstract class AbstractBean implements Serializable{ | |
15 | |
16 private static final long serialVersionUID = -8646299519985691771L; | |
94
d2cee1040062
new servlet lifecycle listener to shut down Spring ApplicationBean.
casties
parents:
82
diff
changeset
|
17 public static String BEAN_APP = "ApplicationBean1"; |
d2cee1040062
new servlet lifecycle listener to shut down Spring ApplicationBean.
casties
parents:
82
diff
changeset
|
18 public static String BEAN_SESSION = "Session"; |
1 | 19 |
20 public Object getRequestBean(String name){ | |
21 return FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get(name); | |
22 } | |
23 | |
24 public Object getSessionBean(String name){ | |
25 return FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(name); | |
26 } | |
27 | |
28 public Object getApplicationBean(String name){ | |
29 return FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get(name); | |
30 } | |
31 | |
32 public void addSessionBean(String name, Object bean){ | |
33 FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(name, bean); | |
34 } | |
35 | |
36 public ApplicationBean getAppBean(){ | |
37 ApplicationBean app = (ApplicationBean)getApplicationBean(BEAN_APP); | |
38 if(app == null){ | |
39 app = new ApplicationBean(); | |
40 FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().put(BEAN_APP, app); | |
41 } | |
42 return app; | |
43 } | |
44 | |
45 protected void printInternalError(Exception e){ | |
46 addErrorMsg("Internal Error, this action could not be executed correctly."); | |
82
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
47 addErrorMsg("Error:"); |
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
48 addErrorMsg(e.toString()); |
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
49 addErrorMsg(e.getStackTrace()[0].toString()); |
1 | 50 addErrorMsg("Server time: " + DateFormat.getDateTimeInstance().format(new Date())); |
82
c000b4b386bc
better "internal error" message. fix NPE when codex has no identifier.
casties
parents:
1
diff
changeset
|
51 addErrorMsg("Please inform support: casties@mpiwg-berlin.mpg.de"); |
1 | 52 } |
53 | |
54 protected SessionBean getSessionBean() { | |
55 SessionBean session = | |
56 ((SessionBean)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(BEAN_SESSION)); | |
57 if(session == null){ | |
58 session = new SessionBean(); | |
59 FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(BEAN_SESSION, session); | |
60 } | |
61 return session; | |
62 } | |
63 | |
64 public void addGeneralMsg(String msg){ | |
65 System.out.println(msg); | |
66 this.getSessionBean().addGeneralMsg(msg); | |
67 } | |
68 | |
69 public void addErrorMsg(String msg){ | |
70 this.getSessionBean().addErrorMsg(msg); | |
71 } | |
72 | |
73 public void addException(Exception e){ | |
74 this.getSessionBean().addErrorMsg("Internal error: " + e.getMessage()); | |
75 } | |
76 | |
77 protected void redirect(String redirectPath, String parameters){ | |
78 FacesContext fc = FacesContext.getCurrentInstance(); | |
79 ExternalContext ec = fc.getExternalContext(); | |
80 String contextPath = ec.getRequestContextPath(); | |
81 if(StringUtils.isEmpty(redirectPath)){ | |
82 redirectPath = ec.getRequestServletPath(); | |
83 } | |
84 try { | |
85 //System.out.println(contextPath + redirectPath + parameters); | |
86 ec.redirect(ec.encodeActionURL(contextPath + redirectPath + parameters)); | |
87 | |
88 //ec.redirect(contextPath + redirectPath + parameters); | |
89 } catch (IOException e) { | |
90 e.printStackTrace(); | |
91 } | |
92 } | |
93 | |
94 protected WrapperService getWrapper() { | |
95 return getAppBean().getWrapper(); | |
96 } | |
97 } |