View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.myfaces.custom.inputAjax;
20  
21  import java.io.IOException;
22  
23  import javax.faces.context.FacesContext;
24  import javax.faces.render.Renderer;
25  
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  import org.apache.myfaces.component.html.ext.HtmlCommandButton;
29  import org.apache.myfaces.custom.ajax.AjaxCallbacks;
30  import org.apache.myfaces.custom.ajax.api.AjaxRenderer;
31  import org.apache.myfaces.custom.ajax.api.DeprecatedAjaxComponent;
32  
33  /**
34   * Extends standard commandButton allowing for dynamic ajax submitting of the form.
35   * 
36   * @JSFComponent
37   *   name = "s:commandButtonAjax"
38   *   class = "org.apache.myfaces.custom.inputAjax.HtmlCommandButtonAjax"
39   *   tagClass = "org.apache.myfaces.custom.inputAjax.HtmlCommandButtonAjaxTag"
40   *   
41   * User: Travis Reeder
42   * Date: Mar 22, 2006
43   * Time: 4:37:53 PM
44   */
45  public abstract class AbstractHtmlCommandButtonAjax extends HtmlCommandButton implements DeprecatedAjaxComponent, AjaxCallbacks
46  {
47      private static final Log log = LogFactory.getLog(HtmlInputTextAjax.class);
48      public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlCommandButtonAjax";
49      public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.CommandButtonAjax";
50  
51      public AbstractHtmlCommandButtonAjax()
52      {
53          super();
54          setRendererType(DEFAULT_RENDERER_TYPE);
55          setType("button"); // we don't want this to submit
56      }
57  
58      /**
59       * Decode ajax request and apply value changes
60       *
61       * @param context
62       */
63      public void decodeAjax(FacesContext context)
64      {
65          log.debug("entering HtmlCommandButtonAjax.decodeAjax");
66  
67          processDecodes(context);
68          processValidators(context);
69          processUpdates(context);
70          //context.getViewRoot().processApplication(context);
71          if (log.isDebugEnabled())
72          {
73              Object valOb = this.getValue();
74              log.debug("value object after decodeAjax: " + valOb);
75          }
76  
77      }
78  
79      public void encodeAjax(FacesContext context) throws IOException
80      {
81          log.debug("encodeAjax in HtmlCommandButtonAjax");
82          if (context == null) throw new NullPointerException("context");
83          if (!isRendered()) return;
84          Renderer renderer = getRenderer(context);
85  
86          if (renderer != null && renderer instanceof AjaxRenderer)
87          {
88              ((AjaxRenderer) renderer).encodeAjax(context, this);
89  
90          }
91      }
92  
93      /**
94       * Javascript method to call on successful ajax update
95       * 
96       * @JSFProperty
97       */
98      public abstract String getOnSuccess();
99  
100     /**
101      * Javascript method to call on failed ajax update
102      * 
103      * @JSFProperty
104      */
105     public abstract String getOnFailure();
106 
107     /**
108      * Javascript method to call on start of ajax update
109      * 
110      * @JSFProperty
111      */
112     public abstract String getOnStart();
113 
114     
115 }