1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.custom.scope;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import javax.faces.context.FacesContext;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public class ScopeUtils
41 {
42 private static final String EL_END = "}";
43 private static final String EL_BEGIN = "#{";
44 private static Log log = LogFactory.getLog(ScopeUtils.class);
45
46
47
48
49
50
51
52 public static final boolean isEl(String beanName)
53 {
54 beanName = beanName.trim();
55 return beanName.startsWith(EL_BEGIN) && beanName.endsWith(EL_END);
56 }
57
58
59
60
61
62
63 public static Object getManagedBean(String beanName)
64 {
65 if (isEl(beanName))
66 {
67 if(FacesContext.getCurrentInstance() == null)
68 return null;
69
70 return FacesContext.getCurrentInstance().getApplication()
71 .createValueBinding(beanName).getValue(
72 FacesContext.getCurrentInstance());
73 }
74 else
75 {
76 try
77 {
78 if(FacesContext.getCurrentInstance() == null)
79 return null;
80
81 return FacesContext.getCurrentInstance().getApplication()
82 .createValueBinding(EL_BEGIN + beanName + EL_END).getValue(
83 FacesContext.getCurrentInstance());
84 }
85 catch(Exception ex)
86 {
87 log.info("ScopeContainer not found - has not been initialized.",ex);
88 return null;
89 }
90 }
91 }
92
93 }