1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.internal.component;
21
22 import org.apache.myfaces.tobago.compat.InvokeOnComponent;
23 import org.apache.myfaces.tobago.component.Form;
24 import org.apache.myfaces.tobago.util.ComponentUtils;
25 import org.apache.myfaces.tobago.util.TobagoCallback;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 import javax.faces.FacesException;
30 import javax.faces.component.ContextCallback;
31 import javax.faces.component.UIComponent;
32 import javax.faces.component.UIForm;
33 import javax.faces.context.FacesContext;
34 import javax.faces.event.PhaseId;
35 import java.util.Iterator;
36
37 public abstract class AbstractUIForm extends UIForm implements InvokeOnComponent, Form {
38
39 private static final Logger LOG = LoggerFactory.getLogger(AbstractUIForm.class);
40
41 public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Form";
42 public static final String SUBMITTED_MARKER = COMPONENT_TYPE + ".InSubmitted";
43
44 @Override
45 public void processDecodes(FacesContext facesContext) {
46
47
48
49
50 decode(facesContext);
51
52 Iterator kids = getFacetsAndChildren();
53 while (kids.hasNext()) {
54 UIComponent kid = (UIComponent) kids.next();
55 kid.processDecodes(facesContext);
56 }
57 }
58
59 @Override
60 public void setSubmitted(boolean b) {
61 super.setSubmitted(b);
62
63
64 for (AbstractUIForm subForm : ComponentUtils.findSubForms(this)) {
65 subForm.setSubmitted(b);
66 }
67 }
68
69 @Override
70 public void processValidators(FacesContext facesContext) {
71
72 if (LOG.isDebugEnabled()) {
73 LOG.debug("processValidators for form: {}", getClientId(facesContext));
74 }
75 if (!isSubmitted()) {
76 for (AbstractUIForm subForm : ComponentUtils.findSubForms(this)) {
77 subForm.processValidators(facesContext);
78 }
79 } else {
80
81 Iterator kids = getFacetsAndChildren();
82 while (kids.hasNext()) {
83 UIComponent kid = (UIComponent) kids.next();
84 kid.processValidators(facesContext);
85 }
86 }
87 }
88
89 @Override
90 public void processUpdates(FacesContext facesContext) {
91
92 if (LOG.isDebugEnabled()) {
93 LOG.debug("processUpdates for form: {}", getClientId(facesContext));
94 }
95 if (!isSubmitted()) {
96 for (AbstractUIForm subForm : ComponentUtils.findSubForms(this)) {
97 subForm.processUpdates(facesContext);
98 }
99 } else {
100
101 Iterator kids = getFacetsAndChildren();
102 while (kids.hasNext()) {
103 UIComponent kid = (UIComponent) kids.next();
104 kid.processUpdates(facesContext);
105 }
106 }
107 }
108
109 @Override
110 public boolean invokeOnComponent(FacesContext context, String clientId, ContextCallback callback)
111 throws FacesException {
112
113 if (callback instanceof TobagoCallback) {
114 if (PhaseId.APPLY_REQUEST_VALUES.equals(((TobagoCallback) callback).getPhaseId())) {
115 decode(context);
116 }
117 }
118 context.getExternalContext().getRequestMap().put(AbstractUIForm.SUBMITTED_MARKER, isSubmitted());
119 return ComponentUtils.invokeOnComponent(context, this, clientId, callback);
120 }
121 }