1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package javax.faces.render; |
20 | |
|
21 | |
import javax.faces.application.StateManager; |
22 | |
import javax.faces.application.StateManager.SerializedView; |
23 | |
import javax.faces.context.FacesContext; |
24 | |
import java.io.IOException; |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | 0 | public abstract class ResponseStateManager |
34 | |
{ |
35 | |
public static final String RENDER_KIT_ID_PARAM = "javax.faces.RenderKitId"; |
36 | |
public static final String VIEW_STATE_PARAM = "javax.faces.ViewState"; |
37 | |
|
38 | |
public void writeState(FacesContext context, Object state) throws IOException{ |
39 | |
SerializedView view; |
40 | 0 | if (state instanceof SerializedView) |
41 | |
{ |
42 | 0 | view = (SerializedView) state; |
43 | |
} |
44 | |
else |
45 | 0 | if (state instanceof Object[]) |
46 | |
{ |
47 | 0 | Object[] structureAndState = (Object[]) state; |
48 | |
|
49 | 0 | if (structureAndState.length == 2) |
50 | |
{ |
51 | 0 | Object structureObj = structureAndState[0]; |
52 | 0 | Object stateObj = structureAndState[1]; |
53 | |
|
54 | 0 | StateManager stateManager = context.getApplication().getStateManager(); |
55 | 0 | view = stateManager.new SerializedView(structureObj, stateObj); |
56 | 0 | } |
57 | |
else |
58 | |
{ |
59 | 0 | throw new IOException("The state should be an array of Object[] of lenght 2"); |
60 | |
} |
61 | 0 | } |
62 | |
else |
63 | |
{ |
64 | 0 | throw new IOException("The state should be an array of Object[] of lenght 2, or a SerializedView instance"); |
65 | |
} |
66 | |
|
67 | 0 | writeState(context, view); |
68 | 0 | } |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
public void writeState(FacesContext context, |
74 | |
StateManager.SerializedView state) |
75 | |
throws IOException { |
76 | |
|
77 | 0 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public Object getState(FacesContext context, String viewId) { |
83 | 0 | Object[] structureAndState = new Object[2]; |
84 | 0 | structureAndState[0] = getTreeStructureToRestore(context, viewId); |
85 | 0 | structureAndState[1] = getComponentStateToRestore(context); |
86 | 0 | return structureAndState; |
87 | |
} |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
public Object getTreeStructureToRestore(FacesContext context, |
94 | |
String viewId) { |
95 | 0 | return null; |
96 | |
} |
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public Object getComponentStateToRestore(FacesContext context) { |
103 | 0 | return null; |
104 | |
} |
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
public boolean isPostback(FacesContext context) { |
111 | 0 | return context.getExternalContext(). |
112 | |
getRequestParameterMap().containsKey( |
113 | |
ResponseStateManager.VIEW_STATE_PARAM); |
114 | |
} |
115 | |
|
116 | |
} |