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