1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.custom.inputAjax;
20
21 import org.apache.myfaces.renderkit.html.ext.HtmlButtonRenderer;
22 import org.apache.myfaces.renderkit.html.util.AddResource;
23 import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
24 import org.apache.myfaces.custom.ajax.util.AjaxRendererUtils;
25 import org.apache.myfaces.custom.ajax.api.AjaxRenderer;
26 import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
27 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30
31 import javax.faces.context.FacesContext;
32 import javax.faces.context.ResponseWriter;
33 import javax.faces.component.UIComponent;
34 import java.io.IOException;
35
36
37
38
39
40
41
42
43
44
45
46
47 public class HtmlCommandButtonAjaxRenderer extends HtmlButtonRenderer implements AjaxRenderer
48 {
49 private static final Log log = LogFactory.getLog(HtmlCommandButtonAjaxRenderer.class);
50 private static final String JAVASCRIPT_ENCODED = "org.apache.myfaces.custom.inputAjax.HtmlCommandButtonAjax.JAVASCRIPT_ENCODED";
51
52
53
54
55
56
57
58
59
60
61
62 private void encodeJavascript(FacesContext context, UIComponent component) throws IOException
63 {
64 HtmlCommandButtonAjax comp = (HtmlCommandButtonAjax) component;
65
66 AddResource addResource = AddResourceFactory.getInstance(context);
67
68 AjaxRendererUtils.addPrototypeScript(context, component, addResource);
69
70 ResponseWriter out = context.getResponseWriter();
71 AjaxRendererUtils.writeAjaxScript(context, out, comp);
72
73 context.getExternalContext().getRequestMap().put(JAVASCRIPT_ENCODED, Boolean.TRUE);
74 }
75
76
77
78
79 public void encodeEnd(FacesContext context, UIComponent component) throws IOException
80 {
81 log.debug("encodeEnd in HtmlCommandButtonAjaxRenderer");
82 RendererUtils.checkParamValidity(context, component, HtmlCommandButtonAjax.class);
83
84 if (HtmlRendererUtils.isDisplayValueOnly(component) || isDisabled(context, component))
85 {
86 super.encodeEnd(context, component);
87 return;
88 }
89
90 this.encodeJavascript(context, component);
91 super.encodeEnd(context, component);
92
93 AjaxRendererUtils.writeLoadingImage(context, component);
94 }
95
96
97 protected StringBuffer buildOnClick(UIComponent uiComponent, FacesContext facesContext, ResponseWriter writer) throws IOException {
98 String clientId = uiComponent.getClientId(facesContext);
99 String submitFunctionStart = AjaxRendererUtils.JS_MYFACES_NAMESPACE + "ajaxSubmit3('" + clientId + "');";
100
101 StringBuffer buf = super.buildOnClick(uiComponent, facesContext, writer);
102
103 if(buf.length()!=0 && !(buf.charAt(buf.length()-1)==';'))
104 {
105 buf.append(";");
106 }
107 buf.append(submitFunctionStart);
108
109 return buf;
110 }
111
112 public void encodeAjax(FacesContext context, UIComponent component) throws IOException
113 {
114 log.debug("encodeAjax in HtmlCommandButtonAjaxRenderer");
115 AjaxRendererUtils.encodeAjax(context, component);
116 }
117
118 }