View Javadoc
1   // ---------- Attention: Generated code, please do not modify! -----------  
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.myfaces.tobago.component;
21  
22  import javax.el.MethodExpression;
23  import javax.faces.context.FacesContext;
24  import org.apache.myfaces.tobago.internal.component.AbstractUISuggest;
25  import org.apache.myfaces.tobago.model.SuggestFilter;
26  import org.apache.myfaces.tobago.internal.util.ArrayUtils;
27  import org.apache.myfaces.tobago.internal.util.StringUtils;
28  import org.apache.myfaces.tobago.internal.util.Deprecation;
29  import javax.el.ELException;
30  import javax.faces.FacesException;
31  import java.util.Arrays;
32  import java.util.ArrayList;
33  import java.util.Collection;
34  import java.util.List;
35  import javax.el.MethodExpression;
36  import javax.el.ValueExpression;
37  
38  /** 
39   Renders a list of suggested texts for a given input field.
40  
41    Basic features:
42    <ul>
43      <li>provide a list directly while rendering (not AJAX needed) [todo]</li>
44      <li>update by typing (AJAX)</li>
45      <li>minimum number of typed characters (to avoid useless requests)</li>
46      <li>update delay (useful for optimization)</li>
47      <li>filter on client side (useful for optimization) [todo]</li>
48    </ul>
49    * UIComponent class, generated from template {@code component.stg} with class
50    * {@link org.apache.myfaces.tobago.internal.taglib.component.SuggestTagDeclaration}.
51   */
52  public class UISuggest
53      extends AbstractUISuggest  {
54  
55    public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Suggest";
56  
57    public static final String COMPONENT_FAMILY = "javax.faces.Input";
58  
59  
60    enum PropertyKeys {
61      filter,
62      delay,
63      suggestMethod,
64      minimumCharacters,
65      update,
66      totalCount,
67      maximumItems,
68    }
69  
70    public String getFamily() {
71      return COMPONENT_FAMILY;
72    }
73  
74  
75    /**
76    TODO: not implemented yet
77     <p>
78     Additional client side filtering of the result list.
79     This is useful when sending the full list initially to the client and
80     setting <code>update=false</code>.
81     </p>
82     <p>
83     Possible values are:
84     </p>
85     <dl>
86       <dt>all</dt>
87       <dd>no filtering</dd>
88       <dt>prefix</dt>
89       <dd>checks if the suggested string starts with the typed text</dd>
90       <dt>contains</dt>
91       <dd>checks if the typed text is inside of the suggested string</dd>
92     </dl>
93     <p>
94     The filter will only applied on the client side and
95     only if server updated (by AJAX) are turned off (<code>update=false</code>);
96     </p>
97    <br>Default: <code>SuggestFilter.ALL</code><br>Allowed Values: <code>all,prefix,contains</code>
98    */
99    public org.apache.myfaces.tobago.model.SuggestFilter getFilter() {
100     org.apache.myfaces.tobago.model.SuggestFilter filter = (org.apache.myfaces.tobago.model.SuggestFilter) getStateHelper().eval(PropertyKeys.filter);
101     if (filter != null) {
102       return filter;
103     }
104     return SuggestFilter.ALL;
105   }
106 
107   public void setFilter(org.apache.myfaces.tobago.model.SuggestFilter filter) {
108     getStateHelper().put(PropertyKeys.filter, filter);
109   }
110 
111   /**
112   Time in milli seconds before the list will be requested (by AJAX).
113   <br>Default: <code>200</code>
114   */
115   public java.lang.Integer getDelay() {
116     Number value  = (Number) getStateHelper().eval(PropertyKeys.delay);
117     if (value != null) {
118       return value.intValue();
119     }
120     return 200;
121   }
122 
123   public void setDelay(java.lang.Integer delay) {
124     getStateHelper().put(PropertyKeys.delay, delay);
125   }
126 
127   /**
128    * @deprecated since 2.0.0
129    */
130   @Deprecated
131   public javax.faces.el.MethodBinding getSuggestMethod() {
132     javax.el.MethodExpression expression = getSuggestMethodExpression();
133     if (expression instanceof MethodBindingToMethodExpression) {
134       return ((MethodBindingToMethodExpression)expression).getMethodBinding();
135     }
136     if (expression != null) {
137        return new MethodExpressionToMethodBinding(expression);
138     }
139     return null;
140   }
141 
142   /**
143    * @deprecated since 2.0.0
144    */
145   @Deprecated
146   public void setSuggestMethod(javax.faces.el.MethodBinding suggestMethod) {
147     if (suggestMethod != null) {
148       setSuggestMethodExpression(new MethodBindingToMethodExpression(suggestMethod));
149     } else {
150       setSuggestMethodExpression(null);
151     }
152   }
153 
154   public javax.el.MethodExpression getSuggestMethodExpression() {
155     return (javax.el.MethodExpression) getStateHelper().eval(PropertyKeys.suggestMethod);
156   }
157 
158   public void setSuggestMethodExpression(javax.el.MethodExpression suggestMethod) {
159     getStateHelper().put(PropertyKeys.suggestMethod, suggestMethod);
160   }
161 
162 
163   /**
164   Minimum number of characters to type before the list will be requested.
165    If the value is 0, there will be send an initial list to the client.
166    So, if you set <pre>update="false"</pre> this value should be 0.
167   <br>Default: <code>1</code>
168   */
169   public java.lang.Integer getMinimumCharacters() {
170     Number value  = (Number) getStateHelper().eval(PropertyKeys.minimumCharacters);
171     if (value != null) {
172       return value.intValue();
173     }
174     return 1;
175   }
176 
177   public void setMinimumCharacters(java.lang.Integer minimumCharacters) {
178     getStateHelper().put(PropertyKeys.minimumCharacters, minimumCharacters);
179   }
180 
181   /**
182   TODO: not implemented yet
183    <p>
184    Should the list be updated while typing (via AJAX). This is the default behaviour.
185    If you set this value to <code>false</code>, please set the <code>minimumCharacters="0"</code>.
186    </p>
187   <br>Default: <code>true</code>
188   */
189   public boolean isUpdate() {
190     Boolean bool = (Boolean) getStateHelper().eval(PropertyKeys.update);
191     if (bool != null) {
192       return bool;
193     }
194     return true;
195   }
196 
197   public void setUpdate(boolean update) {
198     getStateHelper().put(PropertyKeys.update, update);
199   }
200 
201   /**
202   The real size of the result list.
203    Typically the result list will be cropped (in the backend) to save memory.
204    This value can be set, to show the user there are more results for the given string.
205    If the value is -1, no hint will be displayed.
206   <br>Default: <code>-1</code>
207   */
208   public java.lang.Integer getTotalCount() {
209     Number value  = (Number) getStateHelper().eval(PropertyKeys.totalCount);
210     if (value != null) {
211       return value.intValue();
212     }
213     return -1;
214   }
215 
216   public void setTotalCount(java.lang.Integer totalCount) {
217     getStateHelper().put(PropertyKeys.totalCount, totalCount);
218   }
219 
220   /**
221   The maximum number of item to display in the drop down list.
222   <br>Default: <code>10</code>
223   */
224   public java.lang.Integer getMaximumItems() {
225     Number value  = (Number) getStateHelper().eval(PropertyKeys.maximumItems);
226     if (value != null) {
227       return value.intValue();
228     }
229     return 10;
230   }
231 
232   public void setMaximumItems(java.lang.Integer maximumItems) {
233     getStateHelper().put(PropertyKeys.maximumItems, maximumItems);
234   }
235 
236 
237 }