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