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