1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.shared.context; |
20 | |
|
21 | |
import javax.faces.context.ExceptionHandler; |
22 | |
import javax.faces.context.ExceptionHandlerWrapper; |
23 | |
import javax.faces.context.FacesContext; |
24 | |
import javax.faces.context.PartialViewContext; |
25 | |
import javax.faces.event.AbortProcessingException; |
26 | |
import javax.faces.event.ExceptionQueuedEvent; |
27 | |
import javax.faces.event.ExceptionQueuedEventContext; |
28 | |
import javax.faces.event.SystemEvent; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public class SwitchAjaxExceptionHandlerWrapperImpl extends ExceptionHandlerWrapper |
37 | |
{ |
38 | |
private ExceptionHandler _requestExceptionHandler; |
39 | |
private ExceptionHandler _ajaxExceptionHandler; |
40 | |
private Boolean _isAjaxRequest; |
41 | |
|
42 | |
public SwitchAjaxExceptionHandlerWrapperImpl( |
43 | |
ExceptionHandler requestExceptionHandler, |
44 | |
ExceptionHandler ajaxExceptionHandler) |
45 | 0 | { |
46 | 0 | _requestExceptionHandler = requestExceptionHandler; |
47 | 0 | _ajaxExceptionHandler = ajaxExceptionHandler; |
48 | 0 | } |
49 | |
|
50 | |
@Override |
51 | |
public void processEvent(SystemEvent exceptionQueuedEvent) |
52 | |
throws AbortProcessingException |
53 | |
{ |
54 | |
|
55 | 0 | isAjaxRequest(exceptionQueuedEvent); |
56 | 0 | super.processEvent(exceptionQueuedEvent); |
57 | 0 | } |
58 | |
|
59 | |
protected boolean isAjaxRequest(SystemEvent exceptionQueuedEvent) |
60 | |
{ |
61 | 0 | if (_isAjaxRequest == null) |
62 | |
{ |
63 | 0 | if (exceptionQueuedEvent instanceof ExceptionQueuedEvent) |
64 | |
{ |
65 | 0 | ExceptionQueuedEvent eqe = (ExceptionQueuedEvent)exceptionQueuedEvent; |
66 | 0 | ExceptionQueuedEventContext eqec = eqe.getContext(); |
67 | 0 | if (eqec != null) |
68 | |
{ |
69 | 0 | FacesContext facesContext = eqec.getContext(); |
70 | 0 | if (facesContext != null) |
71 | |
{ |
72 | 0 | return isAjaxRequest(facesContext); |
73 | |
} |
74 | |
} |
75 | |
} |
76 | 0 | return isAjaxRequest(); |
77 | |
} |
78 | 0 | return _isAjaxRequest; |
79 | |
} |
80 | |
|
81 | |
protected boolean isAjaxRequest(FacesContext facesContext) |
82 | |
{ |
83 | 0 | if (_isAjaxRequest == null) |
84 | |
{ |
85 | 0 | facesContext = (facesContext == null) ? FacesContext.getCurrentInstance() : facesContext; |
86 | 0 | PartialViewContext pvc = facesContext.getPartialViewContext(); |
87 | 0 | if (pvc == null) |
88 | |
{ |
89 | 0 | return false; |
90 | |
} |
91 | 0 | _isAjaxRequest = pvc.isAjaxRequest(); |
92 | |
} |
93 | 0 | return _isAjaxRequest; |
94 | |
} |
95 | |
|
96 | |
protected boolean isAjaxRequest() |
97 | |
{ |
98 | 0 | if (_isAjaxRequest == null) |
99 | |
{ |
100 | 0 | FacesContext facesContext = FacesContext.getCurrentInstance(); |
101 | 0 | PartialViewContext pvc = facesContext.getPartialViewContext(); |
102 | 0 | if (pvc == null) |
103 | |
{ |
104 | 0 | return false; |
105 | |
} |
106 | 0 | _isAjaxRequest = pvc.isAjaxRequest(); |
107 | |
} |
108 | 0 | return _isAjaxRequest; |
109 | |
} |
110 | |
|
111 | |
@Override |
112 | |
public ExceptionHandler getWrapped() |
113 | |
{ |
114 | 0 | if (isAjaxRequest()) |
115 | |
{ |
116 | 0 | return _ajaxExceptionHandler; |
117 | |
} |
118 | |
else |
119 | |
{ |
120 | 0 | return _requestExceptionHandler; |
121 | |
} |
122 | |
} |
123 | |
} |