1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.shared_orchestra.util;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25 import javax.faces.context.FacesContext;
26 import javax.faces.component.UIComponent;
27 import javax.faces.component.UIInput;
28 import javax.faces.el.ValueBinding;
29 import java.util.Iterator;
30 import java.lang.reflect.Method;
31
32
33
34
35
36 public class RestoreStateUtils
37 {
38 private static Log log = LogFactory.getLog(RestoreStateUtils.class);
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 public static void recursivelyHandleComponentReferencesAndSetValid(FacesContext facesContext,
55 UIComponent parent)
56 {
57 recursivelyHandleComponentReferencesAndSetValid(facesContext, parent, false);
58 }
59
60 public static void recursivelyHandleComponentReferencesAndSetValid(FacesContext facesContext,
61 UIComponent parent, boolean forceHandle)
62 {
63 Method handleBindingsMethod = getBindingMethod(parent);
64
65 if(handleBindingsMethod!=null && !forceHandle)
66 {
67 try
68 {
69 handleBindingsMethod.invoke(parent,new Object[]{});
70 }
71 catch (Throwable th)
72 {
73 log.error("Exception while invoking handleBindings on component with client-id:"
74 +parent.getClientId(facesContext),th);
75 }
76 }
77 else
78 {
79 for (Iterator it = parent.getFacetsAndChildren(); it.hasNext(); )
80 {
81 UIComponent component = (UIComponent)it.next();
82
83 ValueBinding binding = component.getValueBinding("binding");
84 if (binding != null && !binding.isReadOnly(facesContext))
85 {
86 binding.setValue(facesContext, component);
87 }
88
89 if (component instanceof UIInput)
90 {
91 ((UIInput)component).setValid(true);
92 }
93
94 recursivelyHandleComponentReferencesAndSetValid(facesContext, component);
95 }
96 }
97 }
98
99
100
101
102
103
104 private static Method getBindingMethod(UIComponent parent)
105 {
106 Class[] clazzes = parent.getClass().getInterfaces();
107
108 for (int i = 0; i < clazzes.length; i++)
109 {
110 Class clazz = clazzes[i];
111
112 if(clazz.getName().indexOf("BindingAware")!=-1)
113 {
114 try
115 {
116 return parent.getClass().getMethod("handleBindings",new Class[]{});
117 }
118 catch (NoSuchMethodException e)
119 {
120
121 }
122 }
123 }
124
125 return null;
126 }
127 }