1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.renderkit.html.ext;
20
21 import java.io.IOException;
22
23 import javax.faces.component.UIComponent;
24 import javax.faces.context.FacesContext;
25 import javax.faces.context.ResponseWriter;
26
27 import org.apache.myfaces.custom.clientvalidation.common.CVUtils;
28 import org.apache.myfaces.custom.util.ComponentUtils;
29 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlFormRendererBase;
30
31
32
33
34
35
36
37
38
39
40
41 public class HtmlFormRenderer extends HtmlFormRendererBase{
42
43 private static String CLIENT_VALIDATON_SCRIPT = "return tomahawk.executeClientLifeCycle();";
44
45 public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException {
46 if(CVUtils.isCVEnabled()) {
47 ComponentUtils.decorateEventAttribute(component, "onsubmit", CLIENT_VALIDATON_SCRIPT);
48 }
49
50 super.encodeBegin(facesContext, component);
51 }
52
53 public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
54 if(CVUtils.isCVEnabled()) {
55 encodeBypassCVField(facesContext, component);
56 }
57
58 super.encodeEnd(facesContext, component);
59
60 if(CVUtils.isCVEnabled()) {
61 CVUtils.encodeJavascript(facesContext);
62 CVUtils.queueCVCalls(facesContext.getViewRoot());
63 CVUtils.encodeValidationScript(facesContext);
64 }
65 }
66
67
68 private void encodeBypassCVField(FacesContext facesContext, UIComponent component) throws IOException{
69 ResponseWriter writer = facesContext.getResponseWriter();
70
71 writer.startElement("input", component);
72 writer.writeAttribute("type", "hidden", null);
73 writer.writeAttribute("id", CVUtils.BYPASS_CLIENT_VALIDATION_FIELD, null);
74 writer.writeAttribute("name", CVUtils.BYPASS_CLIENT_VALIDATION_FIELD, null);
75 writer.writeAttribute("value", "false", null);
76 writer.endElement("input");
77 }
78 }