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.suggestajax;
20  
21  import java.io.IOException;
22  
23  import javax.el.MethodExpression;
24  import javax.faces.context.FacesContext;
25  import javax.faces.render.Renderer;
26  
27  import org.apache.myfaces.component.LocationAware;
28  import org.apache.myfaces.component.html.ext.HtmlInputText;
29  import org.apache.myfaces.custom.ajax.api.AjaxComponent;
30  import org.apache.myfaces.custom.ajax.api.AjaxRenderer;
31  
32  /**
33   * 
34   * @JSFComponent
35   *   configExcluded = "true"
36   *   class = "org.apache.myfaces.custom.suggestajax.SuggestAjax"
37   *   superClass = "org.apache.myfaces.custom.suggestajax.AbstractSuggestAjax"
38   *   tagClass = "org.apache.myfaces.custom.suggestajax.SuggestAjaxTag"
39   *   tagSuperclass = "org.apache.myfaces.custom.suggestajax.AbstractSuggestAjaxTag"
40   * @author Gerald Muellan
41   *         Date: 25.03.2006
42   *         Time: 17:06:04
43   */
44  public abstract class AbstractSuggestAjax extends HtmlInputText 
45      implements AjaxComponent, LocationAware
46  {
47      public static final String COMPONENT_TYPE = "org.apache.myfaces.SuggestAjax";
48      public static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.SuggestAjax";
49  
50      private MethodExpression _suggestedItemsMethod;
51  
52      public Object saveState(FacesContext context)
53      {
54          Object[] values = new Object[4];
55          values[0] = super.saveState(context);
56          values[1] = saveAttachedState(context, _suggestedItemsMethod);
57  
58          return values;
59      }
60  
61      public void restoreState(FacesContext context, Object state)
62      {
63          Object values[] = (Object[])state;
64          super.restoreState(context, values[0]);
65          _suggestedItemsMethod = (MethodExpression) restoreAttachedState(context, values[1]);
66      }
67      
68      public void encodeAjax(FacesContext context)
69              throws IOException
70      {
71          if (context == null) throw new NullPointerException("context");
72          if (!isRendered()) return;
73          Renderer renderer = getRenderer(context);
74          if (renderer != null && renderer instanceof AjaxRenderer)
75          {
76              ((AjaxRenderer) renderer).encodeAjax(context, this);
77          }
78      }
79  
80      public void decodeAjax(FacesContext context)
81      {
82  
83      }
84  
85      public void encodeChildren(FacesContext context) throws IOException
86      {
87          super.encodeChildren(context);
88      }
89  
90       public void setSuggestedItemsMethod(MethodExpression suggestedItemsMethod)
91      {
92         _suggestedItemsMethod = suggestedItemsMethod;
93      }
94  
95      /**
96       * Reference to the method which returns the suggested items
97       * 
98       * @JSFProperty
99       *   inheritedTag = "true"
100      * @return
101      */
102     public MethodExpression getSuggestedItemsMethod()
103     {
104         return _suggestedItemsMethod;
105     }
106 
107     /**
108      * optional attribute to identify the max size of suggested Values. 
109      * If specified in tableSuggestAjax, paginator functionality is used.
110      * 
111      * @JSFProperty
112      *   inheritedTag = "true"
113      * @return
114      */
115     public abstract Integer getMaxSuggestedItems();
116 
117     
118     /**
119      * Force the charset of the Response
120      * 
121      * @JSFProperty
122      *   literalOnly = "true"
123      * @return
124      */
125     public abstract String getCharset();
126 
127     /**
128      *  An alternate location to find javascript resources. 
129      *  If no values is specified, javascript will be loaded 
130      *  from the resources directory using AddResource and 
131      *  ExtensionsFilter.
132      * 
133      * @JSFProperty 
134      */
135     public abstract String getJavascriptLocation();
136     
137     /**
138      * An alternate location to find image resources. If no 
139      * values is specified, images will be loaded from the 
140      * resources directory using AddResource and ExtensionsFilter.
141      * 
142      * @JSFProperty 
143      */
144     public abstract String getImageLocation();
145     
146     /**
147      * An alternate location to find stylesheet resources. If no 
148      * values is specified, stylesheets will be loaded from the 
149      * resources directory using AddResource and ExtensionsFilter.
150      * 
151      * @JSFProperty 
152      */
153     public abstract String getStyleLocation();
154 
155     
156 }