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.util.ComponentUtils;
23 import org.apache.myfaces.tobago.util.DebugUtils;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 import javax.faces.component.UIComponent;
28 import javax.faces.component.UIViewRoot;
29 import javax.faces.component.behavior.ClientBehaviorHolder;
30 import javax.faces.context.FacesContext;
31 import java.lang.invoke.MethodHandles;
32 import java.nio.charset.Charset;
33 import java.nio.charset.StandardCharsets;
34 import java.util.Iterator;
35
36
37
38
39 public abstract class AbstractUIPage extends AbstractUIFormBase implements ClientBehaviorHolder {
40
41 private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
42
43
44
45
46 @Deprecated
47 public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Page";
48
49 public static final Charset FORM_ACCEPT_CHARSET = StandardCharsets.UTF_8;
50
51 private String formId;
52
53 @Override
54 public boolean getRendersChildren() {
55 return true;
56 }
57
58 public String getFormId(final FacesContext facesContext) {
59 if (formId == null) {
60 formId = getClientId(facesContext) + ComponentUtils.SUB_SEPARATOR + "form";
61 }
62 return formId;
63 }
64
65 @Override
66 public void processDecodes(final FacesContext context) {
67
68 decode(context);
69
70 markSubmittedForm(context);
71
72
73 for (final Iterator kids = getFacetsAndChildren(); kids.hasNext();) {
74 final UIComponent kid = (UIComponent) kids.next();
75 kid.processDecodes(context);
76 }
77 }
78
79 public void markSubmittedForm(final FacesContext facesContext) {
80
81
82
83 final UIViewRoot viewRoot = facesContext.getViewRoot();
84
85
86 setSubmitted(false);
87
88 String sourceId = facesContext.getExternalContext().getRequestParameterMap().get("javax.faces.source");
89 UIComponent command = null;
90 if (sourceId != null) {
91 if (LOG.isDebugEnabled()) {
92 LOG.debug("sourceId = '" + sourceId + "'");
93 }
94 command = viewRoot.findComponent(sourceId);
95 } else {
96 LOG.warn("No sourceId found!");
97 }
98
99
100 if (command == null
101 && sourceId != null && sourceId.matches(".*:\\d+:.*")) {
102
103
104
105
106 sourceId = sourceId.replaceAll(":\\d+:", ":");
107 try {
108 command = viewRoot.findComponent(sourceId);
109
110 } catch (final Exception e) {
111
112 }
113 }
114
115 if (LOG.isTraceEnabled()) {
116 LOG.trace(sourceId);
117 LOG.trace("command:{}", command);
118 LOG.trace(DebugUtils.toString(viewRoot, 0));
119 }
120
121 if (command != null) {
122 final AbstractUIFormBase form = ComponentUtils.findForm(command);
123 form.setSubmitted(true);
124
125 if (LOG.isTraceEnabled()) {
126 LOG.trace("form:{}", form);
127 LOG.trace(form.getClientId(facesContext));
128 }
129 } else {
130 if (LOG.isDebugEnabled()) {
131 LOG.debug("Illegal actionId! Render response...");
132 }
133 facesContext.renderResponse();
134 }
135 }
136
137 public abstract String getLabel();
138
139 public abstract String getFocusId();
140 }